@servicetitan/web-components 40.2.2 → 40.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/loader.js +4 -1
- package/dist/loader.js.map +1 -1
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts +3 -0
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts.map +1 -0
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js +12 -0
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js.map +1 -0
- package/dist/patches/kendo-scrollbar-width/index.d.ts +3 -0
- package/dist/patches/kendo-scrollbar-width/index.d.ts.map +1 -0
- package/dist/patches/kendo-scrollbar-width/index.js +4 -0
- package/dist/patches/kendo-scrollbar-width/index.js.map +1 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts +2 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts.map +1 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js +26 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js.map +1 -0
- package/dist/register.js +2 -2
- package/dist/register.js.map +1 -1
- package/dist/use-prefetch.d.ts +2 -3
- package/dist/use-prefetch.d.ts.map +1 -1
- package/dist/use-prefetch.js +14 -7
- package/dist/use-prefetch.js.map +1 -1
- package/dist/utils/get-bundle-info.d.ts +1 -0
- package/dist/utils/get-bundle-info.d.ts.map +1 -1
- package/dist/utils/get-bundle-info.js +2 -0
- package/dist/utils/get-bundle-info.js.map +1 -1
- package/dist/utils/web-component.d.ts.map +1 -1
- package/dist/utils/web-component.js +13 -2
- package/dist/utils/web-component.js.map +1 -1
- package/package.json +18 -14
- package/src/loader.tsx +5 -1
- package/src/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.ts +11 -0
- package/src/patches/kendo-scrollbar-width/index.ts +2 -0
- package/src/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.ts +27 -0
- package/src/register.tsx +1 -1
- package/src/use-prefetch.ts +36 -32
- package/src/utils/get-bundle-info.ts +2 -0
- package/src/utils/web-component.tsx +20 -3
- package/dist/contexts/tests/mfe-data-context.test.d.ts +0 -2
- package/dist/contexts/tests/mfe-data-context.test.d.ts.map +0 -1
- package/dist/contexts/tests/mfe-data-context.test.js +0 -60
- package/dist/contexts/tests/mfe-data-context.test.js.map +0 -1
- package/dist/contexts/tests/mfe-metadata-context.test.d.ts +0 -2
- package/dist/contexts/tests/mfe-metadata-context.test.d.ts.map +0 -1
- package/dist/contexts/tests/mfe-metadata-context.test.js +0 -41
- package/dist/contexts/tests/mfe-metadata-context.test.js.map +0 -1
- package/src/__mocks__/expect-styles-in-dom.ts +0 -11
- package/src/__mocks__/index.ts +0 -3
- package/src/__mocks__/register-anvil2-harness.tsx +0 -49
- package/src/__mocks__/register-component.tsx +0 -20
- package/src/__mocks__/test-component.tsx +0 -41
- package/src/__tests__/common.test.ts +0 -204
- package/src/__tests__/delayed.test.tsx +0 -49
- package/src/__tests__/event-bus-types.test.ts +0 -620
- package/src/__tests__/event-bus.test.ts +0 -240
- package/src/__tests__/get-value-for-environment.test.ts +0 -95
- package/src/__tests__/globals.test.ts +0 -16
- package/src/__tests__/headless-loader.test.tsx +0 -123
- package/src/__tests__/history-manager.test.ts +0 -111
- package/src/__tests__/loader.test.tsx +0 -1178
- package/src/__tests__/register-anvil2-optional.test.tsx +0 -32
- package/src/__tests__/register-anvil2.test.tsx +0 -80
- package/src/__tests__/register-headless.test.tsx +0 -97
- package/src/__tests__/register-legacy-root.test.tsx +0 -38
- package/src/__tests__/register.test.tsx +0 -247
- package/src/__tests__/use-prefetch.test.tsx +0 -235
- package/src/contexts/tests/mfe-data-context.test.tsx +0 -64
- package/src/contexts/tests/mfe-metadata-context.test.tsx +0 -34
- package/src/css-injector/__tests__/mfe-style-registry.test.ts +0 -163
- package/src/css-injector/__tests__/with-css-injector.test.tsx +0 -128
- package/src/utils/__tests__/get-cached-metadata.test.ts +0 -94
- package/src/utils/__tests__/get-mfe-has-compatible-launchdarkly-version.test.ts +0 -54
- package/src/utils/__tests__/get-mfe-supports-rerendering.test.ts +0 -99
- package/src/utils/__tests__/get-mfe-supports-versioned-ld-client.test.ts +0 -38
- package/src/utils/__tests__/is-versioned-url.test.ts +0 -18
- package/src/utils/__tests__/load-scripts.test.ts +0 -171
- package/src/utils/__tests__/supports-prefetch.test.ts +0 -27
- package/src/utils/__tests__/ttl-cache.test.ts +0 -98
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import * as mitt from 'mitt';
|
|
2
|
-
import { EVENT_BUS_TOKEN, EventBus, typedEventBusToken } from '../event-bus';
|
|
3
|
-
|
|
4
|
-
jest.mock('mitt', () => jest.fn());
|
|
5
|
-
|
|
6
|
-
const allowListedEvents = [
|
|
7
|
-
':widgets:message',
|
|
8
|
-
'[EH] Module Link Clicked',
|
|
9
|
-
'[EH] Module Loaded',
|
|
10
|
-
'[internal] reset',
|
|
11
|
-
'blink',
|
|
12
|
-
'CLOSE_COMPONENT',
|
|
13
|
-
'CLOSE_JOB_EDIT_FLYOUT',
|
|
14
|
-
'company-profile-request-save',
|
|
15
|
-
'company-profile-saved-error',
|
|
16
|
-
'company-profile-saved',
|
|
17
|
-
'dismiss-discrepancy-event',
|
|
18
|
-
'dismiss-discrepancy-map-event',
|
|
19
|
-
'dispatch-JobEditFlyout-fetchData',
|
|
20
|
-
'DRAWER_CREATED_CUSTOMER',
|
|
21
|
-
'employees-emails-processed',
|
|
22
|
-
'employees-request-save',
|
|
23
|
-
'employees-saved-error',
|
|
24
|
-
'employees-saved',
|
|
25
|
-
'ium-ep-cancel-changes',
|
|
26
|
-
'ium-ep-form-can-be-submitted-change',
|
|
27
|
-
'ium-ep-save-changes',
|
|
28
|
-
'loaded',
|
|
29
|
-
'MESSAGE_TECHNICIAN',
|
|
30
|
-
'my-custom-event',
|
|
31
|
-
'NEW_EVENT',
|
|
32
|
-
'NonJobEventSelectedEvent',
|
|
33
|
-
'ON_WIDGET_INIT',
|
|
34
|
-
'OPEN_ASSIST_SCREEN',
|
|
35
|
-
'OPEN_CREATE_CUSTOMER_DRAWER',
|
|
36
|
-
'OPEN_DC_SIDE_PANEL_COMPONENT',
|
|
37
|
-
'OPEN_JOB_EDIT_FLYOUT',
|
|
38
|
-
'OPEN_RESCHEDULE_FLYOUT',
|
|
39
|
-
'open-troubleshooter',
|
|
40
|
-
'resolve-discrepancy-map-event',
|
|
41
|
-
'restore-discrepancy-event',
|
|
42
|
-
'setLabel',
|
|
43
|
-
'SHOW_POP_UP_MESSAGE',
|
|
44
|
-
'TEAMS_SELECTED',
|
|
45
|
-
'technicians-emails-processed',
|
|
46
|
-
'technicians-request-save',
|
|
47
|
-
'technicians-saved-error',
|
|
48
|
-
'technicians-saved',
|
|
49
|
-
'timesheet-activity-saved',
|
|
50
|
-
'TOGGLE_DC_SIDE_PANEL_COMPONENT',
|
|
51
|
-
'updateUserEmail',
|
|
52
|
-
'VIEW_NON_JOB_EVENT',
|
|
53
|
-
'visibility',
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
describe(`[web-components] ${EventBus.name}`, () => {
|
|
57
|
-
let eventBus: EventBus;
|
|
58
|
-
let event: string;
|
|
59
|
-
const handler = jest.fn();
|
|
60
|
-
const mittOn = jest.fn();
|
|
61
|
-
const mittOff = jest.fn();
|
|
62
|
-
const mittEmit = jest.fn();
|
|
63
|
-
|
|
64
|
-
beforeEach(() => {
|
|
65
|
-
jest.spyOn(mitt, 'default').mockImplementation((): any => ({
|
|
66
|
-
on: mittOn,
|
|
67
|
-
off: mittOff,
|
|
68
|
-
emit: mittEmit,
|
|
69
|
-
}));
|
|
70
|
-
|
|
71
|
-
eventBus = new EventBus();
|
|
72
|
-
event = 'example:event';
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
function withInvalidEvent(test: () => void) {
|
|
76
|
-
describe('with invalid event', () => {
|
|
77
|
-
beforeEach(() => (event = 'foo'));
|
|
78
|
-
|
|
79
|
-
test();
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function itRejectsInvalidEvent(subject: () => void) {
|
|
84
|
-
withInvalidEvent(() => {
|
|
85
|
-
test('throws error', () => {
|
|
86
|
-
expect(subject).toThrow();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
describe('on', () => {
|
|
92
|
-
const subject = (testEvent?: string | symbol) => eventBus.on(testEvent ?? event, handler);
|
|
93
|
-
|
|
94
|
-
test("calls the private mitt instance's 'on' method", () => {
|
|
95
|
-
subject();
|
|
96
|
-
expect(mittOn).toHaveBeenCalledWith(event, handler);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
itRejectsInvalidEvent(subject);
|
|
100
|
-
|
|
101
|
-
test.each([
|
|
102
|
-
'',
|
|
103
|
-
':',
|
|
104
|
-
':name',
|
|
105
|
-
'module:',
|
|
106
|
-
Symbol(),
|
|
107
|
-
Symbol.for(':'),
|
|
108
|
-
Symbol.for(':name'),
|
|
109
|
-
Symbol.for('module:'),
|
|
110
|
-
])('rejects "%s"', disallowed => {
|
|
111
|
-
expect(() => subject(disallowed)).toThrow();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test.each(allowListedEvents)('allows "%s" as string or Symbol', allowed => {
|
|
115
|
-
expect(() => subject(allowed)).not.toThrow();
|
|
116
|
-
expect(() => subject(Symbol.for(allowed))).not.toThrow();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
withInvalidEvent(() => {
|
|
120
|
-
describe('when in production environment', () => {
|
|
121
|
-
const nodeEnv = process.env.NODE_ENV;
|
|
122
|
-
|
|
123
|
-
beforeEach(() => (process.env.NODE_ENV = 'production'));
|
|
124
|
-
afterEach(() => (process.env.NODE_ENV = nodeEnv));
|
|
125
|
-
|
|
126
|
-
test('accepts event', () => {
|
|
127
|
-
expect(subject).not.toThrow();
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('off', () => {
|
|
134
|
-
const subject = () => eventBus.off(event, handler);
|
|
135
|
-
|
|
136
|
-
test("calls the private mitt instance's 'off' method", () => {
|
|
137
|
-
subject();
|
|
138
|
-
expect(mittOff).toHaveBeenCalledWith(event, handler);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('emit', () => {
|
|
143
|
-
const data = { foo: 'bar' };
|
|
144
|
-
const subject = () => eventBus.emit(event, data);
|
|
145
|
-
|
|
146
|
-
test("calls the private mitt instance's 'emit' method", () => {
|
|
147
|
-
subject();
|
|
148
|
-
expect(mittEmit).toHaveBeenCalledWith(event, data);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
itRejectsInvalidEvent(subject);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe('job.on', () => {
|
|
155
|
-
const subject = () => eventBus.job.on(event, handler);
|
|
156
|
-
|
|
157
|
-
test("calls the private mitt instance's 'on' method", () => {
|
|
158
|
-
subject();
|
|
159
|
-
expect(mittOn).toHaveBeenCalledWith(event, handler);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
itRejectsInvalidEvent(subject);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
describe('job.off', () => {
|
|
166
|
-
const subject = () => eventBus.job.off(event, handler);
|
|
167
|
-
|
|
168
|
-
test("calls the private mitt instance's 'off' method", () => {
|
|
169
|
-
subject();
|
|
170
|
-
expect(mittOff).toHaveBeenCalledWith(event, handler);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('job.emit', () => {
|
|
175
|
-
const subject = () => eventBus.job.emit(event);
|
|
176
|
-
|
|
177
|
-
describe("when emit's 'emit' resolves", () => {
|
|
178
|
-
beforeEach(() => {
|
|
179
|
-
mittEmit.mockImplementation((_: any, obj: any) => {
|
|
180
|
-
return obj.resolve();
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('the promise resolves', async () => {
|
|
185
|
-
await expect(subject()).resolves.toBeUndefined();
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe("when emit's 'emit' rejects", () => {
|
|
190
|
-
const setup = (reason?: any) =>
|
|
191
|
-
mittEmit.mockImplementation((_: any, obj: any) => {
|
|
192
|
-
return obj.reject(reason);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
describe('with a string reason', () => {
|
|
196
|
-
const reason = 'reason';
|
|
197
|
-
|
|
198
|
-
beforeEach(() => {
|
|
199
|
-
setup(reason);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test('the promise rejects with the reason', async () => {
|
|
203
|
-
await expect(subject()).rejects.toBe(reason);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
describe('with an error', () => {
|
|
208
|
-
const error = Error('reason');
|
|
209
|
-
|
|
210
|
-
beforeEach(() => {
|
|
211
|
-
setup(error);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test('the promise rejects with the error', async () => {
|
|
215
|
-
await expect(subject()).rejects.toBe(error);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe('with no argument', () => {
|
|
220
|
-
beforeEach(() => {
|
|
221
|
-
setup();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('the promise rejects', async () => {
|
|
225
|
-
await expect(subject()).rejects.toBeUndefined();
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
itRejectsInvalidEvent(subject);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
describe(`[web-components] ${typedEventBusToken.name}`, () => {
|
|
235
|
-
const subject = () => typedEventBusToken<any>();
|
|
236
|
-
|
|
237
|
-
test('returns EVENT_BUS_TOKEN', () => {
|
|
238
|
-
expect(subject()).toBe(EVENT_BUS_TOKEN);
|
|
239
|
-
});
|
|
240
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Environment,
|
|
3
|
-
EnvironmentValues,
|
|
4
|
-
getValueForEnvironment,
|
|
5
|
-
} from '../get-value-for-environment';
|
|
6
|
-
|
|
7
|
-
describe(`[web-components] ${getValueForEnvironment.name}`, () => {
|
|
8
|
-
const originalLocation = window.location;
|
|
9
|
-
let values: EnvironmentValues & { [key: string]: string };
|
|
10
|
-
let hostname: string | undefined;
|
|
11
|
-
let defaultEnvironment: Environment | undefined;
|
|
12
|
-
|
|
13
|
-
const subject = () => getValueForEnvironment(values, defaultEnvironment, hostname);
|
|
14
|
-
|
|
15
|
-
beforeAll(() => {
|
|
16
|
-
Object.defineProperty(window, 'location', {
|
|
17
|
-
configurable: true,
|
|
18
|
-
value: new URL('https://example.com'),
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
afterAll(() => {
|
|
22
|
-
Object.defineProperty(window, 'location', {
|
|
23
|
-
configurable: true,
|
|
24
|
-
value: originalLocation,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
values = { dev: 'dev-value', qa: 'qa-value', test: 'test-value' };
|
|
30
|
-
hostname = undefined;
|
|
31
|
-
defaultEnvironment = undefined;
|
|
32
|
-
process.env.NODE_ENV = 'production';
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
function itReturnsQAEnvironment() {
|
|
36
|
-
test('returns id for "qa" environment', () => {
|
|
37
|
-
expect(subject()).toBe(values.qa);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
itReturnsQAEnvironment();
|
|
42
|
-
|
|
43
|
-
describe('when in test environment', () => {
|
|
44
|
-
beforeEach(() => (process.env.NODE_ENV = 'test'));
|
|
45
|
-
|
|
46
|
-
test('returns id for "test" environment', () => {
|
|
47
|
-
expect(subject()).toBe(values.test);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('with a default environment', () => {
|
|
52
|
-
beforeEach(() => (defaultEnvironment = 'dev'));
|
|
53
|
-
|
|
54
|
-
test('returns id for default environment', () => {
|
|
55
|
-
expect(subject()).toBe(values[defaultEnvironment!]);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe.each(['127.0.0.1', 'localhost', 'app-web'])('when hostname contains "%s"', host => {
|
|
60
|
-
beforeEach(() => (hostname = host));
|
|
61
|
-
|
|
62
|
-
test('returns id for "dev" environment', () => {
|
|
63
|
-
expect(subject()).toBe(values.dev);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('when hostname contains "{key}.servicetitan.com"', () => {
|
|
68
|
-
const key = 'foo-bar';
|
|
69
|
-
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
hostname = `${key}.servicetitan.com`;
|
|
72
|
-
values = { [key]: 'key-value' };
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('returns key value', () => {
|
|
76
|
-
expect(subject()).toBe(values[key]);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('when hostname contains ".st.dev"', () => {
|
|
81
|
-
beforeEach(() => (hostname = 'foo-bar-stage.st.dev'));
|
|
82
|
-
|
|
83
|
-
itReturnsQAEnvironment();
|
|
84
|
-
|
|
85
|
-
describe('when key matches ".st.dev" domain', () => {
|
|
86
|
-
const key = 'stage.st.dev';
|
|
87
|
-
|
|
88
|
-
beforeEach(() => (values = { [key]: 'key-value' }));
|
|
89
|
-
|
|
90
|
-
test('returns key value', () => {
|
|
91
|
-
expect(subject()).toBe(values[key]);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
describe('[web-components] globals', () => {
|
|
2
|
-
function itExportsGlobal(globalName: string) {
|
|
3
|
-
test(`exports "${globalName}"`, () => {
|
|
4
|
-
jest.isolateModules(() => {
|
|
5
|
-
const globalValue = 'foo';
|
|
6
|
-
Object.assign(global, { [globalName]: globalValue });
|
|
7
|
-
const globalsExport = require('../globals')[globalName];
|
|
8
|
-
expect(globalsExport).toBe(globalValue);
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
['EXPOSED_DEPENDENCIES', 'EXPOSED_INSTANCE_DEPENDENCIES', 'WEB_COMPONENT_NAME'].forEach(name =>
|
|
14
|
-
itExportsGlobal(name)
|
|
15
|
-
);
|
|
16
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
2
|
-
import { act, render, waitFor } from '@testing-library/react';
|
|
3
|
-
import * as common from '../common';
|
|
4
|
-
import { HeadlessLoader } from '../headless-loader';
|
|
5
|
-
|
|
6
|
-
describe('[web-components] HeadlessLoader', () => {
|
|
7
|
-
class Page {
|
|
8
|
-
static get webComponent() {
|
|
9
|
-
return document.querySelector(`headless-${WEB_COMPONENT_NAME}`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
class WebComponent extends HTMLElement {
|
|
14
|
-
provide = () => {};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const baseName = 'mfe-component';
|
|
18
|
-
const baseUrl = 'http://unpkg.servicetitan.com/mfe';
|
|
19
|
-
const WEB_COMPONENT_NAME = `${baseName}-abc123`;
|
|
20
|
-
const metadata = {
|
|
21
|
-
name: WEB_COMPONENT_NAME,
|
|
22
|
-
version: `0.0.0-test-abc123`,
|
|
23
|
-
sharedDependencies: {},
|
|
24
|
-
dependencies: {},
|
|
25
|
-
entrypoints: {
|
|
26
|
-
full: {
|
|
27
|
-
css: ['full.css'],
|
|
28
|
-
js: ['full.js'],
|
|
29
|
-
},
|
|
30
|
-
light: {
|
|
31
|
-
css: ['light.css'],
|
|
32
|
-
js: ['light.js'],
|
|
33
|
-
},
|
|
34
|
-
headless: {
|
|
35
|
-
js: ['headless.js'],
|
|
36
|
-
css: [],
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const props = {
|
|
41
|
-
src: baseUrl,
|
|
42
|
-
loadingFallback: null,
|
|
43
|
-
};
|
|
44
|
-
let onloadRef: Function | null;
|
|
45
|
-
let getJsonMockFns: Record<string, Function>;
|
|
46
|
-
|
|
47
|
-
function initializeGetJsonMockFns() {
|
|
48
|
-
getJsonMockFns = {
|
|
49
|
-
[`${props.src}/dist/metadata.json`]: () => {
|
|
50
|
-
return Promise.resolve({
|
|
51
|
-
data: metadata,
|
|
52
|
-
headers: {} as Headers,
|
|
53
|
-
url: props.src,
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
beforeAll(() => {
|
|
60
|
-
// register web component in order to test the `provide` method
|
|
61
|
-
window.customElements.define(`headless-${WEB_COMPONENT_NAME}`, WebComponent);
|
|
62
|
-
|
|
63
|
-
/*
|
|
64
|
-
* mock <script>'s onload so that we can call it directly from the test,
|
|
65
|
-
* because it won't call itself in the test environment
|
|
66
|
-
*/
|
|
67
|
-
Object.defineProperty(HTMLScriptElement.prototype, 'onload', {
|
|
68
|
-
get() {
|
|
69
|
-
return this._onload;
|
|
70
|
-
},
|
|
71
|
-
set(onload: Function) {
|
|
72
|
-
onloadRef = onload;
|
|
73
|
-
this._onload = onload;
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
beforeEach(() => {
|
|
79
|
-
jest.resetAllMocks();
|
|
80
|
-
onloadRef = null;
|
|
81
|
-
initializeGetJsonMockFns();
|
|
82
|
-
document.querySelectorAll('script').forEach(script => script.remove());
|
|
83
|
-
jest.spyOn(common, 'getJson').mockImplementation((url, _) => {
|
|
84
|
-
if (getJsonMockFns[url] === undefined) {
|
|
85
|
-
throw new Error(`Unexpected getJson call with url: ${url}`);
|
|
86
|
-
}
|
|
87
|
-
return getJsonMockFns[url]();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
function subject() {
|
|
92
|
-
return render(<HeadlessLoader {...props} />);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
describe('after the script tag added is loaded', () => {
|
|
96
|
-
async function scriptLoadedSetup() {
|
|
97
|
-
const result = subject();
|
|
98
|
-
|
|
99
|
-
await waitFor(() => onloadRef !== undefined);
|
|
100
|
-
act(() => {
|
|
101
|
-
onloadRef!();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
await waitFor(() => expect(Page.webComponent).toBeInTheDocument());
|
|
105
|
-
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
test(`adds the headless entrypoint to a script tag`, async () => {
|
|
110
|
-
await scriptLoadedSetup();
|
|
111
|
-
const script = document.querySelector('script');
|
|
112
|
-
expect(script).toHaveAttribute(
|
|
113
|
-
'src',
|
|
114
|
-
`${baseUrl}/dist/bundle/headless/${metadata.entrypoints.headless.js[0]}`
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test('hides the web component', async () => {
|
|
119
|
-
await scriptLoadedSetup();
|
|
120
|
-
expect(Page.webComponent).toHaveStyle('display: none');
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createMemoryHistory, MemoryHistory } from 'history';
|
|
2
|
-
import { HistoryManager } from '../history-manager';
|
|
3
|
-
|
|
4
|
-
describe(`[web-components] ${HistoryManager.name}`, () => {
|
|
5
|
-
let historyManager: HistoryManager;
|
|
6
|
-
let history: MemoryHistory;
|
|
7
|
-
|
|
8
|
-
const url = '/foo';
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
jest.useFakeTimers();
|
|
12
|
-
history = createMemoryHistory();
|
|
13
|
-
historyManager = new HistoryManager();
|
|
14
|
-
historyManager.register(history);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('when user navigates to a new location', () => {
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
history.push(url);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('navigates to a new location', () => {
|
|
23
|
-
expect(history.location.pathname).toEqual(url);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('when a second history instance is registered', () => {
|
|
28
|
-
let history2: MemoryHistory;
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
history2 = createMemoryHistory();
|
|
32
|
-
historyManager.register(history2);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('when user navigates to a new location', () => {
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
history.push(url);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('navigates to a new location in all registered histories', () => {
|
|
41
|
-
expect(history.location.pathname).toEqual(url);
|
|
42
|
-
expect(history2.location.pathname).toEqual(url);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('when second history is unregistered', () => {
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
historyManager.unregister(history2);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('when user navigates to a new location', () => {
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
history.push(url);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('navigates the first history, but does not navigate second history', () => {
|
|
57
|
-
expect(history.location.pathname).toEqual(url);
|
|
58
|
-
expect(history2.location.pathname).not.toEqual(url);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('when a redirect is setup to go to a deeper page', () => {
|
|
64
|
-
const urlRedirect = '/foo/bar';
|
|
65
|
-
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
history2.listen(location => {
|
|
68
|
-
if (location.pathname === url) {
|
|
69
|
-
history2.replace(urlRedirect);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('when user navigates to a new location', () => {
|
|
75
|
-
beforeEach(() => {
|
|
76
|
-
history.push(url);
|
|
77
|
-
jest.runOnlyPendingTimers();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('redirects to deeper page', () => {
|
|
81
|
-
expect(history.location.pathname).toEqual(urlRedirect);
|
|
82
|
-
expect(history2.location.pathname).toEqual(urlRedirect);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('when a redirect is setup to go to a page that is not deeper', () => {
|
|
88
|
-
const urlRedirect = '/bar';
|
|
89
|
-
|
|
90
|
-
beforeEach(() => {
|
|
91
|
-
history2.listen(location => {
|
|
92
|
-
if (location.pathname === url) {
|
|
93
|
-
history2.replace(urlRedirect);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('when user navigates to a new location', () => {
|
|
99
|
-
beforeEach(() => {
|
|
100
|
-
history.push(url);
|
|
101
|
-
jest.runOnlyPendingTimers();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('does not redirect', () => {
|
|
105
|
-
expect(history.location.pathname).toEqual(url);
|
|
106
|
-
expect(history2.location.pathname).toEqual(url);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|