@griddo/ax 1.73.10 → 1.73.11
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/MainWrapper/AppBar/AppBar.test.tsx +505 -0
- package/src/__tests__/components/MainWrapper/MainWrapper.test.tsx +137 -0
- package/src/components/LanguageMenu/index.tsx +2 -2
- package/src/components/MainWrapper/AppBar/atoms.tsx +3 -3
- package/src/components/MainWrapper/AppBar/index.tsx +15 -13
- package/src/components/MainWrapper/AppBar/style.tsx +3 -0
- package/src/components/MainWrapper/index.tsx +5 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "1.73.
|
|
4
|
+
"version": "1.73.11",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Carlos Torres <carlos.torres@secuoyas.com>",
|
|
@@ -226,5 +226,5 @@
|
|
|
226
226
|
"publishConfig": {
|
|
227
227
|
"access": "public"
|
|
228
228
|
},
|
|
229
|
-
"gitHead": "
|
|
229
|
+
"gitHead": "0ff3dc60103c9eda592bec1db564b7afff2871bf"
|
|
230
230
|
}
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { BrowserRouter } from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
import { ThemeProvider } from "styled-components";
|
|
5
|
+
import { render, cleanup, screen, fireEvent } from "@testing-library/react";
|
|
6
|
+
import { parseTheme } from "@ax/helpers";
|
|
7
|
+
import "@testing-library/jest-dom";
|
|
8
|
+
|
|
9
|
+
import AppBar, { IAppBarProps } from "@ax/components/MainWrapper/AppBar";
|
|
10
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
11
|
+
|
|
12
|
+
afterEach(cleanup);
|
|
13
|
+
|
|
14
|
+
describe("AppBar component rendering", () => {
|
|
15
|
+
it("should render the component empty with title", () => {
|
|
16
|
+
const defaultProps: IAppBarProps = {
|
|
17
|
+
title: "the title",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
render(
|
|
21
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
22
|
+
<AppBar {...defaultProps} />
|
|
23
|
+
</ThemeProvider>,
|
|
24
|
+
{ wrapper: BrowserRouter }
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const header = screen.getByTestId("appbar-header");
|
|
28
|
+
expect(header).toBeTruthy();
|
|
29
|
+
expect(header).not.toHaveClass("fixed");
|
|
30
|
+
|
|
31
|
+
const title = screen.getByText("the title");
|
|
32
|
+
expect(title).toBeTruthy();
|
|
33
|
+
|
|
34
|
+
const backButton = screen.queryByTestId("back-button-wrapper");
|
|
35
|
+
expect(backButton).toBeFalsy();
|
|
36
|
+
|
|
37
|
+
const tabsWrapper = screen.queryByTestId("tabs-wrapper");
|
|
38
|
+
expect(tabsWrapper).toBeFalsy();
|
|
39
|
+
|
|
40
|
+
const searchWrapper = screen.queryByTestId("search-wrapper");
|
|
41
|
+
expect(searchWrapper).toBeFalsy();
|
|
42
|
+
|
|
43
|
+
const languageWrapper = screen.queryByTestId("language-wrapper");
|
|
44
|
+
expect(languageWrapper).toBeFalsy();
|
|
45
|
+
|
|
46
|
+
const pageStatusWrapper = screen.queryByTestId("page-status-wrapper");
|
|
47
|
+
expect(pageStatusWrapper).toBeFalsy();
|
|
48
|
+
|
|
49
|
+
const errorCenterWrapper = screen.queryByTestId("error-center-wrapper");
|
|
50
|
+
expect(errorCenterWrapper).toBeFalsy();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should render the component with subtitle", () => {
|
|
54
|
+
const defaultProps: IAppBarProps = {
|
|
55
|
+
title: "the title",
|
|
56
|
+
subtitle: "the subtitle",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
render(
|
|
60
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
61
|
+
<AppBar {...defaultProps} />
|
|
62
|
+
</ThemeProvider>,
|
|
63
|
+
{ wrapper: BrowserRouter }
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const subtitle = screen.getByText("the subtitle");
|
|
67
|
+
expect(subtitle).toBeTruthy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should render the component inversed", () => {
|
|
71
|
+
const defaultProps: IAppBarProps = {
|
|
72
|
+
title: "the title",
|
|
73
|
+
inversed: true,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
render(
|
|
77
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
78
|
+
<AppBar {...defaultProps} />
|
|
79
|
+
</ThemeProvider>,
|
|
80
|
+
{ wrapper: BrowserRouter }
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const header = screen.getByTestId("appbar-header");
|
|
84
|
+
expect(header).toBeTruthy();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should render with fixed class", () => {
|
|
88
|
+
const defaultProps: IAppBarProps = {
|
|
89
|
+
title: "the title",
|
|
90
|
+
fixedAppBar: true,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
render(
|
|
94
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
95
|
+
<AppBar {...defaultProps} />
|
|
96
|
+
</ThemeProvider>,
|
|
97
|
+
{ wrapper: BrowserRouter }
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const header = screen.getByTestId("appbar-header");
|
|
101
|
+
expect(header).toBeTruthy();
|
|
102
|
+
expect(header).toHaveClass("fixed");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should render without fixed class", () => {
|
|
106
|
+
const defaultProps: IAppBarProps = {
|
|
107
|
+
title: "the title",
|
|
108
|
+
fixedAppBar: false,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
render(
|
|
112
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
113
|
+
<AppBar {...defaultProps} />
|
|
114
|
+
</ThemeProvider>,
|
|
115
|
+
{ wrapper: BrowserRouter }
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const header = screen.getByTestId("appbar-header");
|
|
119
|
+
expect(header).toBeTruthy();
|
|
120
|
+
expect(header).not.toHaveClass("fixed");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should render with additional class", () => {
|
|
124
|
+
const defaultProps: IAppBarProps = {
|
|
125
|
+
title: "the title",
|
|
126
|
+
additionalClass: "customClass",
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
render(
|
|
130
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
131
|
+
<AppBar {...defaultProps} />
|
|
132
|
+
</ThemeProvider>,
|
|
133
|
+
{ wrapper: BrowserRouter }
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const header = screen.getByTestId("appbar-header");
|
|
137
|
+
expect(header).toBeTruthy();
|
|
138
|
+
expect(header).toHaveClass("customClass");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should render with back link", () => {
|
|
142
|
+
const defaultProps: IAppBarProps = {
|
|
143
|
+
title: "the title",
|
|
144
|
+
backLink: true,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
render(
|
|
148
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
149
|
+
<AppBar {...defaultProps} />
|
|
150
|
+
</ThemeProvider>,
|
|
151
|
+
{ wrapper: BrowserRouter }
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const backButton = screen.getByTestId("back-button-wrapper");
|
|
155
|
+
expect(backButton).toBeTruthy();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("should render tabs with icons", () => {
|
|
159
|
+
const tabs = {
|
|
160
|
+
icons: [
|
|
161
|
+
{ name: "tab1", text: "Tab 1" },
|
|
162
|
+
{ name: "tab2", text: "Tab 2" },
|
|
163
|
+
],
|
|
164
|
+
selectedTab: "tab1",
|
|
165
|
+
action: jest.fn(),
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const defaultProps: IAppBarProps = {
|
|
169
|
+
title: "the title",
|
|
170
|
+
tabs,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
render(
|
|
174
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
175
|
+
<AppBar {...defaultProps} />
|
|
176
|
+
</ThemeProvider>,
|
|
177
|
+
{ wrapper: BrowserRouter }
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const tabsWrapper = screen.getByTestId("tabs-wrapper");
|
|
181
|
+
expect(tabsWrapper).toBeTruthy();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("should render tabs", () => {
|
|
185
|
+
const tabs = {
|
|
186
|
+
tabSet: ["Tab 1", "Tab 2"],
|
|
187
|
+
selectedTab: "Tab 1",
|
|
188
|
+
action: jest.fn(),
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const defaultProps: IAppBarProps = {
|
|
192
|
+
title: "the title",
|
|
193
|
+
tabs,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
render(
|
|
197
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
198
|
+
<AppBar {...defaultProps} />
|
|
199
|
+
</ThemeProvider>,
|
|
200
|
+
{ wrapper: BrowserRouter }
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const tabsWrapper = screen.getByTestId("tabs-wrapper");
|
|
204
|
+
expect(tabsWrapper).toBeTruthy();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should render the search field", () => {
|
|
208
|
+
const defaultProps: IAppBarProps = {
|
|
209
|
+
title: "the title",
|
|
210
|
+
searchAction: jest.fn(),
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
render(
|
|
214
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
215
|
+
<AppBar {...defaultProps} />
|
|
216
|
+
</ThemeProvider>,
|
|
217
|
+
{ wrapper: BrowserRouter }
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const searchWrapper = screen.getByTestId("search-wrapper");
|
|
221
|
+
expect(searchWrapper).toBeTruthy();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("should render the language", () => {
|
|
225
|
+
const defaultProps: IAppBarProps = {
|
|
226
|
+
title: "the title",
|
|
227
|
+
language: { locale: "es_ES", id: 4 },
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
render(
|
|
231
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
232
|
+
<AppBar {...defaultProps} />
|
|
233
|
+
</ThemeProvider>,
|
|
234
|
+
{ wrapper: BrowserRouter }
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const languageWrapper = screen.getByTestId("language-wrapper");
|
|
238
|
+
expect(languageWrapper).toBeTruthy();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should render the page status", () => {
|
|
242
|
+
const defaultProps: IAppBarProps = {
|
|
243
|
+
title: "the title",
|
|
244
|
+
pageStatus: "active",
|
|
245
|
+
pageStatusActions: [
|
|
246
|
+
{
|
|
247
|
+
icon: "icon",
|
|
248
|
+
label: "Action 1",
|
|
249
|
+
action: jest.fn(),
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
icon: "icon2",
|
|
253
|
+
label: "Action 2",
|
|
254
|
+
action: jest.fn(),
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
render(
|
|
260
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
261
|
+
<AppBar {...defaultProps} />
|
|
262
|
+
</ThemeProvider>,
|
|
263
|
+
{ wrapper: BrowserRouter }
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const pageStatusWrapper = screen.getByTestId("page-status-wrapper");
|
|
267
|
+
expect(pageStatusWrapper).toBeTruthy();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should render the error center", () => {
|
|
271
|
+
const defaultProps: IAppBarProps = {
|
|
272
|
+
title: "the title",
|
|
273
|
+
isFromEditor: true,
|
|
274
|
+
errors: [
|
|
275
|
+
{
|
|
276
|
+
type: "error",
|
|
277
|
+
message: "error message 1",
|
|
278
|
+
validator: {},
|
|
279
|
+
editorID: null,
|
|
280
|
+
component: "",
|
|
281
|
+
name: "",
|
|
282
|
+
key: "",
|
|
283
|
+
tab: "",
|
|
284
|
+
template: false,
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
type: "error",
|
|
288
|
+
message: "error message 2",
|
|
289
|
+
validator: {},
|
|
290
|
+
editorID: null,
|
|
291
|
+
component: "",
|
|
292
|
+
name: "",
|
|
293
|
+
key: "",
|
|
294
|
+
tab: "",
|
|
295
|
+
template: false,
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
render(
|
|
301
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
302
|
+
<AppBar {...defaultProps} />
|
|
303
|
+
</ThemeProvider>,
|
|
304
|
+
{ wrapper: BrowserRouter }
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
const errorCenterWrapper = screen.getByTestId("error-center-wrapper");
|
|
308
|
+
expect(errorCenterWrapper).toBeTruthy();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("should render the right line button", () => {
|
|
312
|
+
const label = "the right line button";
|
|
313
|
+
const defaultProps: IAppBarProps = {
|
|
314
|
+
title: "the title",
|
|
315
|
+
rightLineButton: {
|
|
316
|
+
label,
|
|
317
|
+
action: jest.fn(),
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const { getByText } = render(
|
|
322
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
323
|
+
<AppBar {...defaultProps} />
|
|
324
|
+
</ThemeProvider>,
|
|
325
|
+
{ wrapper: BrowserRouter }
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
const button = getByText(label);
|
|
329
|
+
expect(button).toBeTruthy();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("should render the right button", () => {
|
|
333
|
+
const label = "the right button";
|
|
334
|
+
const defaultProps: IAppBarProps = {
|
|
335
|
+
title: "the title",
|
|
336
|
+
rightButton: {
|
|
337
|
+
label,
|
|
338
|
+
action: jest.fn(),
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const { getByText } = render(
|
|
343
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
344
|
+
<AppBar {...defaultProps} />
|
|
345
|
+
</ThemeProvider>,
|
|
346
|
+
{ wrapper: BrowserRouter }
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const button = getByText(label);
|
|
350
|
+
expect(button).toBeTruthy();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("should render the action menu", () => {
|
|
354
|
+
const defaultProps: IAppBarProps = {
|
|
355
|
+
title: "the title",
|
|
356
|
+
downArrowMenu: {
|
|
357
|
+
displayed: true,
|
|
358
|
+
options: [
|
|
359
|
+
{
|
|
360
|
+
icon: "icon",
|
|
361
|
+
label: "Action 1",
|
|
362
|
+
action: jest.fn(),
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
icon: "icon2",
|
|
366
|
+
label: "Action 2",
|
|
367
|
+
action: jest.fn(),
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
button: { label: "the menu button", action: jest.fn() },
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const { getByTestId } = render(
|
|
375
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
376
|
+
<AppBar {...defaultProps} />
|
|
377
|
+
</ThemeProvider>,
|
|
378
|
+
{ wrapper: BrowserRouter }
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
const arrowButtonWrapper = getByTestId("down-arrow-button-wrapper");
|
|
382
|
+
expect(arrowButtonWrapper).toBeTruthy();
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe("AppBar component events", () => {
|
|
387
|
+
it("should render the language menu on click", async () => {
|
|
388
|
+
const defaultProps: IAppBarProps = {
|
|
389
|
+
title: "the title",
|
|
390
|
+
downArrowMenu: {
|
|
391
|
+
displayed: true,
|
|
392
|
+
options: [
|
|
393
|
+
{
|
|
394
|
+
icon: "icon",
|
|
395
|
+
label: "Action 1",
|
|
396
|
+
action: jest.fn(),
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
icon: "icon2",
|
|
400
|
+
label: "Action 2",
|
|
401
|
+
action: jest.fn(),
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
button: { label: "the menu button", action: jest.fn() },
|
|
405
|
+
},
|
|
406
|
+
language: { locale: "en_GB", id: 4 },
|
|
407
|
+
availableLanguages: [
|
|
408
|
+
{
|
|
409
|
+
domain: { id: 1, slug: "/pre-griddo", url: "//cx.dev.griddo.io/pre-griddo" },
|
|
410
|
+
home: "//cx.dev.griddo.io/pre-griddo/gonzalo-h",
|
|
411
|
+
id: 4,
|
|
412
|
+
isDefault: true,
|
|
413
|
+
label: "EN",
|
|
414
|
+
language: "English",
|
|
415
|
+
locale: "en_GB",
|
|
416
|
+
path: "/gonzalo-h",
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
domain: { id: 1, url: "//cx.dev.griddo.io/pre-griddo", slug: "/pre-griddo" },
|
|
420
|
+
home: "//cx.dev.griddo.io/pre-griddo/gonzalo-h/es",
|
|
421
|
+
id: 2,
|
|
422
|
+
isDefault: false,
|
|
423
|
+
label: "ES",
|
|
424
|
+
language: "Spanish",
|
|
425
|
+
locale: "es_ES",
|
|
426
|
+
path: "/gonzalo-h/es",
|
|
427
|
+
},
|
|
428
|
+
],
|
|
429
|
+
languageActions: {
|
|
430
|
+
createNewTranslation: jest.fn(),
|
|
431
|
+
getSiteContent: jest.fn(),
|
|
432
|
+
setLanguage: jest.fn(),
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const { getByTestId, getAllByTestId } = render(
|
|
437
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
438
|
+
<AppBar {...defaultProps} />
|
|
439
|
+
</ThemeProvider>,
|
|
440
|
+
{ wrapper: BrowserRouter }
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
const languageMenuBtn = getByTestId("language-menu-btn");
|
|
444
|
+
expect(languageMenuBtn).toBeTruthy();
|
|
445
|
+
fireEvent.click(languageMenuBtn);
|
|
446
|
+
const languageMenu = getByTestId("language-menu");
|
|
447
|
+
expect(languageMenu).toBeTruthy();
|
|
448
|
+
const languageMenuItem = getAllByTestId("language-menu-item");
|
|
449
|
+
expect(languageMenuItem.length).toEqual(2);
|
|
450
|
+
const languageLocaleLabel = getByTestId("language-locale-label");
|
|
451
|
+
expect(languageLocaleLabel.textContent).toEqual("en_GB");
|
|
452
|
+
expect(languageMenuItem[0].textContent).toEqual("EN - English");
|
|
453
|
+
expect(languageMenuItem[1].textContent).toEqual("ES - Spanish");
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("should render the status menu on click", async () => {
|
|
457
|
+
const defaultProps: IAppBarProps = {
|
|
458
|
+
title: "the title",
|
|
459
|
+
downArrowMenu: {
|
|
460
|
+
displayed: true,
|
|
461
|
+
options: [
|
|
462
|
+
{
|
|
463
|
+
icon: "icon",
|
|
464
|
+
label: "Action 1",
|
|
465
|
+
action: jest.fn(),
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
icon: "icon2",
|
|
469
|
+
label: "Action 2",
|
|
470
|
+
action: jest.fn(),
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
button: { label: "the menu button", action: jest.fn() },
|
|
474
|
+
},
|
|
475
|
+
pageStatus: "active",
|
|
476
|
+
pageStatusActions: [
|
|
477
|
+
{
|
|
478
|
+
icon: "icon",
|
|
479
|
+
label: "Action 1",
|
|
480
|
+
action: jest.fn(),
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
icon: "icon2",
|
|
484
|
+
label: "Action 2",
|
|
485
|
+
action: jest.fn(),
|
|
486
|
+
},
|
|
487
|
+
],
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
const { getByTestId, getAllByTestId } = render(
|
|
491
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
492
|
+
<AppBar {...defaultProps} />
|
|
493
|
+
</ThemeProvider>,
|
|
494
|
+
{ wrapper: BrowserRouter }
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
const statusBtn = getByTestId("status-button");
|
|
498
|
+
expect(statusBtn).toBeTruthy();
|
|
499
|
+
fireEvent.click(statusBtn);
|
|
500
|
+
const actionSimpleMenu = getByTestId("action-simple-menu");
|
|
501
|
+
expect(actionSimpleMenu).toBeTruthy();
|
|
502
|
+
const actionMenuItem = getAllByTestId("action-menu-item");
|
|
503
|
+
expect(actionMenuItem.length).toEqual(2);
|
|
504
|
+
});
|
|
505
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { BrowserRouter } from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
import { ThemeProvider } from "styled-components";
|
|
5
|
+
import { render, cleanup, screen } from "@testing-library/react";
|
|
6
|
+
import { parseTheme } from "@ax/helpers";
|
|
7
|
+
import "@testing-library/jest-dom";
|
|
8
|
+
|
|
9
|
+
import MainWrapper, { IWrapperProps } from "@ax/components/MainWrapper";
|
|
10
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
11
|
+
|
|
12
|
+
afterEach(cleanup);
|
|
13
|
+
|
|
14
|
+
describe("MainWrapper component rendering", () => {
|
|
15
|
+
it("should render the component with children", () => {
|
|
16
|
+
const defaultProps: IWrapperProps = {
|
|
17
|
+
title: "the title",
|
|
18
|
+
children: <div>the children</div>,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
render(
|
|
22
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
23
|
+
<MainWrapper {...defaultProps} />
|
|
24
|
+
</ThemeProvider>,
|
|
25
|
+
{ wrapper: BrowserRouter }
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const wrapper = screen.getByTestId("main-wrapper");
|
|
29
|
+
expect(wrapper).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should render the component without children", () => {
|
|
33
|
+
const defaultProps: IWrapperProps = {
|
|
34
|
+
title: "the title",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
render(
|
|
38
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
39
|
+
<MainWrapper {...defaultProps} />
|
|
40
|
+
</ThemeProvider>,
|
|
41
|
+
{ wrapper: BrowserRouter }
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const wrapper = screen.getByTestId("main-wrapper");
|
|
45
|
+
expect(wrapper).toBeTruthy();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should add padding top if fixedAppBar", () => {
|
|
49
|
+
const defaultProps: IWrapperProps = {
|
|
50
|
+
title: "the title",
|
|
51
|
+
fixedAppBar: true,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
render(
|
|
55
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
56
|
+
<MainWrapper {...defaultProps} />
|
|
57
|
+
</ThemeProvider>,
|
|
58
|
+
{ wrapper: BrowserRouter }
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const wrapper = screen.getByTestId("main-wrapper");
|
|
62
|
+
expect(wrapper).toBeTruthy();
|
|
63
|
+
expect(wrapper).toHaveStyle(`padding-top: 64px`);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should add padding top if fixedAppBar", () => {
|
|
67
|
+
const defaultProps: IWrapperProps = {
|
|
68
|
+
title: "the title",
|
|
69
|
+
fixedAppBar: true,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
render(
|
|
73
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
74
|
+
<MainWrapper {...defaultProps} />
|
|
75
|
+
</ThemeProvider>,
|
|
76
|
+
{ wrapper: BrowserRouter }
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const wrapper = screen.getByTestId("main-wrapper");
|
|
80
|
+
expect(wrapper).toBeTruthy();
|
|
81
|
+
expect(wrapper).toHaveStyle(`padding-top: 64px`);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should have padding top 0 if fixedAppBar is false", () => {
|
|
85
|
+
const defaultProps: IWrapperProps = {
|
|
86
|
+
title: "the title",
|
|
87
|
+
fixedAppBar: false,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
render(
|
|
91
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
92
|
+
<MainWrapper {...defaultProps} />
|
|
93
|
+
</ThemeProvider>,
|
|
94
|
+
{ wrapper: BrowserRouter }
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const wrapper = screen.getByTestId("main-wrapper");
|
|
98
|
+
expect(wrapper).toBeTruthy();
|
|
99
|
+
expect(wrapper).toHaveStyle(`padding-top: 0`);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("main should have overflow visible if fullwidth", () => {
|
|
103
|
+
const defaultProps: IWrapperProps = {
|
|
104
|
+
title: "the title",
|
|
105
|
+
fullWidth: true,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
render(
|
|
109
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
110
|
+
<MainWrapper {...defaultProps} />
|
|
111
|
+
</ThemeProvider>,
|
|
112
|
+
{ wrapper: BrowserRouter }
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const main = screen.getByTestId("main-component");
|
|
116
|
+
expect(main).toBeTruthy();
|
|
117
|
+
expect(main).toHaveStyle(`overflow: visible`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("main should have overflow auto if not fullwidth", () => {
|
|
121
|
+
const defaultProps: IWrapperProps = {
|
|
122
|
+
title: "the title",
|
|
123
|
+
fullWidth: false,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
render(
|
|
127
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
128
|
+
<MainWrapper {...defaultProps} />
|
|
129
|
+
</ThemeProvider>,
|
|
130
|
+
{ wrapper: BrowserRouter }
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const main = screen.getByTestId("main-component");
|
|
134
|
+
expect(main).toBeTruthy();
|
|
135
|
+
expect(main).toHaveStyle(`overflow: auto`);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -37,7 +37,7 @@ const LanguageMenu = (props: IProps): JSX.Element => {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const languageMenuItem = (item: ILanguage) => (
|
|
40
|
-
<S.LanguageItem key={item.locale} selected={item.locale === language} onClick={setLanguage(item)}>
|
|
40
|
+
<S.LanguageItem key={item.locale} selected={item.locale === language} onClick={setLanguage(item)} data-testid="language-menu-item">
|
|
41
41
|
<S.LanguageItemWrapper>
|
|
42
42
|
<S.LanguageLabel>
|
|
43
43
|
<Flag name={item.locale} />
|
|
@@ -54,7 +54,7 @@ const LanguageMenu = (props: IProps): JSX.Element => {
|
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
return (
|
|
57
|
-
<S.ActionMenu>{availableLanguages && availableLanguages.map((item: any) => languageMenuItem(item))}</S.ActionMenu>
|
|
57
|
+
<S.ActionMenu data-testid="language-menu">{availableLanguages && availableLanguages.map((item: any) => languageMenuItem(item))}</S.ActionMenu>
|
|
58
58
|
);
|
|
59
59
|
};
|
|
60
60
|
|
|
@@ -6,7 +6,7 @@ import * as S from "./style";
|
|
|
6
6
|
const ActionMenuItem = (item: any, color?: boolean) => {
|
|
7
7
|
const { icon, action, label } = item;
|
|
8
8
|
return (
|
|
9
|
-
<S.ActionItem className={color ? "" : "grey"} key={icon} onClick={action}>
|
|
9
|
+
<S.ActionItem data-testid="action-menu-item" className={color ? "" : "grey"} key={icon} onClick={action}>
|
|
10
10
|
<Icon name={icon} />
|
|
11
11
|
<S.ActionText>{label}</S.ActionText>
|
|
12
12
|
</S.ActionItem>
|
|
@@ -42,7 +42,7 @@ const ActionMenu = (props: any) => {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const DownArrowButton = (props: any) => (
|
|
45
|
-
<S.IconWrapper inversed={props.inversed}>
|
|
45
|
+
<S.IconWrapper inversed={props.inversed} data-testid="down-arrow-button-wrapper">
|
|
46
46
|
<Icon name="DownArrow" />
|
|
47
47
|
</S.IconWrapper>
|
|
48
48
|
);
|
|
@@ -52,7 +52,7 @@ const ActionSimpleMenu = (props: any) => {
|
|
|
52
52
|
return (
|
|
53
53
|
menu &&
|
|
54
54
|
menu.options && (
|
|
55
|
-
<S.ActionMenu>{menu.options.map((item: any, i: number) => ActionMenuItem(item, true))}</S.ActionMenu>
|
|
55
|
+
<S.ActionMenu data-testid="action-simple-menu">{menu.options.map((item: any, i: number) => ActionMenuItem(item, true))}</S.ActionMenu>
|
|
56
56
|
)
|
|
57
57
|
);
|
|
58
58
|
};
|
|
@@ -114,10 +114,10 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
114
114
|
const LanguageBtn = () =>
|
|
115
115
|
language && (
|
|
116
116
|
<>
|
|
117
|
-
<S.FlagWrapper>
|
|
117
|
+
<S.FlagWrapper data-testid="language-menu-btn">
|
|
118
118
|
<Flag name={language.locale} size="24" />
|
|
119
119
|
</S.FlagWrapper>
|
|
120
|
-
<S.LanguageTextWrapper>{language.locale}</S.LanguageTextWrapper>
|
|
120
|
+
<S.LanguageTextWrapper data-testid="language-locale-label">{language.locale}</S.LanguageTextWrapper>
|
|
121
121
|
<DownArrowButton />
|
|
122
122
|
</>
|
|
123
123
|
);
|
|
@@ -130,7 +130,7 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
130
130
|
</S.ErrorWrapper>
|
|
131
131
|
);
|
|
132
132
|
|
|
133
|
-
const StatusBtn = () => pageStatus && <Icon name={pageStatus} size="24"
|
|
133
|
+
const StatusBtn = () => pageStatus && <S.StatusBtn data-testid="status-button"><Icon name={pageStatus} size="24" /></S.StatusBtn>;
|
|
134
134
|
|
|
135
135
|
const statusMenu = {
|
|
136
136
|
options: pageStatusActions,
|
|
@@ -148,12 +148,14 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
148
148
|
const languageTooltip = typeof currentPageID === "number" && "Add language";
|
|
149
149
|
|
|
150
150
|
return (
|
|
151
|
-
<S.Header className={`${fixedClass} ${additionalClass}`} inversed={inversed}>
|
|
151
|
+
<S.Header className={`${fixedClass} ${additionalClass}`} inversed={inversed} data-testid="appbar-header">
|
|
152
152
|
<S.WrapperTitle>
|
|
153
153
|
{backLink && (
|
|
154
|
-
<
|
|
155
|
-
<
|
|
156
|
-
|
|
154
|
+
<span data-testid="back-button-wrapper">
|
|
155
|
+
<Tooltip content="Back to content screen" bottom>
|
|
156
|
+
<IconAction icon="FullArrowLeft" onClick={goToPages} inversed={inversed} />
|
|
157
|
+
</Tooltip>
|
|
158
|
+
</span>
|
|
157
159
|
)}
|
|
158
160
|
<S.Title>
|
|
159
161
|
{trimText(title, 50)}
|
|
@@ -161,7 +163,7 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
161
163
|
</S.Title>
|
|
162
164
|
</S.WrapperTitle>
|
|
163
165
|
{tabs && (
|
|
164
|
-
<S.WrapperTabs>
|
|
166
|
+
<S.WrapperTabs data-testid="tabs-wrapper">
|
|
165
167
|
<S.TabsContent>
|
|
166
168
|
<Tabs
|
|
167
169
|
tabs={tabs.tabSet}
|
|
@@ -177,7 +179,7 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
177
179
|
<S.WrapperEnd>
|
|
178
180
|
{searchAction && (
|
|
179
181
|
<>
|
|
180
|
-
<S.SearchWrapper length={searchFilters && searchFilters.length ? 8 : 5}>
|
|
182
|
+
<S.SearchWrapper length={searchFilters && searchFilters.length ? 8 : 5} data-testid="search-wrapper">
|
|
181
183
|
<SearchField
|
|
182
184
|
onChange={searchAction}
|
|
183
185
|
onFilterChange={filterSearchAction}
|
|
@@ -190,7 +192,7 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
190
192
|
)}
|
|
191
193
|
{language && (
|
|
192
194
|
<>
|
|
193
|
-
<S.LanguageWrapper>
|
|
195
|
+
<S.LanguageWrapper data-testid="language-wrapper">
|
|
194
196
|
<Tooltip content={languageTooltip} hideOnClick bottom>
|
|
195
197
|
<FloatingMenu Button={LanguageBtn} isInAppBar={true} position="left">
|
|
196
198
|
{languageMenu}
|
|
@@ -202,7 +204,7 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
202
204
|
)}
|
|
203
205
|
{pageStatus && (
|
|
204
206
|
<>
|
|
205
|
-
<S.IconStatusWrapper>
|
|
207
|
+
<S.IconStatusWrapper data-testid="page-status-wrapper">
|
|
206
208
|
<Tooltip content={publishedTooltip[pageStatus]} bottom>
|
|
207
209
|
<PageStatus />
|
|
208
210
|
</Tooltip>
|
|
@@ -212,7 +214,7 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
212
214
|
)}
|
|
213
215
|
{isFromEditor && errors && errors.length > 0 && (
|
|
214
216
|
<>
|
|
215
|
-
<S.IconStatusWrapper>
|
|
217
|
+
<S.IconStatusWrapper data-testid="error-center-wrapper">
|
|
216
218
|
<FloatingMenu Button={ErrorCenterBtn} isInAppBar={true} position="left" offset={-20}>
|
|
217
219
|
<ErrorCenter errors={errors} actions={errorActions} />
|
|
218
220
|
</FloatingMenu>
|
|
@@ -248,7 +250,7 @@ const AppBar = (props: IProps): JSX.Element => {
|
|
|
248
250
|
);
|
|
249
251
|
};
|
|
250
252
|
|
|
251
|
-
interface IAppBarProps {
|
|
253
|
+
export interface IAppBarProps {
|
|
252
254
|
backLink?: boolean | string;
|
|
253
255
|
rightButton?: { label: string; disabled?: boolean; action: (e: any) => void };
|
|
254
256
|
rightLineButton?: { label: string; disabled?: boolean; action: (e: any) => void };
|
|
@@ -181,6 +181,8 @@ const SearchWrapper = styled.div<{ length: number }>`
|
|
|
181
181
|
justify-content: flex-end;
|
|
182
182
|
`;
|
|
183
183
|
|
|
184
|
+
const StatusBtn = styled.span``;
|
|
185
|
+
|
|
184
186
|
export {
|
|
185
187
|
ActionMenu,
|
|
186
188
|
Header,
|
|
@@ -202,4 +204,5 @@ export {
|
|
|
202
204
|
WrapperEnd,
|
|
203
205
|
WrapperTitle,
|
|
204
206
|
TabsContent,
|
|
207
|
+
StatusBtn
|
|
205
208
|
};
|
|
@@ -9,14 +9,16 @@ const MainWrapper = (props: IWrapperProps): JSX.Element => {
|
|
|
9
9
|
const { children, fixedAppBar, fullWidth } = props;
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
|
-
<S.Wrapper fixedAppBar={fixedAppBar}>
|
|
12
|
+
<S.Wrapper fixedAppBar={fixedAppBar} data-testid="main-wrapper">
|
|
13
13
|
<AppBar {...props} />
|
|
14
|
-
<S.Main fullWidth={fullWidth}>
|
|
14
|
+
<S.Main fullWidth={fullWidth} data-testid="main-component">
|
|
15
|
+
{children}
|
|
16
|
+
</S.Main>
|
|
15
17
|
</S.Wrapper>
|
|
16
18
|
);
|
|
17
19
|
};
|
|
18
20
|
|
|
19
|
-
interface IWrapperProps {
|
|
21
|
+
export interface IWrapperProps {
|
|
20
22
|
children?: any[] | JSX.Element;
|
|
21
23
|
backLink?: boolean | string;
|
|
22
24
|
rightButton?: { label: string; disabled?: boolean; action: (e: any) => void };
|