@griddo/ax 11.15.7 → 11.15.8
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 +2 -2
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.atoms.test.tsx +409 -0
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.helpers.test.tsx +418 -0
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.test.tsx +776 -29
- package/src/__tests__/components/FieldsBehavior/FieldsBehavior.test.tsx +368 -11
- package/src/__tests__/modules/Users/UserList/UserList.test.tsx +6 -6
- package/src/components/Fields/IntegrationsField/IntegrationItem/atoms.tsx +14 -5
- package/src/components/Fields/IntegrationsField/IntegrationItem/index.tsx +1 -8
- package/src/components/Fields/UrlField/index.tsx +5 -4
- package/src/components/Fields/Wysiwyg/atoms.tsx +140 -0
- package/src/components/Fields/Wysiwyg/config.tsx +190 -9
- package/src/components/Fields/Wysiwyg/helpers.tsx +54 -1
- package/src/components/Fields/Wysiwyg/index.tsx +210 -61
- package/src/components/Fields/Wysiwyg/style.tsx +32 -1
- package/src/components/Fields/Wysiwyg/vendors.tsx +0 -1
- package/src/components/FieldsBehavior/index.tsx +66 -31
- package/src/components/Icon/components/Sync.js +16 -0
- package/src/components/Icon/svgs/Sync.svg +3 -0
- package/src/components/RestoreModal/index.tsx +1 -3
- package/src/components/ScheduleModal/index.tsx +3 -3
- package/src/components/TableList/index.tsx +5 -3
- package/src/containers/FileDrive/actions.tsx +5 -5
- package/src/containers/Forms/actions.tsx +40 -38
- package/src/containers/Gallery/actions.tsx +27 -27
- package/src/containers/Integrations/actions.tsx +2 -2
- package/src/containers/Navigation/Defaults/actions.tsx +1 -1
- package/src/containers/PageEditor/actions.tsx +3 -5
- package/src/containers/Redirects/actions.tsx +2 -2
- package/src/containers/Sites/actions.tsx +15 -8
- package/src/containers/StructuredData/actions.tsx +5 -5
- package/src/containers/Users/actions.tsx +2 -2
- package/src/modules/Categories/CategoriesList/CategoryItem/index.tsx +36 -43
- package/src/modules/Categories/CategoriesList/CategoryPanel/index.tsx +15 -11
- package/src/modules/Categories/CategoriesList/atoms.tsx +42 -12
- package/src/modules/Categories/CategoriesList/index.tsx +8 -30
- package/src/modules/Content/PageItem/index.tsx +6 -5
- package/src/modules/Content/atoms.tsx +7 -3
- package/src/modules/Content/index.tsx +8 -16
- package/src/modules/FileDrive/FileModal/DetailPanel/index.tsx +14 -14
- package/src/modules/FileDrive/FolderItem/index.tsx +46 -54
- package/src/modules/FileDrive/GridItem/index.tsx +32 -37
- package/src/modules/FileDrive/ListItem/index.tsx +31 -37
- package/src/modules/FileDrive/atoms.tsx +59 -12
- package/src/modules/FileDrive/index.tsx +88 -98
- package/src/modules/Forms/FormCategoriesList/CategoryItem/index.tsx +42 -34
- package/src/modules/Forms/FormCategoriesList/atoms.tsx +17 -6
- package/src/modules/Forms/FormCategoriesList/index.tsx +30 -34
- package/src/modules/Forms/FormEditor/index.tsx +14 -6
- package/src/modules/Forms/FormList/FormItem/index.tsx +5 -1
- package/src/modules/Forms/FormList/index.tsx +15 -9
- package/src/modules/Forms/atoms.tsx +7 -4
- package/src/modules/GlobalEditor/atoms.tsx +77 -0
- package/src/modules/GlobalEditor/index.tsx +24 -7
- package/src/modules/MediaGallery/FolderItem/index.tsx +36 -52
- package/src/modules/MediaGallery/GridItem/index.tsx +27 -38
- package/src/modules/MediaGallery/ImageModal/DetailPanel/index.tsx +13 -13
- package/src/modules/MediaGallery/ImageModal/index.tsx +2 -16
- package/src/modules/MediaGallery/ListItem/index.tsx +25 -37
- package/src/modules/MediaGallery/atoms.tsx +84 -15
- package/src/modules/MediaGallery/index.tsx +62 -122
- package/src/modules/Navigation/Defaults/Item/atoms.tsx +2 -4
- package/src/modules/Navigation/Defaults/Item/index.tsx +80 -94
- package/src/modules/Navigation/Defaults/atoms.tsx +179 -7
- package/src/modules/Navigation/Defaults/index.tsx +51 -18
- package/src/modules/Navigation/Defaults/style.tsx +10 -7
- package/src/modules/Navigation/Menus/List/Table/Item/atoms.tsx +33 -19
- package/src/modules/Navigation/Menus/List/Table/Item/index.tsx +18 -19
- package/src/modules/Navigation/Menus/List/Table/index.tsx +15 -13
- package/src/modules/Navigation/Menus/List/index.tsx +1 -1
- package/src/modules/PageEditor/atoms.tsx +14 -11
- package/src/modules/PageEditor/index.tsx +11 -16
- package/src/modules/Redirects/RedirectItem/index.tsx +37 -39
- package/src/modules/Redirects/atoms.tsx +58 -12
- package/src/modules/Redirects/index.tsx +30 -58
- package/src/modules/Settings/Integrations/IntegrationItem/CopyModal/index.tsx +1 -1
- package/src/modules/Settings/Integrations/IntegrationItem/index.tsx +57 -69
- package/src/modules/Settings/Integrations/atoms.tsx +72 -8
- package/src/modules/Settings/Integrations/index.tsx +34 -48
- package/src/modules/StructuredData/Form/index.tsx +25 -8
- package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/atoms.tsx +26 -75
- package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +15 -33
- package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +63 -41
- package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/style.tsx +13 -8
- package/src/modules/StructuredData/StructuredDataList/index.tsx +11 -16
- package/src/modules/StructuredData/{StructuredDataList/atoms.tsx → atoms.tsx} +25 -28
- package/src/modules/Users/UserList/UserItem/index.tsx +18 -35
- package/src/modules/Users/UserList/atoms.tsx +61 -0
- package/src/modules/Users/UserList/index.tsx +12 -32
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "11.15.
|
|
4
|
+
"version": "11.15.8",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -219,5 +219,5 @@
|
|
|
219
219
|
"publishConfig": {
|
|
220
220
|
"access": "public"
|
|
221
221
|
},
|
|
222
|
-
"gitHead": "
|
|
222
|
+
"gitHead": "2d50b3828919cceb67f86fe7283056d4207a0eaf"
|
|
223
223
|
}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
4
|
+
import { ThemeProvider } from "styled-components";
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
7
|
+
import { LinkPopover } from "@ax/components/Fields/Wysiwyg/atoms";
|
|
8
|
+
|
|
9
|
+
// Mock createPortal to render content directly in the test DOM
|
|
10
|
+
jest.mock("react-dom", () => {
|
|
11
|
+
const actual = jest.requireActual("react-dom");
|
|
12
|
+
return {
|
|
13
|
+
...actual,
|
|
14
|
+
createPortal: (element: React.ReactNode) => element,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Mock FieldsBehavior and Button components
|
|
19
|
+
jest.mock("@ax/components", () => ({
|
|
20
|
+
Button: ({ onClick, disabled, children }: any) => (
|
|
21
|
+
<button type="button" onClick={onClick} disabled={disabled} data-testid="insert-button">
|
|
22
|
+
{children}
|
|
23
|
+
</button>
|
|
24
|
+
),
|
|
25
|
+
FieldsBehavior: ({ name, value, onChange, placeholder, fieldType }: any) => {
|
|
26
|
+
if (fieldType === "CheckGroup") {
|
|
27
|
+
return (
|
|
28
|
+
<div data-testid={`field-${name}`}>
|
|
29
|
+
<label>
|
|
30
|
+
<input
|
|
31
|
+
type="checkbox"
|
|
32
|
+
data-testid="checkbox-newTab"
|
|
33
|
+
onChange={(e) => {
|
|
34
|
+
const newValue = e.target.checked ? [...value, "newTab"] : value.filter((v: string) => v !== "newTab");
|
|
35
|
+
onChange(newValue);
|
|
36
|
+
}}
|
|
37
|
+
checked={value.includes("newTab")}
|
|
38
|
+
/>
|
|
39
|
+
Open in new tab
|
|
40
|
+
</label>
|
|
41
|
+
<label>
|
|
42
|
+
<input
|
|
43
|
+
type="checkbox"
|
|
44
|
+
data-testid="checkbox-noFollow"
|
|
45
|
+
onChange={(e) => {
|
|
46
|
+
const newValue = e.target.checked
|
|
47
|
+
? [...value, "noFollow"]
|
|
48
|
+
: value.filter((v: string) => v !== "noFollow");
|
|
49
|
+
onChange(newValue);
|
|
50
|
+
}}
|
|
51
|
+
checked={value.includes("noFollow")}
|
|
52
|
+
/>
|
|
53
|
+
Add nofollow
|
|
54
|
+
</label>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (fieldType === "UrlField") {
|
|
60
|
+
return (
|
|
61
|
+
<input
|
|
62
|
+
data-testid={`field-${name}`}
|
|
63
|
+
type="text"
|
|
64
|
+
value={value?.href || value?.linkToURL || ""}
|
|
65
|
+
onChange={(e) => onChange({ ...value, href: e.target.value })}
|
|
66
|
+
placeholder={placeholder}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<input
|
|
73
|
+
data-testid={`field-${name}`}
|
|
74
|
+
type="text"
|
|
75
|
+
value={value}
|
|
76
|
+
onChange={(e) => onChange(e.target.value)}
|
|
77
|
+
placeholder={placeholder}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
const renderWithTheme = (ui: React.ReactElement) => {
|
|
84
|
+
return render(<ThemeProvider theme={parseTheme(globalTheme)}>{ui}</ThemeProvider>);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
describe("LinkPopover", () => {
|
|
88
|
+
const defaultProps = {
|
|
89
|
+
x: 100,
|
|
90
|
+
y: 100,
|
|
91
|
+
selectedText: "Click here",
|
|
92
|
+
onInsert: jest.fn(),
|
|
93
|
+
onClose: jest.fn(),
|
|
94
|
+
linkData: null,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
beforeEach(() => {
|
|
98
|
+
jest.clearAllMocks();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("Rendering", () => {
|
|
102
|
+
it("should render text field for link text when not image link", () => {
|
|
103
|
+
renderWithTheme(<LinkPopover {...defaultProps} />);
|
|
104
|
+
|
|
105
|
+
const textField = screen.getByTestId("field-text");
|
|
106
|
+
expect(textField).toBeTruthy();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should render URL field", () => {
|
|
110
|
+
renderWithTheme(<LinkPopover {...defaultProps} />);
|
|
111
|
+
|
|
112
|
+
const urlField = screen.getByTestId("field-url");
|
|
113
|
+
expect(urlField).toBeTruthy();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should render INSERT button", () => {
|
|
117
|
+
renderWithTheme(<LinkPopover {...defaultProps} />);
|
|
118
|
+
|
|
119
|
+
const button = screen.getByTestId("insert-button");
|
|
120
|
+
expect(button).toBeTruthy();
|
|
121
|
+
expect(button).toHaveTextContent("INSERT");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should not render text field when isImageLink is true", () => {
|
|
125
|
+
const props = {
|
|
126
|
+
...defaultProps,
|
|
127
|
+
linkData: {
|
|
128
|
+
url: "http://example.com",
|
|
129
|
+
newTab: false,
|
|
130
|
+
noFollow: false,
|
|
131
|
+
isEditing: false,
|
|
132
|
+
isImageLink: true,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
137
|
+
|
|
138
|
+
const textField = screen.queryByTestId("field-text");
|
|
139
|
+
expect(textField).not.toBeInTheDocument();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should render link options (newTab, noFollow)", () => {
|
|
143
|
+
renderWithTheme(<LinkPopover {...defaultProps} />);
|
|
144
|
+
|
|
145
|
+
const checkbox = screen.getByTestId("checkbox-newTab");
|
|
146
|
+
expect(checkbox).toBeTruthy();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("Link insertion", () => {
|
|
151
|
+
it("should disable INSERT button when URL is empty", () => {
|
|
152
|
+
renderWithTheme(<LinkPopover {...defaultProps} />);
|
|
153
|
+
|
|
154
|
+
const button = screen.getByTestId("insert-button");
|
|
155
|
+
expect(button).toBeDisabled();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("should enable INSERT button when URL is provided", async () => {
|
|
159
|
+
renderWithTheme(<LinkPopover {...defaultProps} />);
|
|
160
|
+
|
|
161
|
+
const urlField = screen.getByTestId("field-url") as HTMLInputElement;
|
|
162
|
+
fireEvent.change(urlField, { target: { value: "http://example.com" } });
|
|
163
|
+
|
|
164
|
+
await waitFor(() => {
|
|
165
|
+
const button = screen.getByTestId("insert-button");
|
|
166
|
+
expect(button).not.toBeDisabled();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("should call onInsert with URL and text when INSERT is clicked", async () => {
|
|
171
|
+
const mockOnInsert = jest.fn();
|
|
172
|
+
const props = {
|
|
173
|
+
...defaultProps,
|
|
174
|
+
onInsert: mockOnInsert,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
178
|
+
|
|
179
|
+
const urlField = screen.getByTestId("field-url") as HTMLInputElement;
|
|
180
|
+
fireEvent.change(urlField, { target: { value: "http://example.com" } });
|
|
181
|
+
|
|
182
|
+
const button = screen.getByTestId("insert-button");
|
|
183
|
+
fireEvent.click(button);
|
|
184
|
+
|
|
185
|
+
await waitFor(() => {
|
|
186
|
+
expect(mockOnInsert).toHaveBeenCalledWith(
|
|
187
|
+
"http://example.com",
|
|
188
|
+
"Click here",
|
|
189
|
+
expect.objectContaining({
|
|
190
|
+
newTab: false,
|
|
191
|
+
noFollow: false,
|
|
192
|
+
}),
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("should use URL as text if link text is empty", async () => {
|
|
198
|
+
const mockOnInsert = jest.fn();
|
|
199
|
+
const props = {
|
|
200
|
+
...defaultProps,
|
|
201
|
+
selectedText: "",
|
|
202
|
+
onInsert: mockOnInsert,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
206
|
+
|
|
207
|
+
const urlField = screen.getByTestId("field-url") as HTMLInputElement;
|
|
208
|
+
fireEvent.change(urlField, { target: { value: "http://example.com" } });
|
|
209
|
+
|
|
210
|
+
const button = screen.getByTestId("insert-button");
|
|
211
|
+
fireEvent.click(button);
|
|
212
|
+
|
|
213
|
+
await waitFor(() => {
|
|
214
|
+
const callArgs = mockOnInsert.mock.calls[0];
|
|
215
|
+
expect(callArgs[0]).toBe("http://example.com");
|
|
216
|
+
expect(callArgs[1]).toBe("http://example.com");
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe("Link options", () => {
|
|
222
|
+
it("should include newTab option when checkbox is checked", async () => {
|
|
223
|
+
const mockOnInsert = jest.fn();
|
|
224
|
+
const props = {
|
|
225
|
+
...defaultProps,
|
|
226
|
+
onInsert: mockOnInsert,
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
230
|
+
|
|
231
|
+
const urlField = screen.getByTestId("field-url") as HTMLInputElement;
|
|
232
|
+
fireEvent.change(urlField, { target: { value: "http://example.com" } });
|
|
233
|
+
|
|
234
|
+
const newTabCheckbox = screen.getByTestId("checkbox-newTab");
|
|
235
|
+
fireEvent.click(newTabCheckbox);
|
|
236
|
+
|
|
237
|
+
const button = screen.getByTestId("insert-button");
|
|
238
|
+
fireEvent.click(button);
|
|
239
|
+
|
|
240
|
+
await waitFor(() => {
|
|
241
|
+
expect(mockOnInsert).toHaveBeenCalledWith(
|
|
242
|
+
expect.any(String),
|
|
243
|
+
expect.any(String),
|
|
244
|
+
expect.objectContaining({ newTab: true }),
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("should include noFollow option when checkbox is checked", async () => {
|
|
250
|
+
const mockOnInsert = jest.fn();
|
|
251
|
+
const props = {
|
|
252
|
+
...defaultProps,
|
|
253
|
+
onInsert: mockOnInsert,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
257
|
+
|
|
258
|
+
const urlField = screen.getByTestId("field-url") as HTMLInputElement;
|
|
259
|
+
fireEvent.change(urlField, { target: { value: "http://example.com" } });
|
|
260
|
+
|
|
261
|
+
const noFollowCheckbox = screen.getByTestId("checkbox-noFollow");
|
|
262
|
+
fireEvent.click(noFollowCheckbox);
|
|
263
|
+
|
|
264
|
+
const button = screen.getByTestId("insert-button");
|
|
265
|
+
fireEvent.click(button);
|
|
266
|
+
|
|
267
|
+
await waitFor(() => {
|
|
268
|
+
expect(mockOnInsert).toHaveBeenCalledWith(
|
|
269
|
+
expect.any(String),
|
|
270
|
+
expect.any(String),
|
|
271
|
+
expect.objectContaining({ noFollow: true }),
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("should have both options checked when linkData has them", async () => {
|
|
277
|
+
const props = {
|
|
278
|
+
...defaultProps,
|
|
279
|
+
linkData: {
|
|
280
|
+
url: "http://example.com",
|
|
281
|
+
newTab: true,
|
|
282
|
+
noFollow: true,
|
|
283
|
+
isEditing: true,
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
288
|
+
|
|
289
|
+
await waitFor(() => {
|
|
290
|
+
const newTabCheckbox = screen.getByTestId("checkbox-newTab") as HTMLInputElement;
|
|
291
|
+
const noFollowCheckbox = screen.getByTestId("checkbox-noFollow") as HTMLInputElement;
|
|
292
|
+
|
|
293
|
+
expect(newTabCheckbox.checked).toBe(true);
|
|
294
|
+
expect(noFollowCheckbox.checked).toBe(true);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("Editing existing links", () => {
|
|
300
|
+
it("should load existing link data when isEditing is true", async () => {
|
|
301
|
+
const props = {
|
|
302
|
+
...defaultProps,
|
|
303
|
+
linkData: {
|
|
304
|
+
url: "http://example.com/page",
|
|
305
|
+
newTab: true,
|
|
306
|
+
noFollow: false,
|
|
307
|
+
isEditing: true,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
312
|
+
|
|
313
|
+
await waitFor(() => {
|
|
314
|
+
const textField = screen.getByTestId("field-text") as HTMLInputElement;
|
|
315
|
+
expect(textField.value).toBe("Click here");
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("should populate checkbox options from linkData when editing", async () => {
|
|
320
|
+
const props = {
|
|
321
|
+
...defaultProps,
|
|
322
|
+
selectedText: "Edit me",
|
|
323
|
+
linkData: {
|
|
324
|
+
url: "http://old-url.com",
|
|
325
|
+
newTab: true,
|
|
326
|
+
noFollow: true,
|
|
327
|
+
isEditing: true,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
332
|
+
|
|
333
|
+
await waitFor(() => {
|
|
334
|
+
const newTabCheckbox = screen.getByTestId("checkbox-newTab") as HTMLInputElement;
|
|
335
|
+
const noFollowCheckbox = screen.getByTestId("checkbox-noFollow") as HTMLInputElement;
|
|
336
|
+
|
|
337
|
+
expect(newTabCheckbox.checked).toBe(true);
|
|
338
|
+
expect(noFollowCheckbox.checked).toBe(true);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe("Text field handling", () => {
|
|
344
|
+
it("should update link text when text field changes", async () => {
|
|
345
|
+
const mockOnInsert = jest.fn();
|
|
346
|
+
const props = {
|
|
347
|
+
...defaultProps,
|
|
348
|
+
onInsert: mockOnInsert,
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
352
|
+
|
|
353
|
+
const textField = screen.getByTestId("field-text") as HTMLInputElement;
|
|
354
|
+
fireEvent.change(textField, { target: { value: "New text" } });
|
|
355
|
+
|
|
356
|
+
const urlField = screen.getByTestId("field-url") as HTMLInputElement;
|
|
357
|
+
fireEvent.change(urlField, { target: { value: "http://example.com" } });
|
|
358
|
+
|
|
359
|
+
const button = screen.getByTestId("insert-button");
|
|
360
|
+
fireEvent.click(button);
|
|
361
|
+
|
|
362
|
+
await waitFor(() => {
|
|
363
|
+
expect(mockOnInsert).toHaveBeenCalledWith(
|
|
364
|
+
"http://example.com",
|
|
365
|
+
"New text",
|
|
366
|
+
expect.any(Object),
|
|
367
|
+
);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe("Image link mode", () => {
|
|
373
|
+
it("should hide text field when isImageLink is true", () => {
|
|
374
|
+
const props = {
|
|
375
|
+
...defaultProps,
|
|
376
|
+
linkData: {
|
|
377
|
+
url: "http://example.com",
|
|
378
|
+
newTab: false,
|
|
379
|
+
noFollow: false,
|
|
380
|
+
isImageLink: true,
|
|
381
|
+
isEditing: false,
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
386
|
+
|
|
387
|
+
const textField = screen.queryByTestId("field-text");
|
|
388
|
+
expect(textField).not.toBeInTheDocument();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("should render URL field for image links", () => {
|
|
392
|
+
const props = {
|
|
393
|
+
...defaultProps,
|
|
394
|
+
linkData: {
|
|
395
|
+
url: "http://example.com",
|
|
396
|
+
newTab: false,
|
|
397
|
+
noFollow: false,
|
|
398
|
+
isImageLink: true,
|
|
399
|
+
isEditing: false,
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
renderWithTheme(<LinkPopover {...props} />);
|
|
404
|
+
|
|
405
|
+
const urlField = screen.getByTestId("field-url");
|
|
406
|
+
expect(urlField).toBeTruthy();
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
});
|