@truedat/test 7.5.9 → 7.5.10

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,9 +1,8 @@
1
1
  {
2
2
  "name": "@truedat/test",
3
- "version": "7.5.9",
3
+ "version": "7.5.10",
4
4
  "description": "Truedat Web Test",
5
5
  "sideEffects": false,
6
- "jsnext:main": "src/index.js",
7
6
  "module": "src/index.js",
8
7
  "files": [
9
8
  "src",
@@ -17,64 +16,22 @@
17
16
  "scripts": {
18
17
  "clean": "rimraf yarn-error.log",
19
18
  "test": "TZ=UTC jest --coverage",
20
- "test:watch": "TZ=UTC jest --watch",
21
19
  "eslint": "eslint src/**",
22
20
  "eslint:fix": "eslint --fix src/**"
23
21
  },
24
- "devDependencies": {
25
- "@babel/cli": "^7.19.3",
26
- "@babel/core": "^7.20.5",
27
- "@babel/plugin-proposal-class-properties": "^7.18.6",
28
- "@babel/plugin-proposal-object-rest-spread": "^7.20.2",
29
- "@babel/plugin-proposal-optional-chaining": "^7.18.9",
30
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
31
- "@babel/plugin-transform-modules-commonjs": "^7.19.6",
32
- "@babel/preset-env": "^7.20.2",
33
- "@babel/preset-react": "^7.18.6",
34
- "@testing-library/jest-dom": "^5.16.5",
35
- "@testing-library/react": "^12.0.0",
36
- "@testing-library/react-hooks": "^8.0.1",
37
- "@testing-library/user-event": "^13.2.1",
38
- "babel-jest": "^28.1.0",
39
- "babel-plugin-dynamic-import-node": "^2.3.3",
40
- "babel-plugin-lodash": "^3.3.4",
41
- "babel-plugin-react-intl": "^5.1.18",
42
- "babel-plugin-transform-semantic-ui-react-imports": "^1.4.1",
43
- "enzyme": "^3.11.0",
44
- "enzyme-adapter-react-16": "^1.15.7",
45
- "enzyme-to-json": "^3.6.2",
46
- "identity-obj-proxy": "^3.0.0",
47
- "jest": "^29.0.0",
48
- "jest-environment-jsdom": "^29.0.0",
49
- "react": "^16.14.0",
50
- "react-dom": "^16.14.0",
51
- "rimraf": "^3.0.2"
52
- },
53
22
  "jest": {
54
23
  "maxWorkers": "50%",
55
24
  "testTimeout": 10000,
56
25
  "moduleDirectories": [
57
- "<rootDir>/src",
58
- "../../node_modules"
26
+ "<rootDir>/src"
59
27
  ],
60
28
  "moduleNameMapper": {
61
- "\\.(css|less|png)$": "identity-obj-proxy",
62
- "^@truedat/([^/]+)$": "<rootDir>/../$1/src/index",
63
- "^@truedat/([^/]+)/(.*)$": "<rootDir>/../$1/src/$2"
29
+ "\\.(css|less|png)$": "identity-obj-proxy"
64
30
  },
65
- "setupFiles": [
66
- "jest-localstorage-mock"
67
- ],
68
31
  "setupFilesAfterEnv": [
69
32
  "@truedat/test/setup"
70
33
  ],
71
- "snapshotSerializers": [
72
- "enzyme-to-json/serializer"
73
- ],
74
34
  "testEnvironment": "jsdom",
75
- "testPathIgnorePatterns": [
76
- "<rootDir>/node_modules/"
77
- ],
78
35
  "transform": {
79
36
  "\\.js$": [
80
37
  "babel-jest",
@@ -82,23 +39,24 @@
82
39
  "rootMode": "upward"
83
40
  }
84
41
  ]
85
- },
86
- "transformIgnorePatterns": [
87
- "/node_modules/(?!@truedat).*"
88
- ]
42
+ }
89
43
  },
