@griddo/ax 1.73.28 → 1.74.0
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/griddo-config/index.js +24 -3
- package/config/webpackSchemas.config.js +3 -5
- package/package.json +3 -2
- package/scripts/griddo-sync-schemas.js +4 -3
- package/src/__mocks__/axios/SitesList.ts +84 -0
- package/src/__mocks__/store/SitesList.ts +714 -0
- package/src/__tests__/components/Avatar/Avatar.test.tsx +119 -0
- package/src/__tests__/components/Avatar/__snapshots__/Avatar.test.tsx.snap +61 -0
- package/src/__tests__/components/Fields/ReferenceField/ReferenceField.test.tsx +10 -10
- package/src/__tests__/components/LanguageMenu/LanguageMenu.test.tsx +221 -0
- package/src/__tests__/components/Loading/Loading.test.tsx +23 -0
- package/src/__tests__/components/Login/Login.test.tsx +247 -0
- package/src/__tests__/components/Login/RecoveryModal/RecoveryModal.test.tsx +185 -0
- package/src/__tests__/components/TableFilters/LiveFilter/LiveFilter.test.tsx +6 -6
- package/src/__tests__/modules/Sites/Sites.test.tsx +259 -0
- package/src/__tests__/modules/Sites/SitesList/ListView/BulkHeader/BulkHeader.test.tsx +51 -0
- package/src/__tests__/modules/Sites/SitesList/SitesList.test.tsx +896 -0
- package/src/api/sites.tsx +43 -4
- package/src/components/ActionMenu/index.tsx +1 -1
- package/src/components/Avatar/index.tsx +4 -4
- package/src/components/Browser/index.tsx +27 -20
- package/src/components/BrowserContent/index.tsx +6 -0
- package/src/components/Fields/AsyncSelect/style.tsx +6 -3
- package/src/components/Fields/CheckField/index.tsx +1 -0
- package/src/components/Fields/DateField/style.tsx +3 -1
- package/src/components/Fields/HeadingField/index.tsx +14 -5
- package/src/components/Fields/ImageField/index.tsx +3 -0
- package/src/components/Fields/ImageField/style.tsx +2 -2
- package/src/components/Fields/Select/style.tsx +2 -0
- package/src/components/Fields/SliderField/index.tsx +2 -1
- package/src/components/Fields/TextField/index.tsx +1 -0
- package/src/components/Icon/components/BulletList.js +16 -0
- package/src/components/Icon/components/Grid2.js +16 -0
- package/src/components/Icon/svgs/Bullet-list.svg +3 -0
- package/src/components/Icon/svgs/Grid-2.svg +3 -0
- package/src/components/IconAction/index.tsx +4 -2
- package/src/components/IconAction/style.tsx +8 -2
- package/src/components/LanguageMenu/index.tsx +13 -6
- package/src/components/Login/RecoveryModal/index.tsx +5 -4
- package/src/components/Login/index.tsx +13 -3
- package/src/components/Login/style.tsx +12 -25
- package/src/components/Pagination/style.tsx +1 -1
- package/src/components/SearchField/index.tsx +9 -1
- package/src/components/SideModal/style.tsx +8 -8
- package/src/components/TableFilters/LastAccessFilter/index.tsx +52 -0
- package/src/components/TableFilters/LastAccessFilter/style.tsx +31 -0
- package/src/components/TableFilters/LiveFilter/index.tsx +7 -5
- package/src/components/TableFilters/NameFilter/index.tsx +4 -3
- package/src/components/TableFilters/index.tsx +2 -0
- package/src/components/TableList/index.tsx +2 -1
- package/src/components/TableList/style.tsx +2 -2
- package/src/components/index.tsx +2 -0
- package/src/containers/App/actions.tsx +5 -0
- package/src/containers/App/interfaces.tsx +1 -1
- package/src/containers/App/reducer.tsx +1 -1
- package/src/containers/Navigation/Defaults/actions.tsx +3 -1
- package/src/containers/PageEditor/actions.tsx +6 -3
- package/src/containers/Sites/actions.tsx +76 -11
- package/src/containers/Sites/constants.tsx +2 -0
- package/src/containers/Sites/interfaces.tsx +12 -0
- package/src/containers/Sites/reducer.tsx +8 -0
- package/src/helpers/schemas.tsx +27 -1
- package/src/hooks/iframe.ts +56 -0
- package/src/hooks/index.tsx +3 -0
- package/src/modules/Content/index.tsx +4 -3
- package/src/modules/FramePreview/index.tsx +25 -39
- package/src/modules/GlobalEditor/Editor/index.tsx +2 -2
- package/src/modules/GlobalEditor/PageBrowser/index.tsx +16 -4
- package/src/modules/Navigation/Defaults/DefaultsEditor/Editor/DefaultsBrowser/index.tsx +11 -7
- package/src/modules/Navigation/Defaults/DefaultsEditor/Editor/index.tsx +4 -3
- package/src/modules/Navigation/Menus/List/Table/SidePanel/Form/index.tsx +1 -0
- package/src/modules/PageEditor/Editor/index.tsx +2 -2
- package/src/modules/PageEditor/PageBrowser/index.tsx +16 -4
- package/src/modules/PageEditor/index.tsx +8 -7
- package/src/modules/Settings/ContentTypes/DataPacks/Config/Form/TemplateConfig/TemplateEditor/Editor/ConfigPanel/Field/index.tsx +12 -11
- package/src/modules/Settings/ContentTypes/DataPacks/Config/Form/TemplateConfig/TemplateEditor/index.tsx +3 -17
- package/src/modules/Settings/ContentTypes/DataPacks/Config/Form/style.tsx +2 -10
- package/src/modules/Sites/SitesList/GridView/GridHeaderFilter/index.tsx +72 -0
- package/src/modules/Sites/SitesList/GridView/GridHeaderFilter/style.tsx +32 -0
- package/src/modules/Sites/SitesList/{SiteItem → GridView/GridSiteItem}/index.tsx +17 -27
- package/src/modules/Sites/SitesList/{SiteItem → GridView/GridSiteItem}/style.tsx +14 -25
- package/src/modules/Sites/SitesList/ListView/BulkHeader/TableHeader/index.tsx +64 -0
- package/src/modules/Sites/SitesList/ListView/BulkHeader/TableHeader/style.tsx +50 -0
- package/src/modules/Sites/SitesList/ListView/BulkHeader/index.tsx +75 -0
- package/src/modules/Sites/SitesList/ListView/BulkHeader/style.tsx +8 -0
- package/src/modules/Sites/SitesList/ListView/ListSiteItem/index.tsx +200 -0
- package/src/modules/Sites/SitesList/ListView/ListSiteItem/style.tsx +112 -0
- package/src/modules/Sites/SitesList/RecentSiteItem/index.tsx +50 -0
- package/src/modules/Sites/SitesList/RecentSiteItem/style.tsx +28 -0
- package/src/modules/Sites/SitesList/SiteModal/index.tsx +4 -3
- package/src/modules/Sites/SitesList/atoms.tsx +47 -0
- package/src/modules/Sites/SitesList/hooks.tsx +102 -0
- package/src/modules/Sites/SitesList/index.tsx +272 -19
- package/src/modules/Sites/SitesList/style.tsx +157 -4
- package/src/modules/Sites/SitesList/utils.tsx +33 -0
- package/src/modules/Sites/index.tsx +6 -11
- package/src/modules/StructuredData/StructuredDataList/BulkHeader/TableHeader/index.tsx +1 -1
- package/src/types/index.tsx +25 -2
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Axios from "axios";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, cleanup, screen, fireEvent, waitFor, act } from "@testing-library/react";
|
|
5
|
+
import "@testing-library/jest-dom";
|
|
6
|
+
|
|
7
|
+
import { parseTheme } from "@ax/helpers";
|
|
8
|
+
import RecoveryModal, { IRecoveryProps } from "@ax/components/Login/RecoveryModal";
|
|
9
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
jest.mock("axios"); // This overwrites axios methods with jest Mock
|
|
14
|
+
const mockedAxios = Axios as jest.MockedFunction<typeof Axios>;
|
|
15
|
+
|
|
16
|
+
describe("Recovery modal component rendering", () => {
|
|
17
|
+
it("should render the component if closed", () => {
|
|
18
|
+
const defaultProps: IRecoveryProps = {
|
|
19
|
+
isOpen: true,
|
|
20
|
+
toggleModal: jest.fn(),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
render(
|
|
24
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
25
|
+
<RecoveryModal {...defaultProps} />
|
|
26
|
+
</ThemeProvider>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const modalContent = screen.getByTestId("recovery-modal-content");
|
|
30
|
+
expect(modalContent).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should not render the component content if closed", () => {
|
|
34
|
+
const defaultProps: IRecoveryProps = {
|
|
35
|
+
isOpen: false,
|
|
36
|
+
toggleModal: jest.fn(),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
render(
|
|
40
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
41
|
+
<RecoveryModal {...defaultProps} />
|
|
42
|
+
</ThemeProvider>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const modalContent = screen.queryByTestId("recovery-modal-content");
|
|
46
|
+
expect(modalContent).toBeFalsy();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("Login component events", () => {
|
|
51
|
+
it("should call toggleModal on cancel button click", () => {
|
|
52
|
+
const toggleModalMock = jest.fn();
|
|
53
|
+
const defaultProps: IRecoveryProps = {
|
|
54
|
+
isOpen: true,
|
|
55
|
+
toggleModal: toggleModalMock,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
render(
|
|
59
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
60
|
+
<RecoveryModal {...defaultProps} />
|
|
61
|
+
</ThemeProvider>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const button = screen.getByText("Cancel");
|
|
65
|
+
expect(button).toBeTruthy();
|
|
66
|
+
fireEvent.click(button);
|
|
67
|
+
|
|
68
|
+
expect(toggleModalMock).toBeCalledTimes(1);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should disable button if email is not valid", () => {
|
|
72
|
+
const toggleModalMock = jest.fn();
|
|
73
|
+
const defaultProps: IRecoveryProps = {
|
|
74
|
+
isOpen: true,
|
|
75
|
+
toggleModal: toggleModalMock,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
render(
|
|
79
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
80
|
+
<RecoveryModal {...defaultProps} />
|
|
81
|
+
</ThemeProvider>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const input = screen.getByLabelText("email");
|
|
85
|
+
expect(input).toBeTruthy();
|
|
86
|
+
fireEvent.change(input, { target: { value: "asdfasfsdf" } });
|
|
87
|
+
|
|
88
|
+
const button = screen.getByText("Reset Password").closest("button");
|
|
89
|
+
expect(button).toBeTruthy();
|
|
90
|
+
expect(button).toBeDisabled();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should enable button if email is valid", async () => {
|
|
94
|
+
const toggleModalMock = jest.fn();
|
|
95
|
+
const defaultProps: IRecoveryProps = {
|
|
96
|
+
isOpen: true,
|
|
97
|
+
toggleModal: toggleModalMock,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
render(
|
|
101
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
102
|
+
<RecoveryModal {...defaultProps} />
|
|
103
|
+
</ThemeProvider>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const input = screen.getByLabelText("email");
|
|
107
|
+
expect(input).toBeTruthy();
|
|
108
|
+
fireEvent.change(input, { target: { value: "prueba@email.com" } });
|
|
109
|
+
|
|
110
|
+
const button = screen.getByText("Reset Password").closest("button");
|
|
111
|
+
|
|
112
|
+
await waitFor(() => expect(button).not.toBeDisabled(), {
|
|
113
|
+
timeout: 5000,
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should hide input if api response is ok", async () => {
|
|
118
|
+
const defaultProps: IRecoveryProps = {
|
|
119
|
+
isOpen: true,
|
|
120
|
+
toggleModal: jest.fn(),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const data = { data: [], status: 200, statusText: "Ok", headers: {}, config: {} };
|
|
124
|
+
mockedAxios.mockResolvedValue(data);
|
|
125
|
+
|
|
126
|
+
const Component = (
|
|
127
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
128
|
+
<RecoveryModal {...defaultProps} />
|
|
129
|
+
</ThemeProvider>
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const { rerender } = render(Component);
|
|
133
|
+
|
|
134
|
+
const input = screen.getByLabelText("email");
|
|
135
|
+
expect(input).toBeTruthy();
|
|
136
|
+
fireEvent.change(input, { target: { value: "prueba@email.com" } });
|
|
137
|
+
const button = screen.getByTestId("button-default");
|
|
138
|
+
|
|
139
|
+
await waitFor(() => expect(screen.getByTestId("button-default")).not.toBeDisabled(), {
|
|
140
|
+
timeout: 5000,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
button.click();
|
|
144
|
+
|
|
145
|
+
await act(async () => rerender(Component));
|
|
146
|
+
|
|
147
|
+
expect(screen.queryByLabelText("email")).toBeFalsy();
|
|
148
|
+
|
|
149
|
+
const button2 = screen.getByText("Got it!").closest("button");
|
|
150
|
+
expect(button2).toBeTruthy();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("should show error if api response is not ok", async () => {
|
|
154
|
+
const defaultProps: IRecoveryProps = {
|
|
155
|
+
isOpen: true,
|
|
156
|
+
toggleModal: jest.fn(),
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const data = { data: [], status: 400, statusText: "error", headers: {}, config: {} };
|
|
160
|
+
mockedAxios.mockResolvedValue(data);
|
|
161
|
+
|
|
162
|
+
const Component = (
|
|
163
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
164
|
+
<RecoveryModal {...defaultProps} />
|
|
165
|
+
</ThemeProvider>
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const { rerender } = render(Component);
|
|
169
|
+
|
|
170
|
+
const input = screen.getByLabelText("email");
|
|
171
|
+
expect(input).toBeTruthy();
|
|
172
|
+
fireEvent.change(input, { target: { value: "prueba@email.com" } });
|
|
173
|
+
const button = screen.getByTestId("button-default");
|
|
174
|
+
|
|
175
|
+
await waitFor(() => expect(screen.getByTestId("button-default")).not.toBeDisabled(), {
|
|
176
|
+
timeout: 5000,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
button.click();
|
|
180
|
+
|
|
181
|
+
await act(async () => rerender(Component));
|
|
182
|
+
|
|
183
|
+
expect(screen.getByText("Sorry, this email doesn't exist.")).toBeTruthy();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -16,7 +16,7 @@ const defaultProps = mock<ILiveFilterProps>();
|
|
|
16
16
|
|
|
17
17
|
describe("LiveFilter component rendering", () => {
|
|
18
18
|
it("should render live filter", async () => {
|
|
19
|
-
defaultProps.
|
|
19
|
+
defaultProps.hasBasicStatus = false;
|
|
20
20
|
defaultProps.value = "all";
|
|
21
21
|
const filterItems = jest.fn() as CalledWithMock<void, [pointer: string, filter: string]>;
|
|
22
22
|
|
|
@@ -52,7 +52,7 @@ describe("LiveFilter component rendering", () => {
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
it("should render the component with no options", async () => {
|
|
55
|
-
defaultProps.
|
|
55
|
+
defaultProps.hasBasicStatus = false;
|
|
56
56
|
defaultProps.value = "all";
|
|
57
57
|
const filterItems = jest.fn() as CalledWithMock<void, [pointer: string, filter: string]>;
|
|
58
58
|
|
|
@@ -90,7 +90,7 @@ describe("LiveFilter component rendering", () => {
|
|
|
90
90
|
|
|
91
91
|
describe("LiveFilter events", () => {
|
|
92
92
|
it("should render check group on click", async () => {
|
|
93
|
-
defaultProps.
|
|
93
|
+
defaultProps.hasBasicStatus = false;
|
|
94
94
|
defaultProps.value = "all";
|
|
95
95
|
const filterItemsMock = jest.fn() as CalledWithMock<void, [pointer: string, filter: string]>;
|
|
96
96
|
|
|
@@ -131,7 +131,7 @@ describe("LiveFilter events", () => {
|
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
it("should check option on click", async () => {
|
|
134
|
-
defaultProps.
|
|
134
|
+
defaultProps.hasBasicStatus = false;
|
|
135
135
|
defaultProps.value = "all";
|
|
136
136
|
const filterItemsMock = jest.fn() as CalledWithMock<void, [pointer: string, filter: string]>;
|
|
137
137
|
|
|
@@ -175,7 +175,7 @@ describe("LiveFilter events", () => {
|
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
it("should uncheck selected option on click and select 'All' option", async () => {
|
|
178
|
-
defaultProps.
|
|
178
|
+
defaultProps.hasBasicStatus = false;
|
|
179
179
|
defaultProps.value = "all";
|
|
180
180
|
const filterItemsMock = jest.fn() as CalledWithMock<void, [pointer: string, filter: string]>;
|
|
181
181
|
|
|
@@ -224,7 +224,7 @@ describe("LiveFilter events", () => {
|
|
|
224
224
|
});
|
|
225
225
|
|
|
226
226
|
it("should call filterItems action on change", async () => {
|
|
227
|
-
defaultProps.
|
|
227
|
+
defaultProps.hasBasicStatus = false;
|
|
228
228
|
defaultProps.value = "all";
|
|
229
229
|
const filterItemsMock = jest.fn() as CalledWithMock<void, [pointer: string, filter: string]>;
|
|
230
230
|
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
|
|
4
|
+
import { ThemeProvider } from "styled-components";
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import { mock } from "jest-mock-extended";
|
|
7
|
+
import configureStore from "redux-mock-store";
|
|
8
|
+
import thunk from "redux-thunk";
|
|
9
|
+
import { Router } from "react-router-dom";
|
|
10
|
+
|
|
11
|
+
import { history } from "@ax/routes";
|
|
12
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
13
|
+
import { render, cleanup, screen, act } from "../../../../config/jest/test-utils";
|
|
14
|
+
import Sites, { ISitesProps } from "./../../../modules/Sites";
|
|
15
|
+
import { sitesDataMock, userDataMock } from "./../../../__mocks__/store/SitesList";
|
|
16
|
+
import { sitesResponse, structuredDataResponse } from "./../../../__mocks__/axios/SitesList";
|
|
17
|
+
|
|
18
|
+
afterEach(cleanup);
|
|
19
|
+
jest.mock("axios");
|
|
20
|
+
const mockedAxios = axios as jest.MockedFunction<typeof axios>;
|
|
21
|
+
|
|
22
|
+
const defaultProps = mock<ISitesProps>();
|
|
23
|
+
describe("Sites module rendering", () => {
|
|
24
|
+
it("should render loading component when is loading", async () => {
|
|
25
|
+
mockedAxios.mockResolvedValue(sitesResponse);
|
|
26
|
+
mockedAxios.mockResolvedValue(structuredDataResponse);
|
|
27
|
+
|
|
28
|
+
const initialStore = {
|
|
29
|
+
app: {
|
|
30
|
+
isLoading: true,
|
|
31
|
+
globalLangs: [
|
|
32
|
+
{ id: 4, locale: "en_GB", language: "English", label: "EN", isDefault: true },
|
|
33
|
+
{ id: 2, locale: "es_ES", language: "Spanish", label: "ES", isDefault: false },
|
|
34
|
+
],
|
|
35
|
+
token: "eyJhbGciOiJIUzI",
|
|
36
|
+
},
|
|
37
|
+
users: userDataMock,
|
|
38
|
+
sites: {
|
|
39
|
+
totalItems: 0,
|
|
40
|
+
sites: [],
|
|
41
|
+
recentSites: [],
|
|
42
|
+
},
|
|
43
|
+
structuredData: { global: [], sites: [] },
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const middlewares: any = [thunk];
|
|
47
|
+
const mockStore = configureStore(middlewares);
|
|
48
|
+
const store = mockStore(initialStore);
|
|
49
|
+
|
|
50
|
+
const initialState = { ...initialStore, ...defaultProps };
|
|
51
|
+
|
|
52
|
+
const Component = (
|
|
53
|
+
<Router history={history}>
|
|
54
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
55
|
+
<Sites {...initialState} />
|
|
56
|
+
</ThemeProvider>
|
|
57
|
+
</Router>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
await act(async () => {
|
|
61
|
+
render(Component, { store });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const loadingComponent = screen.getByTestId("loading-wrapper");
|
|
65
|
+
|
|
66
|
+
expect(loadingComponent).toBeTruthy();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should render recent sites list when there are recent sites", async () => {
|
|
70
|
+
mockedAxios.mockResolvedValue(sitesResponse);
|
|
71
|
+
mockedAxios.mockResolvedValue(structuredDataResponse);
|
|
72
|
+
|
|
73
|
+
const initialStore = {
|
|
74
|
+
app: {
|
|
75
|
+
isLoading: false,
|
|
76
|
+
globalLangs: [
|
|
77
|
+
{ id: 4, locale: "en_GB", language: "English", label: "EN", isDefault: true },
|
|
78
|
+
{ id: 2, locale: "es_ES", language: "Spanish", label: "ES", isDefault: false },
|
|
79
|
+
],
|
|
80
|
+
token: "eyJhbGciOiJIUzI",
|
|
81
|
+
},
|
|
82
|
+
users: userDataMock,
|
|
83
|
+
sites: sitesDataMock,
|
|
84
|
+
structuredData: { global: [], sites: [] },
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const middlewares: any = [thunk];
|
|
88
|
+
const mockStore = configureStore(middlewares);
|
|
89
|
+
const store = mockStore(initialStore);
|
|
90
|
+
|
|
91
|
+
const initialState = { ...initialStore, ...defaultProps };
|
|
92
|
+
|
|
93
|
+
const Component = (
|
|
94
|
+
<Router history={history}>
|
|
95
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
96
|
+
<Sites {...initialState} />
|
|
97
|
+
</ThemeProvider>
|
|
98
|
+
</Router>
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await act(async () => {
|
|
102
|
+
render(Component, { store });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const recentSitesList = screen.getByTestId("recent-sites-list");
|
|
106
|
+
const sectionHeader = screen.getByTestId("recent-sites-header");
|
|
107
|
+
const title = screen.getByTestId("recent-sites-title");
|
|
108
|
+
const recentSitesItemsWrapper = screen.getByTestId("recent-sites-items-wrapper");
|
|
109
|
+
const collapseButton = screen.getByTestId("recent-sites-collapse-button");
|
|
110
|
+
const hideLabel = screen.getByTestId("recent-sites-hide-label");
|
|
111
|
+
|
|
112
|
+
expect(recentSitesList).toBeTruthy();
|
|
113
|
+
expect(sectionHeader).toBeTruthy();
|
|
114
|
+
expect(title).toBeTruthy();
|
|
115
|
+
expect(recentSitesItemsWrapper).toBeTruthy();
|
|
116
|
+
expect(collapseButton).toBeTruthy();
|
|
117
|
+
expect(hideLabel).toBeTruthy();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should render default sites list view", async () => {
|
|
121
|
+
mockedAxios.mockResolvedValue(sitesResponse);
|
|
122
|
+
mockedAxios.mockResolvedValue(structuredDataResponse);
|
|
123
|
+
|
|
124
|
+
const initialStore = {
|
|
125
|
+
app: {
|
|
126
|
+
isLoading: false,
|
|
127
|
+
globalLangs: [
|
|
128
|
+
{ id: 4, locale: "en_GB", language: "English", label: "EN", isDefault: true },
|
|
129
|
+
{ id: 2, locale: "es_ES", language: "Spanish", label: "ES", isDefault: false },
|
|
130
|
+
],
|
|
131
|
+
token: "eyJhbGciOiJIUzI",
|
|
132
|
+
},
|
|
133
|
+
users: userDataMock,
|
|
134
|
+
sites: sitesDataMock,
|
|
135
|
+
structuredData: { global: [], sites: [] },
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const middlewares: any = [thunk];
|
|
139
|
+
const mockStore = configureStore(middlewares);
|
|
140
|
+
const store = mockStore(initialStore);
|
|
141
|
+
|
|
142
|
+
const initialState = { ...initialStore, ...defaultProps };
|
|
143
|
+
|
|
144
|
+
const Component = (
|
|
145
|
+
<Router history={history}>
|
|
146
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
147
|
+
<Sites {...initialState} />
|
|
148
|
+
</ThemeProvider>
|
|
149
|
+
</Router>
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
await act(async () => {
|
|
153
|
+
render(Component, { store });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const sectionHeader = screen.getByTestId("all-sites-header");
|
|
157
|
+
const title = screen.getByTestId("all-sites-title");
|
|
158
|
+
const headerIconsWrapper = screen.getByTestId("all-sites-header-icons");
|
|
159
|
+
const filterSelect = screen.getByTestId("all-sites-grid-filter");
|
|
160
|
+
const filterSelectLabel = screen.getByTestId("all-sites-grid-filter-label");
|
|
161
|
+
const sitesGridList = screen.getByTestId("sites-grid-list");
|
|
162
|
+
|
|
163
|
+
expect(sectionHeader).toBeTruthy();
|
|
164
|
+
expect(title).toBeTruthy();
|
|
165
|
+
expect(headerIconsWrapper).toBeTruthy();
|
|
166
|
+
expect(filterSelect).toBeTruthy();
|
|
167
|
+
expect(filterSelectLabel).toBeTruthy();
|
|
168
|
+
expect(sitesGridList).toBeTruthy();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("should not render recent sites list when recent sites list is empty", async () => {
|
|
172
|
+
mockedAxios.mockResolvedValue(sitesResponse);
|
|
173
|
+
mockedAxios.mockResolvedValue(structuredDataResponse);
|
|
174
|
+
|
|
175
|
+
const initialStore = {
|
|
176
|
+
app: {
|
|
177
|
+
isLoading: false,
|
|
178
|
+
globalLangs: [
|
|
179
|
+
{ id: 4, locale: "en_GB", language: "English", label: "EN", isDefault: true },
|
|
180
|
+
{ id: 2, locale: "es_ES", language: "Spanish", label: "ES", isDefault: false },
|
|
181
|
+
],
|
|
182
|
+
token: "eyJhbGciOiJIUzI",
|
|
183
|
+
},
|
|
184
|
+
users: userDataMock,
|
|
185
|
+
sites: {
|
|
186
|
+
totalItems: 2,
|
|
187
|
+
sites: sitesDataMock.sites,
|
|
188
|
+
recentSites: [],
|
|
189
|
+
},
|
|
190
|
+
structuredData: { global: [], sites: [] },
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const middlewares: any = [thunk];
|
|
194
|
+
const mockStore = configureStore(middlewares);
|
|
195
|
+
const store = mockStore(initialStore);
|
|
196
|
+
|
|
197
|
+
const initialState = { ...initialStore, ...defaultProps };
|
|
198
|
+
|
|
199
|
+
const Component = (
|
|
200
|
+
<Router history={history}>
|
|
201
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
202
|
+
<Sites {...initialState} />
|
|
203
|
+
</ThemeProvider>
|
|
204
|
+
</Router>
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
await act(async () => {
|
|
208
|
+
render(Component, { store });
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const recentSitesList = screen.queryByTestId("recent-sites-list");
|
|
212
|
+
|
|
213
|
+
expect(recentSitesList).not.toBeTruthy();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should render empty state when no sites", async () => {
|
|
217
|
+
mockedAxios.mockResolvedValue(sitesResponse);
|
|
218
|
+
mockedAxios.mockResolvedValue(structuredDataResponse);
|
|
219
|
+
|
|
220
|
+
const initialStore = {
|
|
221
|
+
app: {
|
|
222
|
+
isLoading: false,
|
|
223
|
+
globalLangs: [
|
|
224
|
+
{ id: 4, locale: "en_GB", language: "English", label: "EN", isDefault: true },
|
|
225
|
+
{ id: 2, locale: "es_ES", language: "Spanish", label: "ES", isDefault: false },
|
|
226
|
+
],
|
|
227
|
+
token: "eyJhbGciOiJIUzI",
|
|
228
|
+
},
|
|
229
|
+
users: userDataMock,
|
|
230
|
+
sites: {
|
|
231
|
+
totalItems: 0,
|
|
232
|
+
sites: [],
|
|
233
|
+
recentSites: [],
|
|
234
|
+
},
|
|
235
|
+
structuredData: { global: [], sites: [] },
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const middlewares: any = [thunk];
|
|
239
|
+
const mockStore = configureStore(middlewares);
|
|
240
|
+
const store = mockStore(initialStore);
|
|
241
|
+
|
|
242
|
+
const initialState = { ...initialStore, ...defaultProps };
|
|
243
|
+
|
|
244
|
+
const Component = (
|
|
245
|
+
<Router history={history}>
|
|
246
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
247
|
+
<Sites {...initialState} />
|
|
248
|
+
</ThemeProvider>
|
|
249
|
+
</Router>
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
await act(async () => {
|
|
253
|
+
render(Component, { store });
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const emptyState = screen.getByTestId("empty-state");
|
|
257
|
+
expect(emptyState).toBeTruthy();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, screen, cleanup, act } from "@testing-library/react";
|
|
5
|
+
import "@testing-library/jest-dom";
|
|
6
|
+
import { mock } from "jest-mock-extended";
|
|
7
|
+
|
|
8
|
+
import { parseTheme } from "@ax/helpers";
|
|
9
|
+
|
|
10
|
+
import BulkHeader, { IBulkHeaderProps } from "./../../../../../../modules/Sites/SitesList/ListView/BulkHeader";
|
|
11
|
+
|
|
12
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
13
|
+
|
|
14
|
+
afterEach(cleanup);
|
|
15
|
+
|
|
16
|
+
const defaultProps = mock<IBulkHeaderProps>();
|
|
17
|
+
|
|
18
|
+
describe("BulkHeader component rendering", () => {
|
|
19
|
+
it("should render table header", async () => {
|
|
20
|
+
defaultProps.showBulk = false;
|
|
21
|
+
defaultProps.checkState = { isAllSelected: false, indeterminate: false };
|
|
22
|
+
defaultProps.filterValues = { order: "lastAccess-desc", liveStatus: "all" };
|
|
23
|
+
defaultProps.sortedListStatus = { isAscending: false, sortedByTitle: false, sortedByLastAccess: true };
|
|
24
|
+
defaultProps.totalItems = 22;
|
|
25
|
+
|
|
26
|
+
await act(async () => {
|
|
27
|
+
render(
|
|
28
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
29
|
+
<BulkHeader {...defaultProps} />
|
|
30
|
+
</ThemeProvider>
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const tableHeader = screen.getByTestId("sites-table-header");
|
|
35
|
+
expect(tableHeader).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should render bulk header", async () => {
|
|
39
|
+
defaultProps.showBulk = true;
|
|
40
|
+
|
|
41
|
+
await act(async () => {
|
|
42
|
+
render(
|
|
43
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
44
|
+
<BulkHeader {...defaultProps} />
|
|
45
|
+
</ThemeProvider>
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(screen.getByTestId("sites-list-bulk-wrapper")).toBeTruthy();
|
|
50
|
+
});
|
|
51
|
+
});
|