forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration.test.ts
More file actions
128 lines (125 loc) · 3.63 KB
/
Copy pathconfiguration.test.ts
File metadata and controls
128 lines (125 loc) · 3.63 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import {
Configuration,
type ContextProvider,
ElementConfiguration,
checkConfig,
createContextMerger,
} from '../src/configuration';
describe('configuration parsing', () => {
const emptyMerger = createContextMerger();
// Accept valid configs
it.each<{ note: string; input: ElementConfiguration; expected?: Partial<Configuration> }>([
{
note: 'minimal configuration',
input: { selector: '.oncreate' },
},
{
note: 'use selector when no name',
input: { selector: 'unnamed' },
expected: { selector: 'unnamed', name: 'unnamed' },
},
{
note: 'custom name',
input: { selector: '.selector', name: 'named' },
expected: { selector: '.selector', name: 'named' },
},
{
note: 'default event frequencies',
input: { selector: 'unnamed' },
expected: {
create: { when: 'never' },
destroy: { when: 'never' },
expose: { when: 'always', boundaryPixels: 0, minPercentage: 0, minSize: 0, minTimeMillis: 0 },
obscure: { when: 'never' },
component: false,
contents: [],
details: [],
},
},
{
note: 'custom frequencies',
input: { selector: 'unnamed', expose: false, create: true },
expected: {
create: { when: 'always' },
expose: { when: 'never', boundaryPixels: 0, minPercentage: 0, minSize: 0, minTimeMillis: 0 },
},
},
{
note: 'mis-cased frequencies',
input: { selector: 'unnamed', create: { when: 'ALWAYs' as any }, expose: { when: 'Never' as any } },
expected: {
create: { when: 'always' },
expose: { when: 'never' } as any,
},
},
{
note: 'context provider',
input: { selector: 'unnamed', context: [] },
expected: {
context: emptyMerger as Extract<ContextProvider, Function>,
},
},
{
note: 'contents recursion',
input: { selector: 'unnamed', contents: { selector: 'inner' } },
},
])('accepts valid config: $note', ({ input, expected }) => {
const result = checkConfig(input, emptyMerger, true, true);
expect(result).toBeDefined();
if (expected) expect(result).toMatchObject(expected);
});
// Reject invalid configs
it.each<{ note: string; input: ElementConfiguration }>([
{
note: 'invalid name',
input: { selector: 'a', name: '' },
},
{
note: 'empty selector',
input: { selector: '' },
},
{
note: 'invalid selector',
input: { selector: ':asdf' },
},
{
note: 'mistyped selector',
input: { selector: 1 as any },
},
{
note: 'good name, bad selector',
input: { selector: '', name: 'named' },
},
{
note: 'bad expose condition',
input: { selector: '.good', name: 'named', expose: { condition: {} } as any },
},
{
note: 'bad other condition',
input: { selector: '.good', name: 'named', create: { condition: true } as any },
},
{
note: 'bad expose frequency',
input: { selector: '.good', name: 'named', expose: { when: 'fail' } },
},
{
note: 'bad other frequency',
input: { selector: '.good', name: 'named', create: { when: 'fail' } },
},
{
note: 'bad boundaries',
input: { selector: '.good', name: 'named', expose: { when: 'always', boundaryPixels: '1em' } },
},
{
note: 'bad details request',
input: { selector: '.good', name: 'named', details: {} as any },
},
])('rejects invalid config: $note', ({ input }) => {
expect.hasAssertions();
try {
checkConfig(input, emptyMerger, true, true);
} catch (e) {
expect(e).toBeDefined();
}
});
});