-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup_test.js
More file actions
51 lines (42 loc) · 1.49 KB
/
group_test.js
File metadata and controls
51 lines (42 loc) · 1.49 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
// MIT License
// Copyright (c) 2026 Open2b
// See the LICENSE file for full text.
import { assertEquals } from '@std/assert'
import Options from './options.js'
import Storage from './storage.js'
import Group from './group.js'
const writeKey = 'rq6JJg5ENWK28NHfxSwJZmzeIvDC8GQO'
Deno.test('Group', () => {
localStorage.clear()
globalThis.document = {
visibilityState: 'visible',
addEventListener: addEventListener.bind(globalThis),
}
const group = new Group(new Storage(writeKey, new Options()))
assertEquals(group.id(), null)
assertEquals(group.traits(), {})
assertEquals(group.id('acme'), 'acme')
assertEquals(group.id(), 'acme')
assertEquals(group.id(null), null)
assertEquals(group.id(), null)
const rec = {}
rec.boo = rec
// Apply the following changes to traits consecutively and test the results of each step.
const changes = [
{ set: { foo: true }, expect: { foo: true } },
{ set: undefined, expect: { foo: true } },
{ set: null, expect: {} },
{ set: { foo: false }, expect: { foo: false } },
{ set: 'foo', expect: { foo: false } },
{ set: { foo: {} }, expect: { foo: {} } },
{ set: { foo: 5n, boo: true }, expect: { foo: {} } },
{ set: { foo: undefined, boo: 5 }, expect: { boo: 5 } },
{ set: { foo: rec }, expect: { boo: 5 } },
{ set: { foo: () => {}, boo: true }, expect: { boo: true } },
]
for (let i = 0; i < changes.length; i++) {
const change = changes[i]
assertEquals(group.traits(change.set), change.expect)
assertEquals(group.traits(), change.expect)
}
})