-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathstartFullSnapshots.spec.ts
107 lines (95 loc) · 3.24 KB
/
startFullSnapshots.spec.ts
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
import type { RumConfiguration, ViewCreatedEvent } from '@datadog/browser-rum-core'
import { LifeCycle, LifeCycleEventType } from '@datadog/browser-rum-core'
import type { TimeStamp } from '@datadog/browser-core'
import { isIE, noop } from '@datadog/browser-core'
import { RecordType, type BrowserRecord } from '../../types'
import { startFullSnapshots } from './startFullSnapshots'
import { createElementsScrollPositions } from './elementsScrollPositions'
import type { ShadowRootsController } from './shadowRootsController'
describe('startFullSnapshots', () => {
const viewStartClock = { relative: 1, timeStamp: 1 as TimeStamp }
let lifeCycle: LifeCycle
let fullSnapshotCallback: jasmine.Spy<(records: BrowserRecord[]) => void>
beforeEach(() => {
if (isIE()) {
pending('IE not supported')
}
lifeCycle = new LifeCycle()
fullSnapshotCallback = jasmine.createSpy()
startFullSnapshots(
createElementsScrollPositions(),
{} as ShadowRootsController,
lifeCycle,
{} as RumConfiguration,
noop,
fullSnapshotCallback
)
})
it('takes a full snapshot when startFullSnapshots is called', () => {
expect(fullSnapshotCallback).toHaveBeenCalledTimes(1)
})
it('takes a full snapshot when the view changes', () => {
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, {
startClocks: viewStartClock,
} as Partial<ViewCreatedEvent> as any)
expect(fullSnapshotCallback).toHaveBeenCalledTimes(2)
})
it('full snapshot related records should have the view change date', () => {
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, {
startClocks: viewStartClock,
} as Partial<ViewCreatedEvent> as any)
const records = fullSnapshotCallback.calls.mostRecent().args[0]
expect(records[0].timestamp).toEqual(1)
expect(records[1].timestamp).toEqual(1)
expect(records[2].timestamp).toEqual(1)
})
it('full snapshot records should contain Meta, Focus, FullSnapshot', () => {
const records = fullSnapshotCallback.calls.mostRecent().args[0]
expect(records).toEqual(
jasmine.arrayContaining([
{
data: {
height: jasmine.any(Number),
href: window.location.href,
width: jasmine.any(Number),
},
type: RecordType.Meta,
timestamp: jasmine.any(Number),
},
{
data: {
has_focus: document.hasFocus(),
},
type: RecordType.Focus,
timestamp: jasmine.any(Number),
},
{
data: {
node: jasmine.any(Object),
initialOffset: {
left: jasmine.any(Number),
top: jasmine.any(Number),
},
},
type: RecordType.FullSnapshot,
timestamp: jasmine.any(Number),
},
])
)
})
it('full snapshot records should contain visualViewport when supported', () => {
if (!window.visualViewport) {
pending('visualViewport not supported')
}
const records = fullSnapshotCallback.calls.mostRecent().args[0]
expect(records).toEqual(
jasmine.arrayContaining([
{
data: jasmine.any(Object),
type: RecordType.VisualViewport,
timestamp: jasmine.any(Number),
},
])
)
})
})