@griddo/ax 12.13.1 → 12.14.1
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/config/webpack.config.js +1 -1
- package/package.json +4 -4
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.caption.test.tsx +381 -33
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.test.tsx +1 -0
- package/src/__tests__/containers/PageEditor/accessGrants.test.ts +104 -0
- package/src/__tests__/containers/PageEditor/savePageForbidden.test.ts +66 -0
- package/src/__tests__/forms/validators.test.ts +37 -0
- package/src/__tests__/gainup-trace.test.ts +1 -1
- package/src/__tests__/hooks/permissionsForPageKeys.contract.test.ts +50 -0
- package/src/__tests__/hooks/permissionsPageId.test.ts +17 -0
- package/src/__tests__/hooks/users.test.tsx +167 -8
- package/src/components/Fields/Wysiwyg/helpers.tsx +188 -0
- package/src/components/Fields/Wysiwyg/index.tsx +97 -28
- package/src/components/Fields/Wysiwyg/style.tsx +5 -0
- package/src/containers/PageEditor/actions.tsx +70 -49
- package/src/containers/PageEditor/constants.tsx +4 -0
- package/src/forms/errors.tsx +2 -2
- package/src/forms/validators.tsx +14 -12
- package/src/hooks/index.tsx +12 -6
- package/src/hooks/users.tsx +84 -9
- package/src/modules/ActivityLog/DownloadModal/index.tsx +4 -2
- package/src/modules/ActivityLog/index.tsx +6 -5
- package/src/modules/GlobalEditor/index.tsx +2 -1
- package/src/modules/PageEditor/index.tsx +2 -1
package/config/webpack.config.js
CHANGED
|
@@ -83,7 +83,7 @@ const hasJsxRuntime = (() => {
|
|
|
83
83
|
|
|
84
84
|
// This is the production and development configuration.
|
|
85
85
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
86
|
-
module.exports =
|
|
86
|
+
module.exports = (webpackEnv) => {
|
|
87
87
|
const isEnvDevelopment = webpackEnv === "development";
|
|
88
88
|
const isEnvProduction = webpackEnv === "production";
|
|
89
89
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.14.1",
|
|
5
5
|
"homepage": "https://griddo.io",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
129
|
"@biomejs/biome": "2.5.15",
|
|
130
|
-
"@griddo/core": "12.
|
|
130
|
+
"@griddo/core": "12.14.1",
|
|
131
131
|
"@types/redux-mock-store": "1.5.0",
|
|
132
132
|
"@vitest/coverage-v8": "4.1.11",
|
|
133
133
|
"axios-mock-adapter": "1.22.0",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"vitest-styled-components": "1.0.0"
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"@griddo/core": "12.
|
|
141
|
+
"@griddo/core": "12.14.1"
|
|
142
142
|
},
|
|
143
143
|
"babel": {
|
|
144
144
|
"presets": [
|
|
@@ -171,5 +171,5 @@
|
|
|
171
171
|
"publishConfig": {
|
|
172
172
|
"access": "public"
|
|
173
173
|
},
|
|
174
|
-
"gitHead": "
|
|
174
|
+
"gitHead": "e9041d4a7f71dfa96cbcc9ca4ccf43db0b33aa43"
|
|
175
175
|
}
|
|
@@ -14,11 +14,13 @@ import { cleanup, render, waitFor } from "../../../../../config/tests/test-utils
|
|
|
14
14
|
|
|
15
15
|
const schemasConfig = config.schemas.config;
|
|
16
16
|
const store = configureStore()({ app: { token: "token" } });
|
|
17
|
+
// What AX keeps of the content: the editor's HTML only reaches it through here
|
|
18
|
+
const onChange = vi.fn();
|
|
17
19
|
|
|
18
20
|
const mountEditor = async (value: string) => {
|
|
19
21
|
const { container } = render(
|
|
20
22
|
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
21
|
-
<Wysiwyg value={value} onChange={
|
|
23
|
+
<Wysiwyg value={value} onChange={onChange} site={null} />
|
|
22
24
|
</ThemeProvider>,
|
|
23
25
|
{ store },
|
|
24
26
|
);
|
|
@@ -42,6 +44,20 @@ const rect = (width: number) =>
|
|
|
42
44
|
|
|
43
45
|
const caption = (editor: any): HTMLElement | null => editor.el.querySelector(".fr-img-caption");
|
|
44
46
|
|
|
47
|
+
// The editor's top level: each paragraph by its text, anything else by its class
|
|
48
|
+
const outline = (editor: any) =>
|
|
49
|
+
[...editor.el.children].map((el: HTMLElement) => (el.tagName === "P" ? `p: ${el.textContent}` : el.className));
|
|
50
|
+
|
|
51
|
+
const caretAt = (node: Node, offset: number) => {
|
|
52
|
+
const range = document.createRange();
|
|
53
|
+
range.setStart(node, offset);
|
|
54
|
+
getSelection()?.removeAllRanges();
|
|
55
|
+
getSelection()?.addRange(range);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const press = (editor: any, key: string) =>
|
|
59
|
+
editor.el.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
|
|
60
|
+
|
|
45
61
|
describe("Wysiwyg image caption", () => {
|
|
46
62
|
beforeAll(() => {
|
|
47
63
|
// Froala's licence check splits document.domain, which jsdom leaves undefined
|
|
@@ -72,32 +88,39 @@ describe("Wysiwyg image caption", () => {
|
|
|
72
88
|
expect(inner?.getAttribute("contenteditable")).toBe("true");
|
|
73
89
|
});
|
|
74
90
|
|
|
75
|
-
|
|
91
|
+
// The site sizes an image that has no width of its own: a width taken from
|
|
92
|
+
// how it shows in the editor would override that
|
|
93
|
+
it("should give no width to a never resized image, or to its caption", async () => {
|
|
76
94
|
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
77
|
-
|
|
95
|
+
const img = editor.el.querySelector("img");
|
|
96
|
+
vi.spyOn(img, "getBoundingClientRect").mockReturnValue(rect(300));
|
|
78
97
|
vi.spyOn(editor.el.querySelector("p"), "getBoundingClientRect").mockReturnValue(rect(600));
|
|
79
98
|
|
|
80
99
|
toggleCaption(editor);
|
|
81
100
|
|
|
82
|
-
expect(caption(editor)?.style
|
|
101
|
+
expect(caption(editor)?.hasAttribute("style")).toBe(false);
|
|
102
|
+
expect(img.hasAttribute("style")).toBe(false);
|
|
83
103
|
});
|
|
84
104
|
|
|
85
|
-
it("should
|
|
86
|
-
const editor = await mountEditor(
|
|
105
|
+
it("should keep a never resized image's other styles when it is captioned", async () => {
|
|
106
|
+
const editor = await mountEditor(
|
|
107
|
+
'<p><img src="http://x/a.png" alt="" class="fr-dib" style="height: 200px;"></p>',
|
|
108
|
+
);
|
|
109
|
+
const img = editor.el.querySelector("img");
|
|
87
110
|
|
|
88
111
|
toggleCaption(editor);
|
|
89
112
|
|
|
90
|
-
expect(
|
|
113
|
+
expect(img.getAttribute("style")).toBe("height: 200px;");
|
|
91
114
|
});
|
|
92
115
|
|
|
93
|
-
it("should
|
|
116
|
+
it("should give a resized image's width to its caption, and keep it on the image", async () => {
|
|
94
117
|
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib" style="width: 40%;"></p>');
|
|
95
118
|
const img = editor.el.querySelector("img");
|
|
96
119
|
|
|
97
120
|
toggleCaption(editor);
|
|
98
121
|
|
|
99
122
|
expect(caption(editor)?.style.width).toBe("40%");
|
|
100
|
-
expect(img.style.width).toBe("");
|
|
123
|
+
expect(img.style.width).toBe("40%");
|
|
101
124
|
|
|
102
125
|
toggleCaption(editor);
|
|
103
126
|
|
|
@@ -111,7 +134,6 @@ describe("Wysiwyg image caption", () => {
|
|
|
111
134
|
toggleCaption(editor);
|
|
112
135
|
|
|
113
136
|
expect(editor.el.querySelector("[width]")).toBeNull();
|
|
114
|
-
expect(editor.el.querySelector("img").hasAttribute("style")).toBe(false);
|
|
115
137
|
});
|
|
116
138
|
|
|
117
139
|
it("should turn a pixel width from before percentages into the caption's share", async () => {
|
|
@@ -125,7 +147,7 @@ describe("Wysiwyg image caption", () => {
|
|
|
125
147
|
toggleCaption(editor);
|
|
126
148
|
|
|
127
149
|
expect(caption(editor)?.style.width).toBe("50%");
|
|
128
|
-
expect(img.style.width).toBe("");
|
|
150
|
+
expect(img.style.width).toBe("50%");
|
|
129
151
|
});
|
|
130
152
|
|
|
131
153
|
it("should keep a resized image's size when its caption is put back", async () => {
|
|
@@ -137,37 +159,78 @@ describe("Wysiwyg image caption", () => {
|
|
|
137
159
|
toggleCaption(editor);
|
|
138
160
|
|
|
139
161
|
expect(caption(editor)?.style.width).toBe("40%");
|
|
140
|
-
expect(img.style.width).toBe("");
|
|
162
|
+
expect(img.style.width).toBe("40%");
|
|
141
163
|
expect(editor.el.querySelectorAll(".fr-img-space-wrap")).toHaveLength(1);
|
|
142
164
|
});
|
|
143
165
|
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
'<p><img id="first" src="http://x/a.png" alt="" class="fr-dib"></p><p><img id="second" src="http://x/b.png" alt="" class="fr-dib"></p>',
|
|
147
|
-
);
|
|
148
|
-
const first = editor.el.querySelector("#first");
|
|
149
|
-
const second = editor.el.querySelector("#second");
|
|
166
|
+
describe("with the size popup", () => {
|
|
167
|
+
const widthInput = (editor: any) => editor.popups.get("image.size").find('input[name="width"]');
|
|
150
168
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
169
|
+
const captionedAt40 = async () => {
|
|
170
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib" style="width: 40%;"></p>');
|
|
171
|
+
const img = editor.el.querySelector("img");
|
|
172
|
+
toggleCaption(editor);
|
|
173
|
+
editor.image.edit(editor.$(img));
|
|
174
|
+
editor.image.showSizePopup();
|
|
175
|
+
return { editor, img };
|
|
176
|
+
};
|
|
155
177
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
178
|
+
it("should show a captioned image's width", async () => {
|
|
179
|
+
const { editor } = await captionedAt40();
|
|
180
|
+
|
|
181
|
+
expect(widthInput(editor).val()).toBe("40%");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("should size a captioned image and its caption alike", async () => {
|
|
185
|
+
const { editor, img } = await captionedAt40();
|
|
186
|
+
|
|
187
|
+
widthInput(editor).val("30%");
|
|
188
|
+
editor.commands.exec("imageSetSize");
|
|
189
|
+
|
|
190
|
+
expect(caption(editor)?.style.width).toBe("30%");
|
|
191
|
+
expect(img.style.width).toBe("30%");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should keep a captioned image's height on the image", async () => {
|
|
195
|
+
const { editor, img } = await captionedAt40();
|
|
196
|
+
|
|
197
|
+
editor.popups.get("image.size").find('input[name="height"]').val("200px");
|
|
198
|
+
editor.commands.exec("imageSetSize");
|
|
199
|
+
|
|
200
|
+
expect(img.style.height).toBe("200px");
|
|
201
|
+
expect(caption(editor)?.style.height).toBe("");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should keep the size set in the popup when it is opened again and when the caption goes", async () => {
|
|
205
|
+
const { editor, img } = await captionedAt40();
|
|
206
|
+
const heightInput = () => editor.popups.get("image.size").find('input[name="height"]');
|
|
207
|
+
|
|
208
|
+
widthInput(editor).val("30%");
|
|
209
|
+
heightInput().val("200px");
|
|
210
|
+
editor.commands.exec("imageSetSize");
|
|
211
|
+
editor.image.edit(editor.$(img));
|
|
212
|
+
editor.image.showSizePopup();
|
|
213
|
+
|
|
214
|
+
expect(widthInput(editor).val()).toBe("30%");
|
|
215
|
+
expect(heightInput().val()).toBe("200px");
|
|
216
|
+
|
|
217
|
+
toggleCaption(editor, img);
|
|
218
|
+
|
|
219
|
+
expect(caption(editor)).toBeNull();
|
|
220
|
+
expect(img.style.width).toBe("30%");
|
|
221
|
+
expect(img.style.height).toBe("200px");
|
|
222
|
+
});
|
|
160
223
|
});
|
|
161
224
|
|
|
162
225
|
describe("when resizing a captioned image", () => {
|
|
163
|
-
// jsdom has no layout: the column is 600px, and the caption, with
|
|
164
|
-
//
|
|
226
|
+
// jsdom has no layout: the column is 600px, and the caption, with
|
|
227
|
+
// everything inside it, takes the share its style asks for
|
|
165
228
|
const COLUMN = 600;
|
|
166
229
|
|
|
167
230
|
beforeEach(() => {
|
|
168
231
|
vi.spyOn(HTMLElement.prototype, "offsetWidth", "get").mockImplementation(function (this: HTMLElement) {
|
|
169
232
|
const box = this.closest(".fr-img-caption") as HTMLElement | null;
|
|
170
|
-
return box ? (Number.parseFloat(box.style.width) / 100) * COLUMN : COLUMN;
|
|
233
|
+
return box?.style.width ? (Number.parseFloat(box.style.width) / 100) * COLUMN : COLUMN;
|
|
171
234
|
});
|
|
172
235
|
});
|
|
173
236
|
|
|
@@ -179,6 +242,16 @@ describe("Wysiwyg image caption", () => {
|
|
|
179
242
|
return { editor, img };
|
|
180
243
|
};
|
|
181
244
|
|
|
245
|
+
// As captions were saved before the paragraph inside them was dropped
|
|
246
|
+
const captionedWithParagraph = async () => {
|
|
247
|
+
const editor = await mountEditor(
|
|
248
|
+
'<div class="fr-img-space-wrap"><span contenteditable="false" class="fr-img-caption fr-dib" draggable="false" style="width: 50%;"><span class="fr-img-wrap"><p><img src="http://x/a.png" alt="" class="fr-dib"><span class="fr-inner" contenteditable="true">Image Caption</span></p></span></span></div>',
|
|
249
|
+
);
|
|
250
|
+
const img = editor.el.querySelector("img");
|
|
251
|
+
editor.image.edit(editor.$(img));
|
|
252
|
+
return { editor, img };
|
|
253
|
+
};
|
|
254
|
+
|
|
182
255
|
// Froala reads pageX, which jsdom does not derive from clientX
|
|
183
256
|
const mouse = (type: string, pageX = 0) =>
|
|
184
257
|
Object.defineProperty(new MouseEvent(type, { bubbles: true }), "pageX", { value: pageX });
|
|
@@ -192,14 +265,41 @@ describe("Wysiwyg image caption", () => {
|
|
|
192
265
|
});
|
|
193
266
|
};
|
|
194
267
|
|
|
195
|
-
it(
|
|
196
|
-
|
|
268
|
+
it.each([
|
|
269
|
+
["a new caption", captioned],
|
|
270
|
+
["a caption saved with a paragraph in it", captionedWithParagraph],
|
|
271
|
+
])("should follow the pointer without bouncing, with %s", async (_, setup) => {
|
|
272
|
+
await setup();
|
|
197
273
|
|
|
198
274
|
expect(dragHandle([160, 160, 160, 130])).toEqual(["60%", "60%", "60%", "55%"]);
|
|
199
275
|
});
|
|
200
276
|
|
|
201
|
-
it("should
|
|
202
|
-
const { img } = await captioned();
|
|
277
|
+
it("should give the image the width the drag leaves on its caption", async () => {
|
|
278
|
+
const { editor, img } = await captioned();
|
|
279
|
+
|
|
280
|
+
dragHandle([160]);
|
|
281
|
+
document.body.dispatchEvent(mouse("mouseup"));
|
|
282
|
+
|
|
283
|
+
expect(img.style.width).toBe("60%");
|
|
284
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("should size a never resized image and its caption alike", async () => {
|
|
288
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
289
|
+
const img = editor.el.querySelector("img");
|
|
290
|
+
toggleCaption(editor);
|
|
291
|
+
editor.image.edit(editor.$(img));
|
|
292
|
+
|
|
293
|
+
dragHandle([40]);
|
|
294
|
+
document.body.dispatchEvent(mouse("mouseup"));
|
|
295
|
+
|
|
296
|
+
expect(caption(editor)?.style.width).toBe("90%");
|
|
297
|
+
expect(img.style.width).toBe("90%");
|
|
298
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("should put a caption saved with a paragraph in it back in its paragraph when the drag ends", async () => {
|
|
302
|
+
const { editor, img } = await captionedWithParagraph();
|
|
203
303
|
|
|
204
304
|
dragHandle([160]);
|
|
205
305
|
document.body.dispatchEvent(mouse("mouseup"));
|
|
@@ -207,6 +307,7 @@ describe("Wysiwyg image caption", () => {
|
|
|
207
307
|
const paragraph = img.closest(".fr-img-wrap > p");
|
|
208
308
|
expect(paragraph).not.toBeNull();
|
|
209
309
|
expect(paragraph.querySelector(".fr-inner")?.textContent).toBe("Image Caption");
|
|
310
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
210
311
|
});
|
|
211
312
|
});
|
|
212
313
|
|
|
@@ -222,6 +323,253 @@ describe("Wysiwyg image caption", () => {
|
|
|
222
323
|
});
|
|
223
324
|
});
|
|
224
325
|
|
|
326
|
+
describe.each([
|
|
327
|
+
["on", { imageResize: true }],
|
|
328
|
+
["off", undefined],
|
|
329
|
+
])("with image resizing %s", (_, richTextConfig) => {
|
|
330
|
+
beforeEach(() => {
|
|
331
|
+
if (richTextConfig) schemasConfig.richTextConfig = richTextConfig;
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("should put the caption's text right after the image, with no paragraph around them", async () => {
|
|
335
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
336
|
+
|
|
337
|
+
toggleCaption(editor);
|
|
338
|
+
|
|
339
|
+
expect(caption(editor)?.querySelector("p")).toBeNull();
|
|
340
|
+
expect(caption(editor)?.querySelector(".fr-img-wrap > img + .fr-inner")?.textContent).toBe("Image Caption");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("should leave the caption's placeholder selected, to type over it", async () => {
|
|
344
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
345
|
+
|
|
346
|
+
toggleCaption(editor);
|
|
347
|
+
|
|
348
|
+
expect(getSelection()?.toString()).toBe("Image Caption");
|
|
349
|
+
expect(getSelection()?.anchorNode?.parentElement?.closest(".fr-inner")).not.toBeNull();
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("should leave the text sharing the image's paragraph out of the caption", async () => {
|
|
353
|
+
const editor = await mountEditor('<p>Above<img src="http://x/a.png" alt="" class="fr-dib">Below</p>');
|
|
354
|
+
|
|
355
|
+
toggleCaption(editor);
|
|
356
|
+
|
|
357
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
358
|
+
expect(caption(editor)?.textContent).toBe("Image Caption");
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("should keep the text around the image when its caption is removed", async () => {
|
|
362
|
+
const editor = await mountEditor('<p>Above<img src="http://x/a.png" alt="" class="fr-dib">Below</p>');
|
|
363
|
+
|
|
364
|
+
toggleCaption(editor);
|
|
365
|
+
toggleCaption(editor);
|
|
366
|
+
|
|
367
|
+
expect(caption(editor)).toBeNull();
|
|
368
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("should give back the text an earlier caption took in, when that caption is removed", async () => {
|
|
372
|
+
const editor = await mountEditor(
|
|
373
|
+
'<div class="fr-img-space-wrap"><span contenteditable="false" class="fr-img-caption fr-dib" draggable="false"><span class="fr-img-wrap"><p>Above<img src="http://x/a.png" alt="" class="fr-dib"><span class="fr-inner" contenteditable="true">Caption</span>Below</p></span></span></div>',
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
toggleCaption(editor);
|
|
377
|
+
|
|
378
|
+
expect(caption(editor)).toBeNull();
|
|
379
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("should not put a linked image's caption inside a paragraph", async () => {
|
|
383
|
+
const editor = await mountEditor(
|
|
384
|
+
'<p><a href="http://x"><img src="http://x/a.png" alt="" class="fr-dib"></a>Below</p>',
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
toggleCaption(editor);
|
|
388
|
+
|
|
389
|
+
expect(outline(editor)).toEqual(["fr-img-space-wrap", "p: Below"]);
|
|
390
|
+
expect(caption(editor)?.querySelector("a > img")).not.toBeNull();
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// As when the image goes in with the caret inside a link
|
|
394
|
+
it("should leave out of the caption, still linked, the text of a link the image is in", async () => {
|
|
395
|
+
const editor = await mountEditor(
|
|
396
|
+
'<p>Above <a href="http://x">link<img src="http://x/a.png" alt="" class="fr-dib">more</a> below</p>',
|
|
397
|
+
);
|
|
398
|
+
const links = () => [...editor.el.querySelectorAll(":scope > p > a")].map((a: HTMLElement) => a.textContent);
|
|
399
|
+
|
|
400
|
+
toggleCaption(editor);
|
|
401
|
+
|
|
402
|
+
expect(outline(editor)).toEqual(["p: Above link", "fr-img-space-wrap", "p: more below"]);
|
|
403
|
+
expect(links()).toEqual(["link", "more"]);
|
|
404
|
+
expect(caption(editor)?.querySelector("a > img + .fr-inner")?.textContent).toBe("Image Caption");
|
|
405
|
+
|
|
406
|
+
toggleCaption(editor);
|
|
407
|
+
|
|
408
|
+
expect(outline(editor)).toEqual(["p: Above link", "fr-img-space-wrap", "p: more below"]);
|
|
409
|
+
expect(links()).toEqual(["link", "more"]);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// As when the image goes in with the caret inside bold text
|
|
413
|
+
it("should leave out of the caption, still bold, the text around an image in bold", async () => {
|
|
414
|
+
const editor = await mountEditor(
|
|
415
|
+
'<p><strong>Above<img src="http://x/a.png" alt="" class="fr-dib">Below</strong></p>',
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
toggleCaption(editor);
|
|
419
|
+
|
|
420
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
421
|
+
const bold = [...editor.el.querySelectorAll(":scope > p > strong")].map((b: HTMLElement) => b.textContent);
|
|
422
|
+
expect(bold).toEqual(["Above", "Below"]);
|
|
423
|
+
expect(caption(editor)?.querySelector("strong")).toBeNull();
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("should leave the other captions alone when an image is captioned again", async () => {
|
|
427
|
+
const editor = await mountEditor(
|
|
428
|
+
'<p><img id="first" src="http://x/a.png" alt="" class="fr-dib"></p><p><img id="second" src="http://x/b.png" alt="" class="fr-dib"></p>',
|
|
429
|
+
);
|
|
430
|
+
const first = editor.el.querySelector("#first");
|
|
431
|
+
const second = editor.el.querySelector("#second");
|
|
432
|
+
|
|
433
|
+
toggleCaption(editor, first);
|
|
434
|
+
toggleCaption(editor, second);
|
|
435
|
+
toggleCaption(editor, second);
|
|
436
|
+
toggleCaption(editor, second);
|
|
437
|
+
|
|
438
|
+
expect(first.closest(".fr-img-space-wrap")).not.toBeNull();
|
|
439
|
+
expect(first.closest(".fr-img-caption")).not.toBeNull();
|
|
440
|
+
expect(second.closest(".fr-img-caption")).not.toBeNull();
|
|
441
|
+
expect(editor.el.querySelectorAll(".fr-img-space-wrap")).toHaveLength(2);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe("with the keyboard around a captioned image", () => {
|
|
446
|
+
const captioned = async (
|
|
447
|
+
html = '<p>Above</p><p><img src="http://x/a.png" alt="" class="fr-dib"></p><p>Below</p>',
|
|
448
|
+
) => {
|
|
449
|
+
const editor = await mountEditor(html);
|
|
450
|
+
const img = editor.el.querySelector("img");
|
|
451
|
+
toggleCaption(editor, img);
|
|
452
|
+
return { editor, img };
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const paragraph = (editor: any, text: string) =>
|
|
456
|
+
[...editor.el.querySelectorAll(":scope > p")].find((p: HTMLElement) => p.textContent === text);
|
|
457
|
+
|
|
458
|
+
const caretBlock = () => {
|
|
459
|
+
const node = getSelection()?.anchorNode;
|
|
460
|
+
return (node instanceof Element ? node : node?.parentElement)?.closest("p");
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
it("should select the image instead of merging the block after it into its wrapper", async () => {
|
|
464
|
+
const { editor, img } = await captioned();
|
|
465
|
+
caretAt(paragraph(editor, "Below").firstChild, 0);
|
|
466
|
+
|
|
467
|
+
press(editor, "Backspace");
|
|
468
|
+
|
|
469
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
470
|
+
expect(editor.image.get()?.get(0)).toBe(img);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it("should select the image instead of merging its caption into the block before it", async () => {
|
|
474
|
+
const { editor, img } = await captioned();
|
|
475
|
+
caretAt(paragraph(editor, "Above").firstChild, "Above".length);
|
|
476
|
+
|
|
477
|
+
press(editor, "Delete");
|
|
478
|
+
|
|
479
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
480
|
+
expect(editor.image.get()?.get(0)).toBe(img);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it.each([
|
|
484
|
+
[
|
|
485
|
+
"Backspace",
|
|
486
|
+
"after",
|
|
487
|
+
'<p><img src="http://x/a.png" alt="" class="fr-dib"></p><p><br></p><p>Below</p>',
|
|
488
|
+
["fr-img-space-wrap", "p: Below"],
|
|
489
|
+
],
|
|
490
|
+
[
|
|
491
|
+
"Delete",
|
|
492
|
+
"before",
|
|
493
|
+
'<p>Above</p><p><br></p><p><img src="http://x/a.png" alt="" class="fr-dib"></p>',
|
|
494
|
+
["p: Above", "fr-img-space-wrap"],
|
|
495
|
+
],
|
|
496
|
+
])("should drop an empty block on %s %s the image, and select it", async (key, _, html, expected) => {
|
|
497
|
+
const { editor, img } = await captioned(html);
|
|
498
|
+
caretAt(paragraph(editor, ""), 0);
|
|
499
|
+
|
|
500
|
+
press(editor, key);
|
|
501
|
+
|
|
502
|
+
expect(outline(editor)).toEqual(expected);
|
|
503
|
+
expect(editor.image.get()?.get(0)).toBe(img);
|
|
504
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it("should leave Backspace alone away from the start of the block", async () => {
|
|
508
|
+
const { editor } = await captioned();
|
|
509
|
+
caretAt(paragraph(editor, "Below").firstChild, 2);
|
|
510
|
+
|
|
511
|
+
press(editor, "Backspace");
|
|
512
|
+
|
|
513
|
+
expect(editor.image.get()).toBeFalsy();
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it.each([
|
|
517
|
+
["ArrowRight", "Below"],
|
|
518
|
+
["ArrowDown", "Below"],
|
|
519
|
+
["Escape", "Below"],
|
|
520
|
+
["ArrowLeft", "Above"],
|
|
521
|
+
["ArrowUp", "Above"],
|
|
522
|
+
])("should take the caret out of the image's wrapper on %s", async (key, text) => {
|
|
523
|
+
const { editor, img } = await captioned();
|
|
524
|
+
editor.image.edit(editor.$(img));
|
|
525
|
+
|
|
526
|
+
press(editor, key);
|
|
527
|
+
|
|
528
|
+
expect(editor.image.get()).toBeFalsy();
|
|
529
|
+
expect(caretBlock()?.textContent).toBe(text);
|
|
530
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it("should start a paragraph to take the caret to when there is none", async () => {
|
|
534
|
+
const { editor, img } = await captioned('<p>Above</p><p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
535
|
+
editor.image.edit(editor.$(img));
|
|
536
|
+
|
|
537
|
+
press(editor, "ArrowRight");
|
|
538
|
+
|
|
539
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: "]);
|
|
540
|
+
expect(caretBlock()).toBe(editor.el.lastElementChild);
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
it("should hand AX the paragraph it starts between two images", async () => {
|
|
544
|
+
const { editor, img } = await captioned(
|
|
545
|
+
'<p><img src="http://x/a.png" alt="" class="fr-dib"></p><p><img id="second" src="http://x/b.png" alt="" class="fr-dib"></p>',
|
|
546
|
+
);
|
|
547
|
+
toggleCaption(editor, editor.el.querySelector("#second"));
|
|
548
|
+
editor.image.edit(editor.$(img));
|
|
549
|
+
|
|
550
|
+
press(editor, "ArrowRight");
|
|
551
|
+
|
|
552
|
+
expect(outline(editor)).toEqual(["fr-img-space-wrap", "p: ", "fr-img-space-wrap"]);
|
|
553
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it.each([
|
|
557
|
+
["with Backspace", (editor: any) => press(editor, "Backspace")],
|
|
558
|
+
["with Delete", (editor: any) => press(editor, "Delete")],
|
|
559
|
+
["from its popup", (editor: any) => editor.commands.exec("imageRemove")],
|
|
560
|
+
])("should leave a paragraph where the image was when it is removed %s", async (_, remove) => {
|
|
561
|
+
const { editor, img } = await captioned();
|
|
562
|
+
editor.image.edit(editor.$(img));
|
|
563
|
+
|
|
564
|
+
remove(editor);
|
|
565
|
+
|
|
566
|
+
expect(editor.el.querySelector("img")).toBeNull();
|
|
567
|
+
expect(outline(editor)).toEqual(["p: Above", "p: ", "p: Below"]);
|
|
568
|
+
expect(caretBlock()).toBe(editor.el.children[1]);
|
|
569
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
|
|
225
573
|
it("should leave Froala's pixel caption alone when resizing is off", async () => {
|
|
226
574
|
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
227
575
|
|
|
@@ -19,6 +19,7 @@ vi.mock("react-froala-wysiwyg", () => ({
|
|
|
19
19
|
$el: { get: vi.fn(() => editorElRef.current!) },
|
|
20
20
|
el: editorElRef.current,
|
|
21
21
|
edit: { on: vi.fn(), off: vi.fn() },
|
|
22
|
+
events: { on: vi.fn() },
|
|
22
23
|
commands: { exec: vi.fn() },
|
|
23
24
|
opts: { zIndex: 1 },
|
|
24
25
|
$tb: { css: vi.fn() },
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { pages } from "@ax/api";
|
|
2
|
+
import { pageEditorActions } from "@ax/containers/PageEditor";
|
|
3
|
+
import type { PageAccessGrantsSummary } from "@ax/types";
|
|
4
|
+
|
|
5
|
+
const SITE = 7;
|
|
6
|
+
const PAGE = 100;
|
|
7
|
+
const DRAFT = 213;
|
|
8
|
+
|
|
9
|
+
const GRANTS: PageAccessGrantsSummary = { users: [42], roles: [] };
|
|
10
|
+
const GRANTS_IN_EDITOR: PageAccessGrantsSummary = { users: [7], roles: [] };
|
|
11
|
+
|
|
12
|
+
const editorContent = (id: number, draftFromPage: number | null) => ({
|
|
13
|
+
id,
|
|
14
|
+
draftFromPage,
|
|
15
|
+
accessGrants: GRANTS_IN_EDITOR,
|
|
16
|
+
header: null,
|
|
17
|
+
footer: null,
|
|
18
|
+
templateConfig: {},
|
|
19
|
+
template: { templateType: "BasicTemplate" },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("[UC-AX-restrict-page-access] Los accesos son de la página, no de la versión en edición", () => {
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const applyGrants = async (editing: { id: number; draftFromPage: number | null }) => {
|
|
28
|
+
const setPageAccessGrants = vi
|
|
29
|
+
.spyOn(pages, "setPageAccessGrants")
|
|
30
|
+
.mockResolvedValue({ status: 200, data: {} } as any);
|
|
31
|
+
const dispatch = vi.fn();
|
|
32
|
+
const getState = (() => ({
|
|
33
|
+
pageEditor: { editorContent: editorContent(editing.id, editing.draftFromPage) },
|
|
34
|
+
})) as any;
|
|
35
|
+
|
|
36
|
+
await pageEditorActions.updatePageAccessGrants({
|
|
37
|
+
siteID: SITE,
|
|
38
|
+
pageID: editing.id,
|
|
39
|
+
accessGrants: GRANTS,
|
|
40
|
+
})(dispatch, getState);
|
|
41
|
+
|
|
42
|
+
return setPageAccessGrants;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
it("AC8 · aplicar accesos editando un borrador los persiste sobre su página", async () => {
|
|
46
|
+
const fromDraft = await applyGrants({ id: DRAFT, draftFromPage: PAGE });
|
|
47
|
+
|
|
48
|
+
expect(fromDraft).toHaveBeenCalledWith({ siteID: SITE, pageID: PAGE, accessGrants: GRANTS });
|
|
49
|
+
|
|
50
|
+
// Y una página sin borrador de por medio se sigue direccionando a sí misma.
|
|
51
|
+
const fromPage = await applyGrants({ id: PAGE, draftFromPage: null });
|
|
52
|
+
|
|
53
|
+
expect(fromPage).toHaveBeenCalledWith({ siteID: SITE, pageID: PAGE, accessGrants: GRANTS });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("AC9 · el guardado normal de la versión en edición no reescribe los accesos", async () => {
|
|
57
|
+
const updatePage = vi
|
|
58
|
+
.spyOn(pages, "updatePage")
|
|
59
|
+
.mockResolvedValue({ status: 400, data: { message: "cortado a propósito" } } as any);
|
|
60
|
+
const dispatch = vi.fn();
|
|
61
|
+
const getState = (() => ({
|
|
62
|
+
pageEditor: {
|
|
63
|
+
selectedEditorID: 0,
|
|
64
|
+
isNewTranslation: false,
|
|
65
|
+
editorContent: editorContent(DRAFT, PAGE),
|
|
66
|
+
lastTimeout: null,
|
|
67
|
+
},
|
|
68
|
+
sites: { currentSiteInfo: { id: SITE } },
|
|
69
|
+
app: { lang: 1 },
|
|
70
|
+
})) as any;
|
|
71
|
+
|
|
72
|
+
await pageEditorActions.savePage({ setToast: vi.fn() })(dispatch, getState);
|
|
73
|
+
|
|
74
|
+
expect(updatePage).toHaveBeenCalled();
|
|
75
|
+
|
|
76
|
+
const [, body] = updatePage.mock.calls[0];
|
|
77
|
+
|
|
78
|
+
expect(body).not.toHaveProperty("accessGrants");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("una página nueva sí nace con los accesos que se le hayan puesto", async () => {
|
|
82
|
+
const createPage = vi
|
|
83
|
+
.spyOn(pages, "createPage")
|
|
84
|
+
.mockResolvedValue({ status: 400, data: { message: "cortado a propósito" } } as any);
|
|
85
|
+
const dispatch = vi.fn();
|
|
86
|
+
const nuevaPagina = { ...editorContent(0, null), id: undefined };
|
|
87
|
+
const getState = (() => ({
|
|
88
|
+
pageEditor: {
|
|
89
|
+
selectedEditorID: 0,
|
|
90
|
+
isNewTranslation: false,
|
|
91
|
+
editorContent: nuevaPagina,
|
|
92
|
+
lastTimeout: null,
|
|
93
|
+
},
|
|
94
|
+
sites: { currentSiteInfo: { id: SITE } },
|
|
95
|
+
app: { lang: 1 },
|
|
96
|
+
})) as any;
|
|
97
|
+
|
|
98
|
+
await pageEditorActions.savePage({ setToast: vi.fn() })(dispatch, getState);
|
|
99
|
+
|
|
100
|
+
const [body] = createPage.mock.calls[0];
|
|
101
|
+
|
|
102
|
+
expect(body).toHaveProperty("accessGrants", GRANTS_IN_EDITOR);
|
|
103
|
+
});
|
|
104
|
+
});
|