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 | import F from 'lodash/fp';
|
32 | import { DockerWrapper, start, stop } from '../micro';
|
33 |
|
34 | declare var trackPageView: () => void;
|
35 | declare var findMaxX: () => number;
|
36 | declare var findMaxY: () => number;
|
37 | declare var getCurrentPageViewId: () => void;
|
38 | declare var findFirstEventForPageViewId: (id: string) => Record<string, unknown>;
|
39 | declare var findLastEventForPageViewId: (id: string) => Record<string, unknown>;
|
40 |
|
41 | describe('Activity tracking with callbacks', () => {
|
42 | let docker: DockerWrapper;
|
43 |
|
44 | beforeAll(async () => {
|
45 | await browser.call(async () => {
|
46 | return await start().then((container) => {
|
47 | docker = container;
|
48 | });
|
49 | });
|
50 | await browser.url('/index.html');
|
51 | await browser.setCookies({ name: 'container', value: docker.url });
|
52 | });
|
53 |
|
54 | afterAll(async () => {
|
55 | await browser.call(async () => {
|
56 | return await stop(docker.container);
|
57 | });
|
58 | });
|
59 |
|
60 | it('reports events on scroll', async () => {
|
61 | await browser.url('/activity-callback.html?test1');
|
62 | await browser.waitUntil(async () => (await $('#init').getText()) === 'true', {
|
63 | timeout: 5000,
|
64 | timeoutMsg: 'expected init after 5s',
|
65 | interval: 250,
|
66 | });
|
67 |
|
68 | await $('#bottomRight').scrollIntoView();
|
69 |
|
70 | await browser.waitUntil(async () => +(await $('#numEvents').getText()) >= 1, {
|
71 | timeout: 10000,
|
72 | timeoutMsg: 'expected > 1 event after 10s',
|
73 | });
|
74 | const [maxX, maxY] = await browser.execute(() => {
|
75 | return [findMaxX(), findMaxY()];
|
76 | });
|
77 |
|
78 | expect(maxX).toBeGreaterThan(100);
|
79 | expect(maxY).toBeGreaterThan(100);
|
80 | });
|
81 |
|
82 | it('carries pageviewid change through and resets scroll', async () => {
|
83 | await browser.url('/activity-callback.html?test2');
|
84 | await browser.waitUntil(async () => (await $('#init').getText()) === 'true', {
|
85 | timeout: 5000,
|
86 | timeoutMsg: 'expected init after 5s',
|
87 | interval: 250,
|
88 | });
|
89 |
|
90 | await browser.execute(() => window.scrollTo(0, 0));
|
91 |
|
92 | await browser.execute(() => {
|
93 | getCurrentPageViewId();
|
94 | });
|
95 | const firstPageViewId = await $('#currentPageViewId').getText();
|
96 |
|
97 | await $('#bottomRight').scrollIntoView();
|
98 | await $('#middle').scrollIntoView();
|
99 | await browser.waitUntil(async () => +(await $('#numEvents').getText()) >= 1, {
|
100 | timeout: 10000,
|
101 | timeoutMsg: 'expected > 1 event after 10s',
|
102 | });
|
103 |
|
104 | await browser.execute(() => {
|
105 | trackPageView();
|
106 | });
|
107 | await $('#bottomRight').scrollIntoView();
|
108 |
|
109 | await browser.waitUntil(async () => +(await $('#numEvents').getText()) > 1, {
|
110 | timeout: 10000,
|
111 | timeoutMsg: 'expected > 1 event after 10s',
|
112 | });
|
113 |
|
114 | await browser.execute(() => {
|
115 | getCurrentPageViewId();
|
116 | });
|
117 | const secondPageViewId = await $('#currentPageViewId').getText();
|
118 |
|
119 |
|
120 | expect(firstPageViewId).not.toEqual(secondPageViewId);
|
121 |
|
122 | const first = await browser.execute((id) => {
|
123 | return findFirstEventForPageViewId(id);
|
124 | }, firstPageViewId);
|
125 | const second = await browser.execute((id) => {
|
126 | return findLastEventForPageViewId(id);
|
127 | }, secondPageViewId);
|
128 |
|
129 | const getMinXY = F.at(['minXOffset', 'minYOffset']);
|
130 |
|
131 |
|
132 | expect(getMinXY(first)).toEqual([0, 0]);
|
133 |
|
134 |
|
135 |
|
136 | const [secondX, secondY] = getMinXY(second);
|
137 | expect(secondX).toBeGreaterThan(0);
|
138 | expect(secondY).toBeGreaterThan(0);
|
139 | });
|
140 | });
|