-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathpreferences.test.ts
More file actions
94 lines (83 loc) · 2.75 KB
/
Copy pathpreferences.test.ts
File metadata and controls
94 lines (83 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { describe, expect, it, vi } from 'vitest'
import { silenceDebugMessages } from './helpers/debugger'
import { JSDOM } from 'jsdom'
vi.mock('../../src/login/login', () => ({
ensureLoadedPreferences: vi.fn()
}))
import * as loginModule from '../../src/login/login'
import * as Preferences from '../../src/lib/preferences'
import { sym } from 'rdflib'
silenceDebugMessages()
const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window
const dom = window.document
describe('Preferences', () => {
it.skip('exists', () => {
expect(Preferences).toBeInstanceOf(Function)
})
})
describe('Preferences.value', () => {
it('exists', () => {
expect(Preferences.value).toEqual([])
})
})
describe('Preferences.get', () => {
it('exists', () => {
expect(Preferences.get).toBeInstanceOf(Function)
})
it('runs', () => {
expect(Preferences.get(10)).toEqual(undefined)
})
})
describe('Preferences.set', () => {
it('exists', () => {
expect(Preferences.set).toBeInstanceOf(Function)
})
it('runs', () => {
expect(Preferences.set(10, 'a')).toEqual(undefined)
})
})
describe('Preferences.renderPreferencesForm', () => {
it('exists', () => {
expect(Preferences.renderPreferencesForm).toBeInstanceOf(Function)
})
it('runs', () => {
const subject = sym('https://test.test')
const theClass = {}
const preferencesForm = {}
const context = { dom }
expect(Preferences.renderPreferencesForm(
subject, theClass, preferencesForm, context
)).toBeTruthy()
})
})
describe('Preferences.recordSharedPreferences', () => {
it('exists', () => {
expect(Preferences.recordSharedPreferences).toBeInstanceOf(Function)
})
it('runs', () => {
const subject = sym('https://test.test/sub')
const context = {}
expect(Preferences.recordSharedPreferences(subject, context)).toBeTruthy()
})
})
describe('Preferences.recordPersonalDefaults', () => {
it('does not try to load preferences when there is no logged-in user', async () => {
const ensureLoadedPreferencesMock = vi.mocked(loginModule.ensureLoadedPreferences)
const context = { me: null }
const result = await Preferences.recordPersonalDefaults(sym('https://test.example/class'), context)
expect(result).toBe(context)
expect(ensureLoadedPreferencesMock).not.toHaveBeenCalled()
})
})
describe('Preferences.getPreferencesForClass', () => {
it('exists', () => {
expect(Preferences.getPreferencesForClass).toBeInstanceOf(Function)
})
it('runs', () => {
const subject = sym('https://test.test/sub')
const theClass = sym('https://test.test/class')
const predicates = [sym('https://test.test/pred')]
const context = {}
expect(Preferences.getPreferencesForClass(subject, theClass, predicates, context)).toBeTruthy()
})
})