@truedat/test 8.12.7 → 8.12.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/test",
|
|
3
|
-
"version": "8.12.
|
|
3
|
+
"version": "8.12.11",
|
|
4
4
|
"description": "Truedat Web Test",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"react-router": "^8.3.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "48671e0f1467f7713019ab8d729818c741fa9bc7"
|
|
70
70
|
}
|
|
@@ -1,33 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lazy } from "react";
|
|
2
|
+
import { MockedProvider } from "@apollo/client/testing";
|
|
3
|
+
import { configureStore } from "@reduxjs/toolkit";
|
|
4
|
+
import { screen } from "@testing-library/react";
|
|
5
|
+
import { FormattedMessage } from "react-intl";
|
|
6
|
+
import { Provider } from "react-redux";
|
|
7
|
+
import { MemoryRouter } from "react-router";
|
|
2
8
|
import { render, waitForLoad } from "../render";
|
|
9
|
+
import { renderWithIntl } from "../renderWithIntl";
|
|
3
10
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
jest.mock("@apollo/client/testing", () => ({
|
|
12
|
+
MockedProvider: jest.fn(({ children }) => children),
|
|
13
|
+
}));
|
|
14
|
+
jest.mock("@reduxjs/toolkit", () => ({
|
|
15
|
+
configureStore: jest.fn(() => ({ dispatch: jest.fn() })),
|
|
16
|
+
}));
|
|
17
|
+
jest.mock("react-redux", () => ({
|
|
18
|
+
Provider: jest.fn(({ children }) => children),
|
|
19
|
+
}));
|
|
20
|
+
jest.mock("react-router", () => ({
|
|
21
|
+
MemoryRouter: jest.fn(({ children }) => children),
|
|
22
|
+
}));
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
describe("render utility", () => {
|
|
25
|
+
it("configures its providers and renders the component", () => {
|
|
26
|
+
const state = { user: { name: "Test User" } };
|
|
27
|
+
const reducer = (currentState) => currentState;
|
|
28
|
+
const routes = ["/test-route"];
|
|
29
|
+
const mocks = [];
|
|
30
|
+
const dispatch = jest.fn();
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
render(<div>Test Component</div>, {
|
|
33
|
+
state,
|
|
34
|
+
reducer,
|
|
35
|
+
routes,
|
|
36
|
+
routeIndex: 0,
|
|
37
|
+
mocks,
|
|
38
|
+
dispatch,
|
|
39
|
+
});
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
expect(configureStore).toHaveBeenCalledWith({
|
|
42
|
+
preloadedState: state,
|
|
43
|
+
reducer,
|
|
44
|
+
});
|
|
45
|
+
expect(configureStore.mock.results[0].value.dispatch).toBe(dispatch);
|
|
46
|
+
expect(MemoryRouter.mock.calls[0][0]).toEqual(
|
|
47
|
+
expect.objectContaining({ initialEntries: routes, initialIndex: 0 }),
|
|
48
|
+
);
|
|
49
|
+
expect(Provider.mock.calls[0][0]).toEqual(
|
|
50
|
+
expect.objectContaining({ store: configureStore.mock.results[0].value }),
|
|
51
|
+
);
|
|
52
|
+
expect(MockedProvider.mock.calls[0][0]).toEqual(
|
|
53
|
+
expect.objectContaining({ mocks, addTypename: false }),
|
|
54
|
+
);
|
|
55
|
+
expect(screen.getByText("Test Component")).toBeInTheDocument();
|
|
31
56
|
});
|
|
32
57
|
|
|
33
58
|
describe("waitForLoad", () => {
|
|
@@ -42,6 +67,7 @@ describe("render utility", () => {
|
|
|
42
67
|
);
|
|
43
68
|
|
|
44
69
|
const renderResult = render(<TestComponent />);
|
|
70
|
+
const defaultReducer = configureStore.mock.calls.at(-1)[0].reducer;
|
|
45
71
|
|
|
46
72
|
// Simulate loader disappearing
|
|
47
73
|
setTimeout(() => {
|
|
@@ -50,7 +76,25 @@ describe("render utility", () => {
|
|
|
50
76
|
}, 100);
|
|
51
77
|
|
|
52
78
|
await waitForLoad(renderResult);
|
|
79
|
+
expect(defaultReducer({ ready: true })).toEqual({ ready: true });
|
|
53
80
|
expect(screen.getByText("Content")).toBeInTheDocument();
|
|
54
81
|
});
|
|
55
82
|
});
|
|
56
83
|
});
|
|
84
|
+
|
|
85
|
+
describe("renderWithIntl", () => {
|
|
86
|
+
it("keeps the Suspense boundary and messages when rerendering", async () => {
|
|
87
|
+
const LazyMessage = lazy(async () => ({
|
|
88
|
+
default: () => <FormattedMessage id="ready" />,
|
|
89
|
+
}));
|
|
90
|
+
const rendered = renderWithIntl(<div>Initial</div>, {
|
|
91
|
+
messages: { en: { ready: "Ready" } },
|
|
92
|
+
fallback: <div>Loading</div>,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
rendered.rerender(<LazyMessage />);
|
|
96
|
+
|
|
97
|
+
expect(rendered.getByText("Loading")).toBeInTheDocument();
|
|
98
|
+
expect(await rendered.findByText("Ready")).toBeInTheDocument();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { lazy } from "react";
|
|
2
|
-
import { FormattedMessage } from "react-intl";
|
|
3
|
-
import { renderWithIntl } from "../renderWithIntl";
|
|
4
|
-
|
|
5
|
-
describe("renderWithIntl", () => {
|
|
6
|
-
it("keeps the Suspense boundary and messages when rerendering", async () => {
|
|
7
|
-
const LazyMessage = lazy(async () => ({
|
|
8
|
-
default: () => <FormattedMessage id="ready" />,
|
|
9
|
-
}));
|
|
10
|
-
const rendered = renderWithIntl(<div>Initial</div>, {
|
|
11
|
-
messages: { en: { ready: "Ready" } },
|
|
12
|
-
fallback: <div>Loading</div>,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
rendered.rerender(<LazyMessage />);
|
|
16
|
-
|
|
17
|
-
expect(rendered.getByText("Loading")).toBeInTheDocument();
|
|
18
|
-
expect(await rendered.findByText("Ready")).toBeInTheDocument();
|
|
19
|
-
});
|
|
20
|
-
});
|