-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathplugin_features.test.ts
More file actions
61 lines (52 loc) · 1.78 KB
/
plugin_features.test.ts
File metadata and controls
61 lines (52 loc) · 1.78 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
import { SelfDescribingJson } from '@snowplow/tracker-core';
import { Plugins } from '../../src/features';
describe('Performance Navigation Timing', () => {
let windowSpy: any;
const otherContexts = {
webPage: false,
session: false,
performanceTiming: false,
gaCookies: false,
geolocation: false,
clientHints: false,
webVitals: false,
};
const hasPerformanceNavigationTimingContext = (plugins: ReturnType<typeof Plugins>): boolean => {
const pluginContexts = plugins.map((plugin) => plugin[0]?.contexts?.());
const hasPerformanceContext = pluginContexts.some((contexts?: SelfDescribingJson[]) =>
contexts?.some(
(context: { schema?: string }) => context.schema === 'iglu:org.w3/PerformanceNavigationTiming/jsonschema/1-0-0'
)
);
return hasPerformanceContext;
};
beforeEach(() => {
windowSpy = jest.spyOn(global, 'window', 'get');
// The PerformanceNavigationTiming context will only be added if the plugin can:
// - Access the `performance` object on the window
// - See that a value is returned from `getEntriesByType`
windowSpy.mockImplementation(() => ({
performance: {
getEntriesByType: () => [{}],
},
}));
});
it('Is enabled if contexts.performanceNavigationTiming is true', () => {
const plugins = Plugins({
contexts: {
performanceNavigationTiming: true,
...otherContexts,
},
});
expect(hasPerformanceNavigationTimingContext(plugins)).toBe(true);
});
it('Is disabled if contexts.performanceNavigationTiming is false', () => {
const plugins = Plugins({
contexts: {
performanceNavigationTiming: false,
...otherContexts,
},
});
expect(hasPerformanceNavigationTimingContext(plugins)).toBe(false);
});
});