90
- "dependencies": {
91
- "@apollo/client": "^3.7.1",
92
- "lodash": "^4.17.21",
93
- "prop-types": "^15.8.1",
94
- "react-intl": "^5.20.10",
95
- "react-redux": "^7.2.4",
96
- "react-router-dom": "^5.2.0",
97
- "redux": "^4.1.1"
98
- },
99
- "peerDependencies": {
100
- "react": ">= 16.8.6 < 17",
101
- "react-dom": ">= 16.8.6 < 17"
44
+ "devDependencies": {
45
+ "@apollo/client": "^3.13.5",
46
+ "@reduxjs/toolkit": "^2.6.1",
47
+ "@testing-library/dom": "^10.4.0",
48
+ "@testing-library/jest-dom": "^6.6.3",
49
+ "@testing-library/react": "^16.2.0",
50
+ "@testing-library/user-event": "^14.6.1",
51
+ "graphql": "^16.10.0",
52
+ "jest": "^29.7.0",
53
+ "react": "^19.0.0",
54
+ "react-dom": "^19.0.0",
55
+ "react-intl": "^7.1.10",
56
+ "react-redux": "^9.2.0",
57
+ "react-router": "^7.4.0",
58
+ "react-test-renderer": "^19.0.0",
59
+ "redux": "^5.0.1"
102
60
  },
103
- "gitHead": "03770e3241daa955de2e6e40fdaea91e3d147860"
61
+ "gitHead": "8a8c49e9d5d6bb4e5f2b503b063bfd6dd20a503d"
104
62
  }
package/setup.js CHANGED
@@ -1,5 +1,5 @@
1
- import "@testing-library/jest-dom";
2
- import Enzyme from "enzyme";
3
- import Adapter from "enzyme-adapter-react-16";
1
+ const { TextEncoder, TextDecoder } = require("util");
2
+ global.TextEncoder = TextEncoder;
3
+ global.TextDecoder = TextDecoder;
4
4
 
5
- Enzyme.configure({ adapter: new Adapter() });
5
+ import "@testing-library/jest-dom";
@@ -0,0 +1,53 @@
1
+ import { render, waitForLoad } from "../render";
2
+ import { screen, waitFor } from "@testing-library/react";
3
+
4
+ describe("render utility", () => {
5
+ it("renders components with default options", () => {
6
+ const TestComponent = () => <div>Test Component</div>;
7
+ render(<TestComponent />);
8
+ expect(screen.getByText("Test Component")).toBeInTheDocument();
9
+ });
10
+
11
+ it("provides redux store with initial state", () => {
12
+ const initialState = { user: { name: "Test User" } };
13
+ const TestComponent = () => {
14
+ return <div>State Test</div>;
15
+ };
16
+
17
+ render(<TestComponent />, { state: initialState });
18
+ expect(screen.getByText("State Test")).toBeInTheDocument();
19
+ });
20
+
21
+ it("handles routing with MemoryRouter", () => {
22
+ const TestComponent = () => <div>Route Test</div>;
23
+ render(<TestComponent />, { routes: ["/test-route"] });
24
+ expect(screen.getByText("Route Test")).toBeInTheDocument();
25
+ });
26
+
27
+ it("handles Apollo mocks", async () => {
28
+ const TestComponent = () => <div>Apollo Test</div>;
29
+ render(<TestComponent />, { mocks: [] });
30
+ expect(screen.getByText("Apollo Test")).toBeInTheDocument();
31
+ });
32
+
33
+ describe("waitForLoad", () => {
34
+ it("waits for loading indicators to disappear", async () => {
35
+ const TestComponent = () => (
36
+ <div><div className="loader" data-testid="loader">
37
+ Loading...
38
+ </div><div>Content</div></div>
39
+ );
40
+
41
+ const renderResult = render(<TestComponent />);
42
+
43
+ // Simulate loader disappearing
44
+ setTimeout(() => {
45
+ const loader = screen.getByTestId("loader");
46
+ loader.remove();
47
+ }, 100);
48
+
49
+ await waitForLoad(renderResult);
50
+ expect(screen.getByText("Content")).toBeInTheDocument();
51
+ });
52
+ });
53
+ });
package/src/mocks.js CHANGED
@@ -39,6 +39,11 @@ export const singleTemplateMock = (variables) => ({
39
39
  result: { data: { templates: [template1] } },
40
40
  });
41
41
 
