@dotcms/client 0.0.1-alpha.11 → 0.0.1-alpha.13
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/package.json +26 -24
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/client/{sdk-js-client.ts → sdk-js-client.d.ts} +13 -121
- package/src/lib/client/sdk-js-client.js +148 -0
- package/src/lib/client/sdk-js-client.js.map +1 -0
- package/src/lib/editor/listeners/listeners.d.ts +46 -0
- package/src/lib/editor/listeners/{listeners.ts → listeners.js} +38 -61
- package/src/lib/editor/listeners/listeners.js.map +1 -0
- package/src/lib/editor/models/{client.model.ts → client.model.d.ts} +13 -13
- package/src/lib/editor/models/client.model.js +45 -0
- package/src/lib/editor/models/client.model.js.map +1 -0
- package/src/lib/editor/models/{editor.model.ts → editor.model.d.ts} +0 -1
- package/src/lib/editor/models/editor.model.js +2 -0
- package/src/lib/editor/models/editor.model.js.map +1 -0
- package/src/lib/editor/models/{listeners.model.ts → listeners.model.d.ts} +5 -8
- package/src/lib/editor/models/listeners.model.js +22 -0
- package/src/lib/editor/models/listeners.model.js.map +1 -0
- package/src/lib/editor/sdk-editor-vtl.d.ts +6 -0
- package/src/lib/editor/{sdk-editor-vtl.ts → sdk-editor-vtl.js} +2 -14
- package/src/lib/editor/sdk-editor-vtl.js.map +1 -0
- package/src/lib/editor/sdk-editor.d.ts +23 -0
- package/src/lib/editor/{sdk-editor.ts → sdk-editor.js} +7 -21
- package/src/lib/editor/sdk-editor.js.map +1 -0
- package/src/lib/editor/utils/editor.utils.d.ts +82 -0
- package/src/lib/editor/utils/{editor.utils.ts → editor.utils.js} +25 -75
- package/src/lib/editor/utils/editor.utils.js.map +1 -0
- package/.eslintrc.json +0 -18
- package/jest.config.ts +0 -15
- package/project.json +0 -63
- package/src/lib/client/sdk-js-client.spec.ts +0 -258
- package/src/lib/editor/listeners/listeners.spec.ts +0 -58
- package/src/lib/editor/sdk-editor.spec.ts +0 -92
- package/src/lib/editor/utils/editor.utils.spec.ts +0 -164
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -9
- /package/src/{index.ts → index.d.ts} +0 -0
package/project.json
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sdk-client",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/sdk/client/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"targets": {
|
|
7
|
-
"build": {
|
|
8
|
-
"executor": "@nrwl/js:tsc",
|
|
9
|
-
"outputs": ["{options.outputPath}"],
|
|
10
|
-
"options": {
|
|
11
|
-
"outputPath": "dist/libs/sdk/client",
|
|
12
|
-
"main": "libs/sdk/client/src/index.ts",
|
|
13
|
-
"tsConfig": "libs/sdk/client/tsconfig.lib.json",
|
|
14
|
-
"assets": ["libs/sdk/client/*.md"]
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"build:js": {
|
|
18
|
-
"executor": "@nrwl/rollup:rollup",
|
|
19
|
-
"outputs": ["{options.outputPath}"],
|
|
20
|
-
"options": {
|
|
21
|
-
"outputPath": "../dotCMS/src/main/webapp/html/js/editor-js",
|
|
22
|
-
"outputFileName": "sdk-editor",
|
|
23
|
-
"format": ["esm"],
|
|
24
|
-
"tsConfig": "libs/sdk/client/tsconfig.lib.json",
|
|
25
|
-
"project": "libs/sdk/client/package.json",
|
|
26
|
-
"entryFile": "libs/sdk/client/src/lib/editor/sdk-editor-vtl.ts",
|
|
27
|
-
"external": ["react/jsx-runtime"],
|
|
28
|
-
"rollupConfig": "@nrwl/react/plugins/bundle-rollup",
|
|
29
|
-
"compiler": "swc",
|
|
30
|
-
"extractCss": false
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"publish": {
|
|
34
|
-
"executor": "nx:run-commands",
|
|
35
|
-
"options": {
|
|
36
|
-
"command": "node tools/scripts/publish.mjs sdk-js-client {args.ver} {args.tag}"
|
|
37
|
-
},
|
|
38
|
-
"dependsOn": ["build"]
|
|
39
|
-
},
|
|
40
|
-
"lint": {
|
|
41
|
-
"executor": "@nrwl/linter:eslint",
|
|
42
|
-
"outputs": ["{options.outputFile}"],
|
|
43
|
-
"options": {
|
|
44
|
-
"lintFilePatterns": ["libs/sdk/client/**/*.ts"]
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"test": {
|
|
48
|
-
"executor": "@nrwl/jest:jest",
|
|
49
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
50
|
-
"options": {
|
|
51
|
-
"jestConfig": "libs/sdk/client/jest.config.ts",
|
|
52
|
-
"passWithNoTests": true
|
|
53
|
-
},
|
|
54
|
-
"configurations": {
|
|
55
|
-
"ci": {
|
|
56
|
-
"ci": true,
|
|
57
|
-
"codeCoverage": true
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"tags": []
|
|
63
|
-
}
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
import { DotCmsClient, dotcmsClient } from './sdk-js-client';
|
|
4
|
-
global.fetch = jest.fn();
|
|
5
|
-
|
|
6
|
-
// Utility function to mock fetch responses
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
const mockFetchResponse = (body: any, ok = true, status = 200) => {
|
|
9
|
-
(fetch as jest.Mock).mockImplementationOnce(() =>
|
|
10
|
-
Promise.resolve({
|
|
11
|
-
ok,
|
|
12
|
-
status,
|
|
13
|
-
json: () => Promise.resolve(body)
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
describe('DotCmsClient', () => {
|
|
19
|
-
describe('with full configuration', () => {
|
|
20
|
-
let client: DotCmsClient;
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
(fetch as jest.Mock).mockClear();
|
|
24
|
-
|
|
25
|
-
client = dotcmsClient.init({
|
|
26
|
-
dotcmsUrl: 'http://localhost',
|
|
27
|
-
siteId: '123456',
|
|
28
|
-
authToken: 'ABC'
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('init', () => {
|
|
33
|
-
it('should initialize with valid configuration', () => {
|
|
34
|
-
const config = {
|
|
35
|
-
dotcmsUrl: 'https://example.com',
|
|
36
|
-
siteId: '123456',
|
|
37
|
-
authToken: 'ABC'
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const client = dotcmsClient.init(config);
|
|
41
|
-
expect(client).toBeDefined();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should throw error on missing dotcmsUrl', () => {
|
|
45
|
-
const config = {
|
|
46
|
-
dotcmsUrl: '',
|
|
47
|
-
siteId: '123456',
|
|
48
|
-
authToken: 'ABC'
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
expect(() => {
|
|
52
|
-
dotcmsClient.init(config);
|
|
53
|
-
}).toThrow("Invalid configuration - 'dotcmsUrl' is required");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should throw error if dotcmsUrl is not a valid URL', () => {
|
|
57
|
-
const config = {
|
|
58
|
-
dotcmsUrl: '//example.com',
|
|
59
|
-
siteId: '123456',
|
|
60
|
-
authToken: 'ABC'
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
expect(() => {
|
|
64
|
-
dotcmsClient.init(config);
|
|
65
|
-
}).toThrow("Invalid configuration - 'dotcmsUrl' must be a valid URL");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should throw error on missing authToken', () => {
|
|
69
|
-
const config = {
|
|
70
|
-
dotcmsUrl: 'https://example.com',
|
|
71
|
-
siteId: '123456',
|
|
72
|
-
authToken: ''
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
expect(() => {
|
|
76
|
-
dotcmsClient.init(config);
|
|
77
|
-
}).toThrow("Invalid configuration - 'authToken' is required");
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('page.get', () => {
|
|
82
|
-
it('should fetch page data successfully', async () => {
|
|
83
|
-
const mockResponse = { content: 'Page data' };
|
|
84
|
-
mockFetchResponse(mockResponse);
|
|
85
|
-
|
|
86
|
-
const data = await client.page.get({ path: '/home' });
|
|
87
|
-
|
|
88
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
89
|
-
expect(fetch).toHaveBeenCalledWith(
|
|
90
|
-
'http://localhost/api/v1/page/json/home?host_id=123456',
|
|
91
|
-
{
|
|
92
|
-
headers: { Authorization: 'Bearer ABC' }
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
expect(data).toEqual(mockResponse);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should throw an error if the path is not provided', async () => {
|
|
99
|
-
await expect(client.page.get({} as any)).rejects.toThrowError(
|
|
100
|
-
`The 'path' parameter is required for the Page API`
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should get the page for specified persona', () => {
|
|
105
|
-
const mockResponse = { content: 'Page data' };
|
|
106
|
-
mockFetchResponse(mockResponse);
|
|
107
|
-
|
|
108
|
-
client.page.get({ path: '/home', personaId: 'doe123' });
|
|
109
|
-
|
|
110
|
-
expect(fetch).toHaveBeenCalledWith(
|
|
111
|
-
'http://localhost/api/v1/page/json/home?com.dotmarketing.persona.id=doe123&host_id=123456',
|
|
112
|
-
{
|
|
113
|
-
headers: { Authorization: 'Bearer ABC' }
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should get the page for specified siteId', () => {
|
|
119
|
-
const mockResponse = { content: 'Page data' };
|
|
120
|
-
mockFetchResponse(mockResponse);
|
|
121
|
-
|
|
122
|
-
client.page.get({ path: '/home', siteId: 'host-123' });
|
|
123
|
-
|
|
124
|
-
expect(fetch).toHaveBeenCalledWith(
|
|
125
|
-
'http://localhost/api/v1/page/json/home?host_id=host-123',
|
|
126
|
-
{
|
|
127
|
-
headers: { Authorization: 'Bearer ABC' }
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should get the page for specified language', () => {
|
|
133
|
-
const mockResponse = { content: 'Page data' };
|
|
134
|
-
mockFetchResponse(mockResponse);
|
|
135
|
-
|
|
136
|
-
client.page.get({ path: '/home', language_id: 99 });
|
|
137
|
-
|
|
138
|
-
expect(fetch).toHaveBeenCalledWith(
|
|
139
|
-
'http://localhost/api/v1/page/json/home?language_id=99&host_id=123456',
|
|
140
|
-
{
|
|
141
|
-
headers: { Authorization: 'Bearer ABC' }
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('nav.get', () => {
|
|
148
|
-
it('should fetch navigation data successfully', async () => {
|
|
149
|
-
const mockResponse = { nav: 'Navigation data' };
|
|
150
|
-
mockFetchResponse(mockResponse);
|
|
151
|
-
|
|
152
|
-
const data = await client.nav.get({ path: '/', depth: 1 });
|
|
153
|
-
|
|
154
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
155
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost/api/v1/nav/?depth=1', {
|
|
156
|
-
headers: { Authorization: 'Bearer ABC' }
|
|
157
|
-
});
|
|
158
|
-
expect(data).toEqual(mockResponse);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should correctly handle the root path', async () => {
|
|
162
|
-
const mockResponse = { nav: 'Root nav data' };
|
|
163
|
-
mockFetchResponse(mockResponse);
|
|
164
|
-
|
|
165
|
-
const data = await client.nav.get({ path: '/' });
|
|
166
|
-
|
|
167
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost/api/v1/nav/', {
|
|
168
|
-
headers: { Authorization: 'Bearer ABC' }
|
|
169
|
-
});
|
|
170
|
-
expect(data).toEqual(mockResponse);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should throw an error if the path is not provided', async () => {
|
|
174
|
-
await expect(client.nav.get({} as any)).rejects.toThrowError(
|
|
175
|
-
`The 'path' parameter is required for the Nav API`
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('with minimal configuration', () => {
|
|
182
|
-
let client: DotCmsClient;
|
|
183
|
-
|
|
184
|
-
beforeEach(() => {
|
|
185
|
-
(fetch as jest.Mock).mockClear();
|
|
186
|
-
|
|
187
|
-
client = dotcmsClient.init({
|
|
188
|
-
dotcmsUrl: 'http://localhost',
|
|
189
|
-
authToken: 'ABC'
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should get the page without siteId', () => {
|
|
194
|
-
const mockResponse = { content: 'Page data' };
|
|
195
|
-
mockFetchResponse(mockResponse);
|
|
196
|
-
|
|
197
|
-
client.page.get({ path: '/home' });
|
|
198
|
-
|
|
199
|
-
expect(fetch).toHaveBeenCalledWith('http://localhost/api/v1/page/json/home', {
|
|
200
|
-
headers: { Authorization: 'Bearer ABC' }
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe('with requestOptions', () => {
|
|
206
|
-
let client: DotCmsClient;
|
|
207
|
-
|
|
208
|
-
beforeEach(() => {
|
|
209
|
-
(fetch as jest.Mock).mockClear();
|
|
210
|
-
|
|
211
|
-
client = dotcmsClient.init({
|
|
212
|
-
dotcmsUrl: 'http://localhost',
|
|
213
|
-
siteId: '123456',
|
|
214
|
-
authToken: 'ABC',
|
|
215
|
-
requestOptions: {
|
|
216
|
-
headers: {
|
|
217
|
-
'X-My-Header': 'my-value'
|
|
218
|
-
},
|
|
219
|
-
cache: 'no-cache'
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('should fetch page data with extra headers and cache', async () => {
|
|
225
|
-
const mockResponse = { content: 'Page data' };
|
|
226
|
-
mockFetchResponse(mockResponse);
|
|
227
|
-
|
|
228
|
-
const data = await client.page.get({ path: '/home' });
|
|
229
|
-
|
|
230
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
231
|
-
expect(fetch).toHaveBeenCalledWith(
|
|
232
|
-
'http://localhost/api/v1/page/json/home?host_id=123456',
|
|
233
|
-
{
|
|
234
|
-
headers: { Authorization: 'Bearer ABC', 'X-My-Header': 'my-value' },
|
|
235
|
-
cache: 'no-cache'
|
|
236
|
-
}
|
|
237
|
-
);
|
|
238
|
-
expect(data).toEqual(mockResponse);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('should fetch bav data with extra headers and cache', async () => {
|
|
242
|
-
const mockResponse = { content: 'Page data' };
|
|
243
|
-
mockFetchResponse(mockResponse);
|
|
244
|
-
|
|
245
|
-
const data = await client.nav.get();
|
|
246
|
-
|
|
247
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
248
|
-
expect(fetch).toHaveBeenCalledWith(
|
|
249
|
-
'http://localhost/api/v1/nav/?depth=0&languageId=1',
|
|
250
|
-
{
|
|
251
|
-
headers: { Authorization: 'Bearer ABC', 'X-My-Header': 'my-value' },
|
|
252
|
-
cache: 'no-cache'
|
|
253
|
-
}
|
|
254
|
-
);
|
|
255
|
-
expect(data).toEqual(mockResponse);
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
listenEditorMessages,
|
|
3
|
-
listenHoveredContentlet,
|
|
4
|
-
pingEditor,
|
|
5
|
-
preserveScrollOnIframe,
|
|
6
|
-
scrollHandler
|
|
7
|
-
} from './listeners';
|
|
8
|
-
|
|
9
|
-
import { CUSTOMER_ACTIONS, postMessageToEditor } from '../models/client.model';
|
|
10
|
-
|
|
11
|
-
jest.mock('../models/client.model', () => ({
|
|
12
|
-
postMessageToEditor: jest.fn(),
|
|
13
|
-
CUSTOMER_ACTIONS: {
|
|
14
|
-
NAVIGATION_UPDATE: 'set-url',
|
|
15
|
-
SET_BOUNDS: 'set-bounds',
|
|
16
|
-
SET_CONTENTLET: 'set-contentlet',
|
|
17
|
-
IFRAME_SCROLL: 'scroll',
|
|
18
|
-
PING_EDITOR: 'ping-editor',
|
|
19
|
-
CONTENT_CHANGE: 'content-change',
|
|
20
|
-
NOOP: 'noop'
|
|
21
|
-
}
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Observation: We must test the execution of methods as well.
|
|
26
|
-
*/
|
|
27
|
-
describe('listeners', () => {
|
|
28
|
-
it('should listen editor messages', () => {
|
|
29
|
-
const addEventListenerSpy = jest.spyOn(window, 'addEventListener');
|
|
30
|
-
listenEditorMessages();
|
|
31
|
-
expect(addEventListenerSpy).toHaveBeenCalledWith('message', expect.any(Function));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should listen to hovered contentlet', () => {
|
|
35
|
-
const addEventListenerSpy = jest.spyOn(document, 'addEventListener');
|
|
36
|
-
listenHoveredContentlet();
|
|
37
|
-
expect(addEventListenerSpy).toHaveBeenCalledWith('pointermove', expect.any(Function));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should handle scroll', () => {
|
|
41
|
-
const addEventListenerSpy = jest.spyOn(window, 'addEventListener');
|
|
42
|
-
scrollHandler();
|
|
43
|
-
expect(addEventListenerSpy).toHaveBeenCalledWith('scroll', expect.any(Function));
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should preserve scroll on iframe', () => {
|
|
47
|
-
const addEventListenerSpy = jest.spyOn(window, 'addEventListener');
|
|
48
|
-
preserveScrollOnIframe();
|
|
49
|
-
expect(addEventListenerSpy).toHaveBeenCalledWith('load', expect.any(Function));
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should send ping to editor', () => {
|
|
53
|
-
pingEditor();
|
|
54
|
-
expect(postMessageToEditor).toHaveBeenCalledWith({
|
|
55
|
-
action: CUSTOMER_ACTIONS.PING_EDITOR
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
listenEditorMessages,
|
|
3
|
-
listenHoveredContentlet,
|
|
4
|
-
pingEditor,
|
|
5
|
-
scrollHandler
|
|
6
|
-
} from './listeners/listeners';
|
|
7
|
-
import { postMessageToEditor, CUSTOMER_ACTIONS } from './models/client.model';
|
|
8
|
-
import { initEditor, isInsideEditor, updateNavigation } from './sdk-editor';
|
|
9
|
-
|
|
10
|
-
jest.mock('./models/client.model', () => ({
|
|
11
|
-
postMessageToEditor: jest.fn(),
|
|
12
|
-
CUSTOMER_ACTIONS: {
|
|
13
|
-
NAVIGATION_UPDATE: 'set-url',
|
|
14
|
-
SET_BOUNDS: 'set-bounds',
|
|
15
|
-
SET_CONTENTLET: 'set-contentlet',
|
|
16
|
-
IFRAME_SCROLL: 'scroll',
|
|
17
|
-
PING_EDITOR: 'ping-editor',
|
|
18
|
-
CONTENT_CHANGE: 'content-change',
|
|
19
|
-
NOOP: 'noop'
|
|
20
|
-
}
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
jest.mock('./listeners/listeners', () => ({
|
|
24
|
-
pingEditor: jest.fn(),
|
|
25
|
-
listenEditorMessages: jest.fn(),
|
|
26
|
-
listenHoveredContentlet: jest.fn(),
|
|
27
|
-
scrollHandler: jest.fn(),
|
|
28
|
-
listenContentChange: jest.fn()
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
describe('DotCMSPageEditor', () => {
|
|
32
|
-
describe('is NOT inside editor', () => {
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
const mockWindow = {
|
|
35
|
-
...window,
|
|
36
|
-
parent: window
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const spy = jest.spyOn(global, 'window', 'get');
|
|
40
|
-
spy.mockReturnValueOnce(mockWindow as unknown as Window & typeof globalThis);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
jest.clearAllMocks();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should initialize without any listener', () => {
|
|
48
|
-
const addEventListenerSpy = jest.spyOn(window, 'addEventListener');
|
|
49
|
-
|
|
50
|
-
expect(isInsideEditor()).toBe(false);
|
|
51
|
-
expect(addEventListenerSpy).not.toHaveBeenCalled();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('is inside editor', () => {
|
|
56
|
-
beforeEach(() => {
|
|
57
|
-
const mockWindow = {
|
|
58
|
-
...window,
|
|
59
|
-
parent: null
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const spy = jest.spyOn(global, 'window', 'get');
|
|
63
|
-
spy.mockReturnValue(mockWindow as unknown as Window & typeof globalThis);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
afterEach(() => {
|
|
67
|
-
jest.clearAllMocks();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should initialize properly', () => {
|
|
71
|
-
expect(isInsideEditor()).toBe(true);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should update navigation', () => {
|
|
75
|
-
updateNavigation('/');
|
|
76
|
-
expect(postMessageToEditor).toHaveBeenCalledWith({
|
|
77
|
-
action: CUSTOMER_ACTIONS.NAVIGATION_UPDATE,
|
|
78
|
-
payload: {
|
|
79
|
-
url: 'index'
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should init editor calling listeners', () => {
|
|
85
|
-
initEditor();
|
|
86
|
-
expect(pingEditor).toHaveBeenCalled();
|
|
87
|
-
expect(listenEditorMessages).toHaveBeenCalled();
|
|
88
|
-
expect(listenHoveredContentlet).toHaveBeenCalled();
|
|
89
|
-
expect(scrollHandler).toHaveBeenCalled();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { getContentletsBound } from './editor.utils';
|
|
2
|
-
|
|
3
|
-
describe('getContentletsBound', () => {
|
|
4
|
-
const createContentlet = ({
|
|
5
|
-
x,
|
|
6
|
-
y,
|
|
7
|
-
width,
|
|
8
|
-
height,
|
|
9
|
-
dataset
|
|
10
|
-
}: {
|
|
11
|
-
x: number;
|
|
12
|
-
y: number;
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
dataset: { [key: string]: string };
|
|
16
|
-
}): HTMLDivElement => {
|
|
17
|
-
const contentlet = document.createElement('div');
|
|
18
|
-
const mockGetBoundingClientRect = jest.fn(() => ({
|
|
19
|
-
x,
|
|
20
|
-
y,
|
|
21
|
-
width,
|
|
22
|
-
height
|
|
23
|
-
})) as unknown as () => DOMRect;
|
|
24
|
-
contentlet.getBoundingClientRect = mockGetBoundingClientRect;
|
|
25
|
-
Object.keys(dataset).forEach((key) => {
|
|
26
|
-
contentlet.setAttribute(`data-${key}`, dataset[key]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return contentlet;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const containerRect = {
|
|
33
|
-
x: 0,
|
|
34
|
-
y: 0,
|
|
35
|
-
width: 100,
|
|
36
|
-
height: 100,
|
|
37
|
-
top: 0,
|
|
38
|
-
right: 100,
|
|
39
|
-
bottom: 100,
|
|
40
|
-
left: 0
|
|
41
|
-
} as DOMRect;
|
|
42
|
-
|
|
43
|
-
const contentlets: HTMLDivElement[] = [
|
|
44
|
-
createContentlet({
|
|
45
|
-
x: 10,
|
|
46
|
-
y: 20,
|
|
47
|
-
width: 30,
|
|
48
|
-
height: 40,
|
|
49
|
-
dataset: {
|
|
50
|
-
'dot-container': JSON.stringify({ uuid: 'container1' }),
|
|
51
|
-
'dot-identifier': 'contentlet1',
|
|
52
|
-
'dot-title': 'Contentlet 1',
|
|
53
|
-
'dot-inode': 'inode1',
|
|
54
|
-
'dot-type': 'type1'
|
|
55
|
-
}
|
|
56
|
-
}),
|
|
57
|
-
createContentlet({
|
|
58
|
-
x: 50,
|
|
59
|
-
y: 60,
|
|
60
|
-
width: 70,
|
|
61
|
-
height: 80,
|
|
62
|
-
dataset: {
|
|
63
|
-
'dot-container': JSON.stringify({ uuid: 'container1' }),
|
|
64
|
-
'dot-identifier': 'contentlet2',
|
|
65
|
-
'dot-title': 'Contentlet 2',
|
|
66
|
-
'dot-inode': 'inode2',
|
|
67
|
-
'dot-type': 'type2'
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
it('should return an array of contentlets bound from contentlet with data atrribute dotContainer ', () => {
|
|
73
|
-
const result = getContentletsBound(containerRect, contentlets);
|
|
74
|
-
|
|
75
|
-
expect(result).toEqual([
|
|
76
|
-
{
|
|
77
|
-
x: 0,
|
|
78
|
-
y: 20,
|
|
79
|
-
width: 30,
|
|
80
|
-
height: 40,
|
|
81
|
-
payload: JSON.stringify({
|
|
82
|
-
container: { uuid: 'container1' },
|
|
83
|
-
contentlet: {
|
|
84
|
-
identifier: 'contentlet1',
|
|
85
|
-
title: 'Contentlet 1',
|
|
86
|
-
inode: 'inode1',
|
|
87
|
-
contentType: 'type1'
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
x: 0,
|
|
93
|
-
y: 60,
|
|
94
|
-
width: 70,
|
|
95
|
-
height: 80,
|
|
96
|
-
payload: JSON.stringify({
|
|
97
|
-
container: { uuid: 'container1' },
|
|
98
|
-
contentlet: {
|
|
99
|
-
identifier: 'contentlet2',
|
|
100
|
-
title: 'Contentlet 2',
|
|
101
|
-
inode: 'inode2',
|
|
102
|
-
contentType: 'type2'
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
]);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should return an empty array if contentlets is empty', () => {
|
|
110
|
-
const result = getContentletsBound(containerRect, []);
|
|
111
|
-
|
|
112
|
-
expect(result).toEqual([]);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should return an array of contentlets with correct properties when dotContainer is not present in dataset', () => {
|
|
116
|
-
const contentletsWithMissingContainer: HTMLDivElement[] = [
|
|
117
|
-
createContentlet({
|
|
118
|
-
x: 10,
|
|
119
|
-
y: 20,
|
|
120
|
-
width: 30,
|
|
121
|
-
height: 40,
|
|
122
|
-
dataset: {
|
|
123
|
-
'dot-identifier': 'contentlet1',
|
|
124
|
-
'dot-title': 'Contentlet 1',
|
|
125
|
-
'dot-inode': 'inode1',
|
|
126
|
-
'dot-type': 'type1'
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
const container = document.createElement('div');
|
|
132
|
-
|
|
133
|
-
container.appendChild(contentletsWithMissingContainer[0]);
|
|
134
|
-
container.setAttribute('data-dot-object', 'container');
|
|
135
|
-
container.setAttribute('data-dot-accept-types', '[Blogs]');
|
|
136
|
-
container.setAttribute('data-dot-identifier', '1');
|
|
137
|
-
container.setAttribute('data-max-contentlets', '1');
|
|
138
|
-
container.setAttribute('data-dot-uuid', '1');
|
|
139
|
-
const result = getContentletsBound(containerRect, contentletsWithMissingContainer);
|
|
140
|
-
|
|
141
|
-
expect(result).toEqual([
|
|
142
|
-
{
|
|
143
|
-
x: 0,
|
|
144
|
-
y: 20,
|
|
145
|
-
width: 30,
|
|
146
|
-
height: 40,
|
|
147
|
-
payload: JSON.stringify({
|
|
148
|
-
container: {
|
|
149
|
-
acceptTypes: '[Blogs]',
|
|
150
|
-
identifier: '1',
|
|
151
|
-
maxContentlets: '1',
|
|
152
|
-
uuid: '1'
|
|
153
|
-
},
|
|
154
|
-
contentlet: {
|
|
155
|
-
identifier: 'contentlet1',
|
|
156
|
-
title: 'Contentlet 1',
|
|
157
|
-
inode: 'inode1',
|
|
158
|
-
contentType: 'type1'
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
]);
|
|
163
|
-
});
|
|
164
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"forceConsistentCasingInFileNames": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"noImplicitOverride": true,
|
|
8
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
9
|
-
"noImplicitReturns": true,
|
|
10
|
-
"noFallthroughCasesInSwitch": true
|
|
11
|
-
},
|
|
12
|
-
"files": [],
|
|
13
|
-
"include": [],
|
|
14
|
-
"references": [
|
|
15
|
-
{
|
|
16
|
-
"path": "./tsconfig.lib.json"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"path": "./tsconfig.spec.json"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
package/tsconfig.lib.json
DELETED
package/tsconfig.spec.json
DELETED
|
File without changes
|