@griddo/ax 1.72.11 → 1.73.2
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/scripts/griddo-sync-schemas.js +1 -1
- package/src/__tests__/components/ErrorCenter/ErrorCenter.test.tsx +186 -0
- package/src/__tests__/components/Flag/Flag.test.tsx +60 -0
- package/src/__tests__/components/FloatingMenu/FloatingMenu.test.tsx +712 -0
- package/src/__tests__/components/FloatingPanel/FloatingPanel.test.tsx +149 -0
- package/src/__tests__/components/GuardModal/GuardModal.test.tsx +31 -0
- package/src/__tests__/components/Icon/Icon.test.tsx +76 -0
- package/src/__tests__/components/IconAction/IconAction.test.tsx +91 -0
- package/src/__tests__/components/Notification/Notification.test.tsx +206 -0
- package/src/__tests__/components/Notification/SubNotification/Subnotification.test.tsx +46 -0
- package/src/__tests__/components/ReorderArrows/ReorderArrows.test.tsx +96 -0
- package/src/__tests__/components/ResizePanel/ResizePanel.test.tsx +200 -0
- package/src/__tests__/components/SearchField/SearchField.test.tsx +375 -0
- package/src/api/analytics.tsx +4 -4
- package/src/components/ActionMenu/style.tsx +1 -0
- package/src/components/ConfigPanel/Form/ConnectedField/NavConnectedField/index.tsx +1 -1
- package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/Field/index.tsx +2 -1
- package/src/components/ConfigPanel/Form/index.tsx +22 -1
- package/src/components/ConfigPanel/Form/style.tsx +19 -0
- package/src/components/ConfigPanel/GlobalPageForm/index.tsx +22 -3
- package/src/components/ConfigPanel/GlobalPageForm/style.tsx +18 -2
- package/src/components/ConfigPanel/NavigationForm/Field/index.tsx +25 -13
- package/src/components/ConfigPanel/index.tsx +8 -0
- package/src/components/ErrorCenter/index.tsx +8 -4
- package/src/components/Fields/DateField/DatePickerInput/index.tsx +30 -8
- package/src/components/Fields/DateField/index.tsx +8 -2
- package/src/components/Fields/Select/index.tsx +1 -0
- package/src/components/Flag/index.tsx +13 -11
- package/src/components/FloatingMenu/index.tsx +23 -7
- package/src/components/FloatingMenu/style.tsx +1 -0
- package/src/components/FloatingPanel/index.tsx +9 -3
- package/src/components/GuardModal/index.tsx +3 -3
- package/src/components/Icon/index.tsx +2 -1
- package/src/components/IconAction/index.tsx +3 -3
- package/src/components/MainWrapper/AppBar/index.tsx +3 -1
- package/src/components/MainWrapper/AppBar/style.tsx +3 -0
- package/src/components/MenuItem/index.tsx +1 -1
- package/src/components/Modal/index.tsx +1 -1
- package/src/components/Notification/SubNotification/index.tsx +33 -0
- package/src/components/Notification/SubNotification/style.tsx +49 -0
- package/src/components/Notification/index.tsx +31 -17
- package/src/components/Notification/style.tsx +33 -8
- package/src/components/ReorderArrows/index.tsx +3 -3
- package/src/components/ResizePanel/ResizeHandle/index.tsx +29 -38
- package/src/components/ResizePanel/index.tsx +13 -15
- package/src/components/SearchField/index.tsx +9 -8
- package/src/containers/Analytics/actions.tsx +14 -4
- package/src/containers/App/actions.tsx +18 -6
- package/src/containers/App/reducer.tsx +1 -0
- package/src/containers/Domains/actions.tsx +8 -1
- package/src/containers/Navigation/Defaults/actions.tsx +16 -2
- package/src/containers/PageEditor/actions.tsx +82 -6
- package/src/containers/PageEditor/utils.tsx +28 -10
- package/src/containers/Redirects/actions.tsx +16 -2
- package/src/containers/Sites/actions.tsx +80 -3
- package/src/containers/StructuredData/actions.tsx +24 -3
- package/src/containers/Users/actions.tsx +8 -1
- package/src/forms/errors.tsx +1 -0
- package/src/forms/fields.tsx +6 -3
- package/src/forms/validators.tsx +14 -4
- package/src/guards/error/index.tsx +17 -21
- package/src/helpers/dates.tsx +2 -0
- package/src/helpers/index.tsx +2 -0
- package/src/hooks/modals.tsx +4 -4
- package/src/modules/Content/OptionTable/index.tsx +20 -7
- package/src/modules/Content/index.tsx +4 -7
- package/src/modules/Content/utils.tsx +18 -13
- package/src/modules/FramePreview/index.tsx +39 -12
- package/src/modules/GlobalEditor/index.tsx +17 -20
- package/src/modules/Navigation/Menus/List/Table/index.tsx +2 -2
- package/src/modules/PageEditor/Editor/index.tsx +13 -0
- package/src/modules/PageEditor/index.tsx +17 -20
- package/src/modules/Redirects/RedirectItem/index.tsx +17 -3
- package/src/modules/Settings/ContentTypes/DataPacks/Item/index.tsx +1 -1
- package/src/modules/StructuredData/Form/index.tsx +10 -13
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, cleanup, screen, fireEvent } from "@testing-library/react";
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import "@testing-library/jest-dom";
|
|
7
|
+
|
|
8
|
+
import FloatingPanel, { IFloatingPanelProps } from "@ax/components/FloatingPanel";
|
|
9
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
describe("FloatingPanel component rendering", () => {
|
|
14
|
+
it("should render the component", () => {
|
|
15
|
+
const defaultProps: IFloatingPanelProps = {
|
|
16
|
+
isOpen: true,
|
|
17
|
+
isOpenedSecond: false,
|
|
18
|
+
children: false,
|
|
19
|
+
title: "title",
|
|
20
|
+
toggleModal: jest.fn(),
|
|
21
|
+
handlePanel: jest.fn(),
|
|
22
|
+
secondary: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
render(
|
|
26
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
27
|
+
<FloatingPanel {...defaultProps} />
|
|
28
|
+
</ThemeProvider>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const FloatingPanelWrapper = screen.getByTestId("floating-panel");
|
|
32
|
+
expect(FloatingPanelWrapper).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should render the component with iconAction", () => {
|
|
36
|
+
const defaultProps: IFloatingPanelProps = {
|
|
37
|
+
isOpen: true,
|
|
38
|
+
isOpenedSecond: false,
|
|
39
|
+
children: false,
|
|
40
|
+
title: "title",
|
|
41
|
+
toggleModal: jest.fn(),
|
|
42
|
+
handlePanel: jest.fn(),
|
|
43
|
+
secondary: true,
|
|
44
|
+
closeOnOutsideClick: false,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
render(
|
|
48
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
49
|
+
<FloatingPanel {...defaultProps} />
|
|
50
|
+
</ThemeProvider>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const floatingPanelWrapper = screen.getByTestId("floating-panel");
|
|
54
|
+
expect(floatingPanelWrapper).toBeTruthy();
|
|
55
|
+
const iconAction = screen.getByTestId("icon-action-component");
|
|
56
|
+
expect(iconAction).toBeTruthy();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("FloatingPanel component events trigger", () => {
|
|
61
|
+
it("should trigger the handleOnClick", () => {
|
|
62
|
+
const handlePanelMock = jest.fn();
|
|
63
|
+
const toggleModalMock = jest.fn();
|
|
64
|
+
const defaultProps: IFloatingPanelProps = {
|
|
65
|
+
isOpen: true,
|
|
66
|
+
isOpenedSecond: false,
|
|
67
|
+
children: false,
|
|
68
|
+
title: "title",
|
|
69
|
+
toggleModal: toggleModalMock,
|
|
70
|
+
handlePanel: handlePanelMock,
|
|
71
|
+
secondary: true,
|
|
72
|
+
closeOnOutsideClick: false,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
render(
|
|
76
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
77
|
+
<FloatingPanel {...defaultProps} />
|
|
78
|
+
</ThemeProvider>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const floatingPanelWrapper = screen.getByTestId("floating-panel");
|
|
82
|
+
expect(floatingPanelWrapper).toBeTruthy();
|
|
83
|
+
const iconAction = screen.getByTestId("icon-action-component");
|
|
84
|
+
expect(iconAction).toBeTruthy();
|
|
85
|
+
fireEvent.click(iconAction);
|
|
86
|
+
expect(toggleModalMock).toBeCalled();
|
|
87
|
+
expect(handlePanelMock).toBeCalledWith(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should trigger the handleClickOutside and trigger handlePanel", () => {
|
|
91
|
+
const handlePanelMock = jest.fn();
|
|
92
|
+
const toggleModalMock = jest.fn();
|
|
93
|
+
const defaultProps: IFloatingPanelProps = {
|
|
94
|
+
isOpen: true,
|
|
95
|
+
isOpenedSecond: false,
|
|
96
|
+
children: false,
|
|
97
|
+
title: "title",
|
|
98
|
+
toggleModal: toggleModalMock,
|
|
99
|
+
handlePanel: handlePanelMock,
|
|
100
|
+
secondary: true,
|
|
101
|
+
closeOnOutsideClick: true,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
render(
|
|
105
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
106
|
+
<FloatingPanel {...defaultProps} />
|
|
107
|
+
</ThemeProvider>
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const floatingPanelWrapper = screen.getByTestId("floating-panel");
|
|
111
|
+
expect(floatingPanelWrapper).toBeTruthy();
|
|
112
|
+
const iconAction = screen.getByTestId("icon-action-component");
|
|
113
|
+
expect(iconAction).toBeTruthy();
|
|
114
|
+
|
|
115
|
+
fireEvent.mouseDown(document);
|
|
116
|
+
expect(toggleModalMock).toBeCalled();
|
|
117
|
+
expect(handlePanelMock).toBeCalledWith(false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should trigger the handleClickOutside and not trigger handlePanel", () => {
|
|
121
|
+
const handlePanelMock = jest.fn();
|
|
122
|
+
const toggleModalMock = jest.fn();
|
|
123
|
+
const defaultProps: IFloatingPanelProps = {
|
|
124
|
+
isOpen: true,
|
|
125
|
+
isOpenedSecond: false,
|
|
126
|
+
children: false,
|
|
127
|
+
title: "title",
|
|
128
|
+
toggleModal: toggleModalMock,
|
|
129
|
+
handlePanel: handlePanelMock,
|
|
130
|
+
secondary: true,
|
|
131
|
+
closeOnOutsideClick: false,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
render(
|
|
135
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
136
|
+
<FloatingPanel {...defaultProps} />
|
|
137
|
+
</ThemeProvider>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const floatingPanelWrapper = screen.getByTestId("floating-panel");
|
|
141
|
+
expect(floatingPanelWrapper).toBeTruthy();
|
|
142
|
+
const iconAction = screen.getByTestId("icon-action-component");
|
|
143
|
+
expect(iconAction).toBeTruthy();
|
|
144
|
+
|
|
145
|
+
fireEvent.mouseDown(document);
|
|
146
|
+
expect(toggleModalMock).not.toBeCalled();
|
|
147
|
+
expect(handlePanelMock).not.toBeCalled();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { mock } from "jest-mock-extended";
|
|
5
|
+
import { render, cleanup, screen } from "@testing-library/react";
|
|
6
|
+
import { parseTheme } from "@ax/helpers";
|
|
7
|
+
import "@testing-library/jest-dom";
|
|
8
|
+
|
|
9
|
+
import GuardModal, { IGuardModalProps } from "@ax/components/GuardModal";
|
|
10
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
11
|
+
|
|
12
|
+
afterEach(cleanup);
|
|
13
|
+
|
|
14
|
+
const defaultProps = mock<IGuardModalProps>();
|
|
15
|
+
|
|
16
|
+
describe("GuardModal component rendering", () => {
|
|
17
|
+
it("should render the component", () => {
|
|
18
|
+
defaultProps.isOpen = true;
|
|
19
|
+
|
|
20
|
+
render(
|
|
21
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
22
|
+
<GuardModal {...defaultProps} />
|
|
23
|
+
</ThemeProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const guardModal = screen.getByTestId("modal-wrapper");
|
|
27
|
+
expect(guardModal).toBeTruthy();
|
|
28
|
+
const guardModalContent = screen.getByTestId("guard-modal-content");
|
|
29
|
+
expect(guardModalContent).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, cleanup } from "@testing-library/react";
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import "@testing-library/jest-dom";
|
|
7
|
+
|
|
8
|
+
import Icon, { IStateProps } from "@ax/components/Icon";
|
|
9
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
describe("Icon component rendering", () => {
|
|
14
|
+
it("should render the component", () => {
|
|
15
|
+
const defaultProps: IStateProps = {
|
|
16
|
+
name: "delete",
|
|
17
|
+
size: "24",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
22
|
+
<Icon {...defaultProps} />
|
|
23
|
+
</ThemeProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const svgIcon = container.querySelector("svg");
|
|
27
|
+
expect(svgIcon).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should render the component with no size", () => {
|
|
31
|
+
const defaultProps: IStateProps = {
|
|
32
|
+
name: "delete",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const { container } = render(
|
|
36
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
37
|
+
<Icon {...defaultProps} />
|
|
38
|
+
</ThemeProvider>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const svgIcon = container.querySelector("svg");
|
|
42
|
+
expect(svgIcon).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should render the component with fill", () => {
|
|
46
|
+
const defaultProps: IStateProps = {
|
|
47
|
+
name: "delete",
|
|
48
|
+
fill: "#FFFFFF",
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const { container } = render(
|
|
52
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
53
|
+
<Icon {...defaultProps} />
|
|
54
|
+
</ThemeProvider>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const svgIcon = container.querySelector("svg");
|
|
58
|
+
expect(svgIcon).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should not render the component if no svg", () => {
|
|
62
|
+
const defaultProps: IStateProps = {
|
|
63
|
+
name: "no-icon",
|
|
64
|
+
size: "24",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const { container } = render(
|
|
68
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
69
|
+
<Icon {...defaultProps} />
|
|
70
|
+
</ThemeProvider>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const svgIcon = container.querySelector("svg");
|
|
74
|
+
expect(svgIcon).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, cleanup, screen, fireEvent } from "@testing-library/react";
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import "@testing-library/jest-dom";
|
|
7
|
+
|
|
8
|
+
import IconAction, { IIconActionProps } from "@ax/components/IconAction";
|
|
9
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
describe("IconAction component rendering", () => {
|
|
14
|
+
it("should render the component", () => {
|
|
15
|
+
const defaultProps: IIconActionProps = {
|
|
16
|
+
icon: "delete",
|
|
17
|
+
size: "m",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
render(
|
|
21
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
22
|
+
<IconAction {...defaultProps} />
|
|
23
|
+
</ThemeProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const button = screen.getByTestId("icon-action-component");
|
|
27
|
+
expect(button).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should render the component inversed", () => {
|
|
31
|
+
const defaultProps: IIconActionProps = {
|
|
32
|
+
icon: "delete",
|
|
33
|
+
size: "m",
|
|
34
|
+
inversed: true,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
render(
|
|
38
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
39
|
+
<IconAction {...defaultProps} />
|
|
40
|
+
</ThemeProvider>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const button = screen.getByTestId("icon-action-component");
|
|
44
|
+
expect(button).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("onClick events", () => {
|
|
49
|
+
test("onClick been called if enabled", () => {
|
|
50
|
+
const onClickMock = jest.fn();
|
|
51
|
+
const defaultProps: IIconActionProps = {
|
|
52
|
+
icon: "delete",
|
|
53
|
+
size: "m",
|
|
54
|
+
onClick: onClickMock,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
render(
|
|
58
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
59
|
+
<IconAction {...defaultProps} />
|
|
60
|
+
</ThemeProvider>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const button = screen.getByTestId("icon-action-component");
|
|
64
|
+
expect(button).toBeTruthy();
|
|
65
|
+
|
|
66
|
+
fireEvent.click(button);
|
|
67
|
+
expect(onClickMock).toBeCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("onClick not to be called if disabled", () => {
|
|
71
|
+
const onClickMock = jest.fn();
|
|
72
|
+
const defaultProps: IIconActionProps = {
|
|
73
|
+
icon: "delete",
|
|
74
|
+
size: "m",
|
|
75
|
+
onClick: onClickMock,
|
|
76
|
+
disabled: true,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
render(
|
|
80
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
81
|
+
<IconAction {...defaultProps} />
|
|
82
|
+
</ThemeProvider>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const button = screen.getByTestId("icon-action-component");
|
|
86
|
+
expect(button).toBeTruthy();
|
|
87
|
+
|
|
88
|
+
fireEvent.click(button);
|
|
89
|
+
expect(onClickMock).toBeCalledTimes(0);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, cleanup, screen, fireEvent } from "@testing-library/react";
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import "@testing-library/jest-dom";
|
|
7
|
+
|
|
8
|
+
import Notification, { INotificationProps } from "@ax/components/Notification";
|
|
9
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
describe("Notification component rendering", () => {
|
|
14
|
+
it("should render the success notification", () => {
|
|
15
|
+
const defaultProps: INotificationProps = {
|
|
16
|
+
text: "Notification text",
|
|
17
|
+
type: "success",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
render(
|
|
21
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
22
|
+
<Notification {...defaultProps} />
|
|
23
|
+
</ThemeProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const notificationWrapper = screen.getByTestId("notification-wrapper");
|
|
27
|
+
const successIcon = screen.getByTestId("success-icon");
|
|
28
|
+
expect(notificationWrapper).toBeTruthy();
|
|
29
|
+
expect(successIcon).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should render the error notification", () => {
|
|
33
|
+
const defaultProps: INotificationProps = {
|
|
34
|
+
text: "Notification text",
|
|
35
|
+
type: "error",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
render(
|
|
39
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
40
|
+
<Notification {...defaultProps} />
|
|
41
|
+
</ThemeProvider>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const notificationWrapper = screen.getByTestId("notification-wrapper");
|
|
45
|
+
const alertIcon = screen.getByTestId("alert-icon");
|
|
46
|
+
expect(notificationWrapper).toBeTruthy();
|
|
47
|
+
expect(alertIcon).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should render the warning notification", () => {
|
|
51
|
+
const defaultProps: INotificationProps = {
|
|
52
|
+
text: "Notification text",
|
|
53
|
+
type: "warning",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
render(
|
|
57
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
58
|
+
<Notification {...defaultProps} />
|
|
59
|
+
</ThemeProvider>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const notificationWrapper = screen.getByTestId("notification-wrapper");
|
|
63
|
+
const warningIcon = screen.getByTestId("warning-icon");
|
|
64
|
+
expect(notificationWrapper).toBeTruthy();
|
|
65
|
+
expect(warningIcon).toBeTruthy();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should render the close button", () => {
|
|
69
|
+
const defaultProps: INotificationProps = {
|
|
70
|
+
text: "Notification text",
|
|
71
|
+
type: "success",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
render(
|
|
75
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
76
|
+
<Notification {...defaultProps} />
|
|
77
|
+
</ThemeProvider>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const closeButton = screen.getByTestId("close-button");
|
|
81
|
+
expect(closeButton).toBeTruthy();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should not render the close button", () => {
|
|
85
|
+
const defaultProps: INotificationProps = {
|
|
86
|
+
text: "Notification text",
|
|
87
|
+
type: "success",
|
|
88
|
+
closeButton: false,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
render(
|
|
92
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
93
|
+
<Notification {...defaultProps} />
|
|
94
|
+
</ThemeProvider>
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const closeButton = screen.queryByTestId("close-button");
|
|
98
|
+
expect(closeButton).toBeFalsy();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should render the action button with no actionsBelow", () => {
|
|
102
|
+
const defaultProps: INotificationProps = {
|
|
103
|
+
text: "Notification text",
|
|
104
|
+
type: "success",
|
|
105
|
+
btnText: "Action",
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
render(
|
|
109
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
110
|
+
<Notification {...defaultProps} />
|
|
111
|
+
</ThemeProvider>
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const actionButton = screen.getByTestId("action-button");
|
|
115
|
+
expect(actionButton).toBeTruthy();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("should render the action button with actionsBelow", () => {
|
|
119
|
+
const defaultProps: INotificationProps = {
|
|
120
|
+
text: "Notification text",
|
|
121
|
+
type: "success",
|
|
122
|
+
btnText: "Action",
|
|
123
|
+
actionsBelow: true,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
render(
|
|
127
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
128
|
+
<Notification {...defaultProps} />
|
|
129
|
+
</ThemeProvider>
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const actionButton = screen.getByTestId("action-button");
|
|
133
|
+
expect(actionButton).toBeTruthy();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("Notification component with subnotifications", () => {
|
|
138
|
+
it("should render the subnotifications open button", () => {
|
|
139
|
+
const defaultProps: INotificationProps = {
|
|
140
|
+
text: "Notification text",
|
|
141
|
+
type: "error",
|
|
142
|
+
subErrors: [
|
|
143
|
+
{ id: 1, error: "SubError 1" },
|
|
144
|
+
{ id: 2, error: "SubError 2" },
|
|
145
|
+
{ id: 3, error: "Suberror 3" },
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
render(
|
|
150
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
151
|
+
<Notification {...defaultProps} />
|
|
152
|
+
</ThemeProvider>
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const suberrorsButton = screen.getByTestId("suberrors-button");
|
|
156
|
+
expect(suberrorsButton).toBeTruthy();
|
|
157
|
+
fireEvent.click(suberrorsButton);
|
|
158
|
+
const subnotifications = screen.getAllByTestId("subnotification-wrapper");
|
|
159
|
+
expect(subnotifications).toHaveLength(3);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("Notification component events", () => {
|
|
164
|
+
it("should call onClick on action button click", () => {
|
|
165
|
+
const onClickMock = jest.fn();
|
|
166
|
+
const defaultProps: INotificationProps = {
|
|
167
|
+
text: "Notification text",
|
|
168
|
+
type: "success",
|
|
169
|
+
btnText: "Action",
|
|
170
|
+
onClick: onClickMock,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
render(
|
|
174
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
175
|
+
<Notification {...defaultProps} />
|
|
176
|
+
</ThemeProvider>
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const actionButton = screen.getByTestId("action-button");
|
|
180
|
+
expect(actionButton).toBeTruthy();
|
|
181
|
+
fireEvent.click(actionButton);
|
|
182
|
+
expect(onClickMock).toBeCalledTimes(1);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("should call resetError on close and hide notification", () => {
|
|
186
|
+
const resetErrorMock = jest.fn();
|
|
187
|
+
const defaultProps: INotificationProps = {
|
|
188
|
+
text: "Notification text",
|
|
189
|
+
type: "success",
|
|
190
|
+
resetError: resetErrorMock,
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
render(
|
|
194
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
195
|
+
<Notification {...defaultProps} />
|
|
196
|
+
</ThemeProvider>
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const closeButton = screen.getByTestId("close-button");
|
|
200
|
+
expect(closeButton).toBeTruthy();
|
|
201
|
+
fireEvent.click(closeButton);
|
|
202
|
+
expect(resetErrorMock).toBeCalledTimes(1);
|
|
203
|
+
const notificationWrapper = screen.getByTestId("notification-wrapper");
|
|
204
|
+
expect(notificationWrapper).not.toBeVisible();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, cleanup, screen, fireEvent } from "@testing-library/react";
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import "@testing-library/jest-dom";
|
|
7
|
+
|
|
8
|
+
import SubNotification, { ISubNotificationProps } from "@ax/components/Notification/SubNotification";
|
|
9
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
describe("SubNotification component rendering", () => {
|
|
14
|
+
it("should render the subnotification", () => {
|
|
15
|
+
const defaultProps: ISubNotificationProps = {
|
|
16
|
+
text: "SubNotification text",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
render(
|
|
20
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
21
|
+
<SubNotification {...defaultProps} />
|
|
22
|
+
</ThemeProvider>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const subnotificationWrapper = screen.getByTestId("subnotification-wrapper");
|
|
26
|
+
expect(subnotificationWrapper).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should close the subnotification", () => {
|
|
30
|
+
const defaultProps: ISubNotificationProps = {
|
|
31
|
+
text: "SubNotification text",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
render(
|
|
35
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
36
|
+
<SubNotification {...defaultProps} />
|
|
37
|
+
</ThemeProvider>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const subnotificationButton = screen.getByTestId("subnotification-close-button");
|
|
41
|
+
expect(subnotificationButton).toBeTruthy();
|
|
42
|
+
fireEvent.click(subnotificationButton);
|
|
43
|
+
const subnotificationWrapper = screen.queryByTestId("subnotification-wrapper");
|
|
44
|
+
expect(subnotificationWrapper).not.toBeVisible();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { mock } from "jest-mock-extended";
|
|
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 ReorderArrows, { IReorderArrows } from "@ax/components/ReorderArrows";
|
|
10
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
11
|
+
|
|
12
|
+
afterEach(cleanup);
|
|
13
|
+
|
|
14
|
+
const defaultProps = mock<IReorderArrows>();
|
|
15
|
+
|
|
16
|
+
describe("ReorderArrows component rendering", () => {
|
|
17
|
+
it("should render the component if is first", () => {
|
|
18
|
+
defaultProps.index = 0;
|
|
19
|
+
defaultProps.listLength = 10;
|
|
20
|
+
render(
|
|
21
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
22
|
+
<ReorderArrows {...defaultProps} />
|
|
23
|
+
</ThemeProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const reorderWrapper = screen.getByTestId("reorder-first");
|
|
27
|
+
expect(reorderWrapper).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should render the component if is last", () => {
|
|
31
|
+
defaultProps.index = 9;
|
|
32
|
+
defaultProps.listLength = 10;
|
|
33
|
+
render(
|
|
34
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
35
|
+
<ReorderArrows {...defaultProps} />
|
|
36
|
+
</ThemeProvider>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const reorderWrapper = screen.getByTestId("reorder-last");
|
|
40
|
+
expect(reorderWrapper).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("shouldn't render the component", () => {
|
|
44
|
+
defaultProps.index = 9;
|
|
45
|
+
defaultProps.listLength = 0;
|
|
46
|
+
render(
|
|
47
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
48
|
+
<ReorderArrows {...defaultProps} />
|
|
49
|
+
</ThemeProvider>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const reorderWrapperLast = screen.queryByTestId("reorder-last");
|
|
53
|
+
const reorderWrapperFirst = screen.queryByTestId("reorder-first");
|
|
54
|
+
expect(reorderWrapperLast).not.toBeTruthy();
|
|
55
|
+
expect(reorderWrapperFirst).not.toBeTruthy();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("ReorderArrows component events trigger", () => {
|
|
60
|
+
it("should trigger the handleDownClick", () => {
|
|
61
|
+
const handleDownClickMock = defaultProps.handleDownClick as jest.MockedFunction<(value: any) => void>;
|
|
62
|
+
defaultProps.index = 0;
|
|
63
|
+
defaultProps.listLength = 10;
|
|
64
|
+
|
|
65
|
+
render(
|
|
66
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
67
|
+
<ReorderArrows {...defaultProps} />
|
|
68
|
+
</ThemeProvider>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const reorderWrapper = screen.getByTestId("reorder-first");
|
|
72
|
+
expect(reorderWrapper).toBeTruthy();
|
|
73
|
+
const reorderIcon = screen.getByTestId("icon-action-component");
|
|
74
|
+
expect(reorderIcon).toBeTruthy();
|
|
75
|
+
fireEvent.click(reorderIcon);
|
|
76
|
+
expect(handleDownClickMock).toBeCalled();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should trigger the handleUpClick", () => {
|
|
80
|
+
const handleUpClickMock = defaultProps.handleUpClick as jest.MockedFunction<(value: any) => void>;
|
|
81
|
+
defaultProps.index = 9;
|
|
82
|
+
defaultProps.listLength = 10;
|
|
83
|
+
render(
|
|
84
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
85
|
+
<ReorderArrows {...defaultProps} />
|
|
86
|
+
</ThemeProvider>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const reorderWrapper = screen.getByTestId("reorder-last");
|
|
90
|
+
expect(reorderWrapper).toBeTruthy();
|
|
91
|
+
const reorderIcon = screen.getByTestId("icon-action-component");
|
|
92
|
+
expect(reorderIcon).toBeTruthy();
|
|
93
|
+
fireEvent.click(reorderIcon);
|
|
94
|
+
expect(handleUpClickMock).toBeCalled();
|
|
95
|
+
});
|
|
96
|
+
});
|