42
+ export const templatesMockWith = (variables, templates) => ({
43
+ request: { query: TEMPLATES_QUERY, variables },
44
+ result: { data: { templates } },
45
+ });
46
+
42
47
  export const templateByNameMock = (variables) => ({
43
48
  request: { query: TEMPLATE_QUERY, variables },
44
49
  result: { data: { template: template1 } },
@@ -46,7 +51,7 @@ export const templateByNameMock = (variables) => ({
46
51
 
47
52
  export const emptyTemplateByNameMock = () => ({
48
53
  request: { query: TEMPLATE_QUERY, variables: { name: "", domainIds: null } },
49
- result: { data: null },
54
+ result: { data: { template: null } },
50
55
  });
51
56
 
52
57
  export const errorTemplateMock = (variables) => ({
@@ -66,48 +71,47 @@ export const rolesMock = (variables) => ({
66
71
  },
67
72
  });
68
73
 
69
- export const domainsMock = (variables) => ({
74
+ const defaultDomains = [
75
+ {
76
+ __typename: "Domain",
77
+ name: "fooDomain",
78
+ id: "1",
79
+ externalId: "foo",
80
+ parentId: null,
81
+ actions: null,
82
+ },
83
+ {
84
+ __typename: "Domain",
85
+ name: "barDomain",
86
+ id: "2",
87
+ externalId: "bar",
88
+ parentId: null,
89
+ actions: null,
90
+ },
91
+ {
92
+ __typename: "Domain",
93
+ name: "bazDomain",
94
+ id: "3",
95
+ externalId: "baz",
96
+ parentId: null,
97
+ actions: null,
98
+ },
99
+ {
100
+ __typename: "Domain",
101
+ name: "xyzzy",
102
+ id: "33",
103
+ externalId: "d1",
104
+ parentId: "2",
105
+ actions: null,
106
+ },
107
+ ];
108
+ export const domainsMock = (variables, domains = defaultDomains) => ({
70
109
  request: {
71
110
  query: DOMAINS_QUERY,
72
111
  variables,
73
112
  },
74
113
  result: {
75
- data: {
76
- domains: [
77
- {
78
- __typename: "Domain",
79
- name: "fooDomain",
80
- id: "1",
81
- externalId: "foo",
82
- parentId: null,
83
- actions: null,
84
- },
85
- {
86
- __typename: "Domain",
87
- name: "barDomain",
88
- id: "2",
89
- externalId: "bar",
90
- parentId: null,
91
- actions: null,
92
- },
93
- {
94
- __typename: "Domain",
95
- name: "bazDomain",
96
- id: "3",
97
- externalId: "baz",
98
- parentId: null,
99
- actions: null,
100
- },
101
- {
102
- __typename: "Domain",
103
- name: "xyzzy",
104
- id: "33",
105
- externalId: "d1",
106
- parentId: "2",
107
- actions: null,
108
- },
109
- ],
110
- },
114
+ data: { domains },
111
115
  },
112
116
  });
113
117
 
package/src/render.js CHANGED
@@ -1,11 +1,38 @@
1
- import React from "react";
1
+ import { Suspense } from "react";
2
2
  import { MockedProvider } from "@apollo/client/testing";
3
- import { render } from "@testing-library/react";
3
+ import { render, waitFor } from "@testing-library/react";
4
4
  import { IntlProvider } from "react-intl";
5
- import { createStore } from "redux";
5
+ import { configureStore } from "@reduxjs/toolkit";
6
6
  import { Provider } from "react-redux";
7
- import { MemoryRouter } from "react-router-dom";
8
- import defaultMessages from "./messages";
7
+ import { MemoryRouter } from "react-router";
8
+
9
+ const originalXHR = window.XMLHttpRequest;
10
+ const mockXHR = function () {
11
+ const xhr = new originalXHR();
12
+
13
+ // Save the original open method
14
+ const originalOpen = xhr.open;
15
+
16
+ // Override open to log the URL being requested
17
+ xhr.open = function () {
18
+ console.log("XHR requested URL:", arguments[1]);
19
+ return originalOpen.apply(this, arguments);
20
+ };
21
+
22
+ return xhr;
23
+ };
24
+
25
+ // Setup mock date for all tests
26
+ beforeAll(() => {
27
+ jest.useFakeTimers();
28
+ jest.setSystemTime(new Date("2025-01-01"));
29
+ window.XMLHttpRequest = mockXHR;
30
+ });
31
+
32
+ afterAll(() => {
33
+ jest.useRealTimers();
34
+ window.XMLHttpRequest = originalXHR;
35
+ });
9
36
 
10
37
  const customRender = (
11
38
  component,
@@ -13,15 +40,20 @@ const customRender = (
13
40
  locale = "en",
14
41
  mocks = [],
15
42
  state = {},
16
- messages = defaultMessages,
43
+ reducer = (x) => x,
44
+ messages = { en: {} },
17
45
  routes = ["/"],
18
- routeIndex,
19
- fallback = false,
46
+ routeIndex = 0,
47
+ fallback = <div>loading</div>,
20
48
  dispatch,
21
49
  ...renderOptions
22
50
  } = {}
23
51
  ) => {
24
- const store = createStore(() => state);
52
+ const store = configureStore({
53
+ preloadedState: state,
54
+ reducer,
55
+ });
56
+
25
57
  // eslint-disable-next-line react/prop-types
26
58
  function Wrapper({ children }) {
27
59
  const content = (
@@ -41,7 +73,7 @@ const customRender = (
41
73
  </MemoryRouter>
42
74
  );
43
75
  return fallback ? (
44
- <React.Suspense fallback={fallback}>{content}</React.Suspense>
76
+ <Suspense fallback={fallback}>{content}</Suspense>
45
77
  ) : (
46
78
  content
47
79
  );
@@ -51,4 +83,15 @@ const customRender = (
51
83
  return render(component, { wrapper: Wrapper, ...renderOptions });
52
84
  };
53
85
 
86
+ export const waitForLoad = async (
87
+ { container, queryByText },
88
+ fallback = /loading/i
89
+ ) => {
90
+ await waitFor(() => {
91
+ if (fallback) expect(queryByText(fallback)).not.toBeInTheDocument();
92
+ expect(container.querySelector(".loader")).not.toBeInTheDocument();
93
+ expect(container.querySelector(".loading")).not.toBeInTheDocument();
94
+ });
95
+ };
96
+
54
97
  export { customRender as render };
@@ -1,12 +0,0 @@
1
- import React from "react";
2
- import { shallowWithIntl } from "@truedat/test/intl-stub";
3
-
4
- describe("shallowWithIntl", () => {
5
- it("injects the intl context into the wrapped component", () => {
6
- const wrapper = shallowWithIntl(<p>Hello</p>);
7
- expect(wrapper.find("p").prop("intl")).toMatchObject({
8
- locale: "en",
9
- messages: expect.objectContaining({ foo: "foo" })
10
- });
11
- });
12
- });
package/src/intl-stub.js DELETED
@@ -1,55 +0,0 @@
1
- import _ from "lodash/fp";
2
- import React from "react";
3
- import { createIntl, createIntlCache } from "react-intl";
4
- import { shallow, mount } from "enzyme";
5
- import audit from "@truedat/audit/messages/es";
6
- import auth from "@truedat/auth/messages/es";
7
- import bg from "@truedat/bg/messages/es";
8
- import core from "@truedat/core/messages/es";
9
- import cx from "@truedat/cx/messages/es";
10
- import dd from "@truedat/dd/messages/es";
11
- import df from "@truedat/df/messages/es";
12
- import dq from "@truedat/dq/messages/es";
13
- import ie from "@truedat/ie/messages/es";
14
- import lm from "@truedat/lm/messages/es";
15
- import se from "@truedat/se/messages/es";
16
-
17
- const cache = createIntlCache();
18
-
19
- const messages = _.flow(
20
- _.mergeAll,
21
- _.keys,
22
- _.map(x => [x, x]),
23
- _.fromPairs
24
- )([audit, auth, bg, core, cx, dd, df, dq, ie, lm, se, { foo: "bar" }]);
25
-
26
- export const intl = createIntl(
27
- {
28
- locale: "en",
29
- defaultLocale: "en",
30
- messages
31
- },
32
- cache
33
- );
34
-
35
- /**
36
- * Equivalent to enzyme's 'shallow' method.
37
- * @param {string} node React Component that requires reactintl.
38
- * @return {object}
39
- */
40
- export const shallowWithIntl = node => {
41
- return shallow(React.cloneElement(node, { intl }), {
42
- context: { intl, useIntl: () => intl }
43
- });
44
- };
45
-
46
- /**
47
- * Equivalent to enzyme's 'mount' method.
48
- * @param {string} node React Component that requires reactintl.
49
- * @return {object}
50
- */
51
- export const mountWithIntl = node => {
52
- return mount(React.cloneElement(node, { intl }), {
53
- context: { intl, useIntl: () => intl }
54
- });
55
- };