From f5f92e9ac7ccbba5a5e772623d8ce754144af190 Mon Sep 17 00:00:00 2001 From: capyq Date: Fri, 20 Sep 2024 11:35:05 +0200 Subject: [PATCH 1/3] tests:adding common tools Signed-off-by: capyq --- jest.config.ts | 2 +- jest.setup.ts | 1 + package-lock.json | 197 +++++++++++++++++++++++++++++++++++---- package.json | 10 +- src/tests/testsUtils.tsx | 111 ++++++++++++++++++++++ tsconfig.json | 3 +- 6 files changed, 303 insertions(+), 21 deletions(-) create mode 100644 src/tests/testsUtils.tsx diff --git a/jest.config.ts b/jest.config.ts index 93874b54..a64af08e 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -18,7 +18,7 @@ const config: Config = { globals: { IS_REACT_ACT_ENVIRONMENT: true, }, - setupFiles: ['/jest.setup.ts'], + setupFilesAfterEnv: ['/jest.setup.ts'], }; export default config; diff --git a/jest.setup.ts b/jest.setup.ts index 996e17fd..df2d89b7 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import '@testing-library/jest-dom' import { TextEncoder, TextDecoder } from 'util'; // fix for ReferenceError: TextDecoder / TextEncoder is not defined diff --git a/package-lock.json b/package-lock.json index 23bbd3e8..70189e91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@react-querybuilder/dnd": "^7.2.0", "@react-querybuilder/material": "^7.2.0", + "@testing-library/user-event": "^14.5.2", "autosuggest-highlight": "^3.3.4", "clsx": "^2.1.0", "jwt-decode": "^4.0.0", @@ -40,10 +41,12 @@ "@mui/lab": "5.0.0-alpha.169", "@mui/material": "^5.15.14", "@react-hook/window-size": "^3.1.1", + "@testing-library/jest-dom": "^6.5.0", "@testing-library/react": "^16.0.0", "@types/autosuggest-highlight": "^3.2.3", "@types/eslint": "^8.56.7", "@types/eslint-config-prettier": "^6.11.3", + "@types/jest": "^29.5.13", "@types/json-logic-js": "^2.0.7", "@types/license-checker": "^25.0.6", "@types/localized-countries": "^2.0.3", @@ -79,6 +82,7 @@ "glob": "^10.3.12", "identity-obj-proxy": "^3.0.0", "jest": "^29.7.0", + "jest-dom": "^4.0.0", "jest-environment-jsdom": "^29.7.0", "license-checker": "^25.0.1", "notistack": "^3.0.1", @@ -136,6 +140,12 @@ "node": ">=0.10.0" } }, + "node_modules/@adobe/css-tools": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz", + "integrity": "sha512-Ff9+ksdQQB3rMncgqDK78uLznstjyfIf2Arnh22pW8kBpLs6rpKDwgnZT46hin5Hl1WzazzK64DOrhSwYpS7bQ==", + "dev": true + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -5266,7 +5276,6 @@ "version": "10.4.0", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.0.tgz", "integrity": "sha512-pemlzrSESWbdAloYml3bAJMEfNh1Z7EduzqPKprCH5S341frlpYnUEW0H72dLxa6IsYr+mPno20GiSm+h9dEdQ==", - "dev": true, "peer": true, "dependencies": { "@babel/code-frame": "^7.10.4", @@ -5286,7 +5295,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "peer": true, "dependencies": { "color-convert": "^2.0.1" @@ -5302,7 +5310,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "peer": true, "dependencies": { "ansi-styles": "^4.1.0", @@ -5319,7 +5326,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "peer": true, "dependencies": { "color-name": "~1.1.4" @@ -5332,14 +5338,12 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true, "peer": true }, "node_modules/@testing-library/dom/node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "peer": true, "engines": { "node": ">=8" @@ -5349,7 +5353,6 @@ "version": "27.5.1", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", - "dev": true, "peer": true, "dependencies": { "ansi-regex": "^5.0.1", @@ -5364,7 +5367,6 @@ "version": "5.2.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", - "dev": true, "peer": true, "engines": { "node": ">=10" @@ -5377,14 +5379,12 @@ "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "dev": true, "peer": true }, "node_modules/@testing-library/dom/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "peer": true, "dependencies": { "has-flag": "^4.0.0" @@ -5393,6 +5393,99 @@ "node": ">=8" } }, + "node_modules/@testing-library/jest-dom": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.5.0.tgz", + "integrity": "sha512-xGGHpBXYSHUUr6XsKBfs85TWlYKpTc37cSBBVrXcib2MkHLboWlkClhWF37JKlDb9KEq3dHs+f2xR7XJEWGBxA==", + "dev": true, + "dependencies": { + "@adobe/css-tools": "^4.4.0", + "aria-query": "^5.0.0", + "chalk": "^3.0.0", + "css.escape": "^1.5.1", + "dom-accessibility-api": "^0.6.3", + "lodash": "^4.17.21", + "redent": "^3.0.0" + }, + "engines": { + "node": ">=14", + "npm": ">=6", + "yarn": ">=1" + } + }, + "node_modules/@testing-library/jest-dom/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@testing-library/jest-dom/node_modules/chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@testing-library/jest-dom/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/@testing-library/jest-dom/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/@testing-library/jest-dom/node_modules/dom-accessibility-api": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.6.3.tgz", + "integrity": "sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==", + "dev": true + }, + "node_modules/@testing-library/jest-dom/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@testing-library/jest-dom/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/@testing-library/react": { "version": "16.0.0", "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-16.0.0.tgz", @@ -5420,6 +5513,18 @@ } } }, + "node_modules/@testing-library/user-event": { + "version": "14.5.2", + "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.5.2.tgz", + "integrity": "sha512-YAh82Wh4TIrxYLmfGcixwD18oIjyC1pFQC2Y01F2lzV2HTMiYrI0nze0FD0ocB//CKS/7jIUgae+adPqxK5yCQ==", + "engines": { + "node": ">=12", + "npm": ">=6" + }, + "peerDependencies": { + "@testing-library/dom": ">=7.21.4" + } + }, "node_modules/@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", @@ -5463,7 +5568,6 @@ "version": "5.0.4", "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==", - "dev": true, "peer": true }, "node_modules/@types/autosuggest-highlight": { @@ -5577,6 +5681,16 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/jest": { + "version": "29.5.13", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.13.tgz", + "integrity": "sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==", + "dev": true, + "dependencies": { + "expect": "^29.0.0", + "pretty-format": "^29.0.0" + } + }, "node_modules/@types/jsdom": { "version": "20.0.1", "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-20.0.1.tgz", @@ -6374,7 +6488,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "engines": { "node": ">=8" } @@ -6419,7 +6532,6 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==", - "dev": true, "dependencies": { "dequal": "^2.0.3" } @@ -7564,6 +7676,12 @@ "tiny-invariant": "^1.0.6" } }, + "node_modules/css.escape": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz", + "integrity": "sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg==", + "dev": true + }, "node_modules/cssom": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.5.0.tgz", @@ -7779,7 +7897,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", - "dev": true, "engines": { "node": ">=6" } @@ -7859,7 +7976,6 @@ "version": "0.5.16", "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==", - "dev": true, "peer": true }, "node_modules/dom-helpers": { @@ -10066,6 +10182,15 @@ "node": ">=0.8.19" } }, + "node_modules/indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -11164,6 +11289,13 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-dom": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jest-dom/-/jest-dom-4.0.0.tgz", + "integrity": "sha512-gBxYZlZB1Jgvf2gP2pRfjjUWF8woGBHj/g5rAQgFPB/0K2atGuhVcPO+BItyjWeKg9zM+dokgcMOH01vrWVMFA==", + "deprecated": "🚨 jest-dom has moved to @testing-library/jest-dom. Please uninstall jest-dom and install @testing-library/jest-dom instead, or use an older version of jest-dom. Learn more about this change here: https://github.com/testing-library/dom-testing-library/issues/260 Thanks! :)", + "dev": true + }, "node_modules/jest-each": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-29.7.0.tgz", @@ -12692,7 +12824,6 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", - "dev": true, "peer": true, "bin": { "lz-string": "bin/bin.js" @@ -12836,6 +12967,15 @@ "node": ">=6" } }, + "node_modules/min-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", + "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/minimatch": { "version": "9.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", @@ -14206,6 +14346,19 @@ "once": "^1.3.0" } }, + "node_modules/redent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", + "integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==", + "dev": true, + "dependencies": { + "indent-string": "^4.0.0", + "strip-indent": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/redux": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/redux/-/redux-4.2.1.tgz", @@ -15074,6 +15227,18 @@ "node": ">=6" } }, + "node_modules/strip-indent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", + "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", + "dev": true, + "dependencies": { + "min-indent": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", diff --git a/package.json b/package.json index 72c47885..c10e6c37 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dependencies": { "@react-querybuilder/dnd": "^7.2.0", "@react-querybuilder/material": "^7.2.0", + "@testing-library/user-event": "^14.5.2", "autosuggest-highlight": "^3.3.4", "clsx": "^2.1.0", "jwt-decode": "^4.0.0", @@ -46,18 +47,18 @@ "uuid": "^9.0.1" }, "peerDependencies": { - "@mui/system": "^5.15.15", - "@mui/x-tree-view": "^6.17.0", - "papaparse": "^5.4.1", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.0", "@hookform/resolvers": "^3.3.4", "@mui/icons-material": "^5.15.14", "@mui/lab": "5.0.0-alpha.169", "@mui/material": "^5.15.14", + "@mui/system": "^5.15.15", + "@mui/x-tree-view": "^6.17.0", "ag-grid-community": "^31.0.0", "ag-grid-react": "^31.2.0", "notistack": "^3.0.1", + "papaparse": "^5.4.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", @@ -80,10 +81,12 @@ "@mui/lab": "5.0.0-alpha.169", "@mui/material": "^5.15.14", "@react-hook/window-size": "^3.1.1", + "@testing-library/jest-dom": "^6.5.0", "@testing-library/react": "^16.0.0", "@types/autosuggest-highlight": "^3.2.3", "@types/eslint": "^8.56.7", "@types/eslint-config-prettier": "^6.11.3", + "@types/jest": "^29.5.13", "@types/json-logic-js": "^2.0.7", "@types/license-checker": "^25.0.6", "@types/localized-countries": "^2.0.3", @@ -119,6 +122,7 @@ "glob": "^10.3.12", "identity-obj-proxy": "^3.0.0", "jest": "^29.7.0", + "jest-dom": "^4.0.0", "jest-environment-jsdom": "^29.7.0", "license-checker": "^25.0.1", "notistack": "^3.0.1", diff --git a/src/tests/testsUtils.tsx b/src/tests/testsUtils.tsx new file mode 100644 index 00000000..59e07a9a --- /dev/null +++ b/src/tests/testsUtils.tsx @@ -0,0 +1,111 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// eslint-disable-next-line import/no-extraneous-dependencies +import { render as rtlRender } from '@testing-library/react'; +import { createTheme, ThemeProvider } from '@mui/material/styles'; +import { IntlProvider } from 'react-intl'; +import { + login_en, + report_viewer_en, + top_bar_en, + table_en, + treeview_finder_en, + element_search_en, + equipment_search_en, + filter_en, + filter_expert_en, + description_en, + equipments_en, + csv_en, + card_error_boundary_en, + flat_parameters_en, + multiple_selection_dialog_en, + common_button_en, + directory_items_input_en, +} from '..'; + +const fullTrad = { + ...report_viewer_en, + ...login_en, + ...top_bar_en, + ...table_en, + ...treeview_finder_en, + ...element_search_en, + ...equipment_search_en, + ...filter_en, + ...filter_expert_en, + ...description_en, + ...equipments_en, + ...csv_en, + ...card_error_boundary_en, + ...flat_parameters_en, + ...multiple_selection_dialog_en, + ...common_button_en, + ...directory_items_input_en, +}; +const renderWithTranslation = (ui: React.ReactElement) => ( + + {ui} + +); + +const lightTheme = createTheme( + { + components: { + MuiTab: { + styleOverrides: { + root: { + textTransform: 'none', + }, + }, + }, + MuiButton: { + styleOverrides: { + root: { + textTransform: 'none', + }, + }, + }, + }, + palette: { + mode: 'light', + }, + }, + { + aggrid: { + theme: 'ag-theme-alpine', + overlay: { + background: '#e6e6e6', + }, + }, + } +); +const renderWithTheme = (ui: React.ReactElement) => {ui}; + +// eslint-disable-next-line import/prefer-default-export +export class RenderBuilder { + renderWithTheme: boolean = false; + + renderWithTrad: boolean = false; + + withTrad() { + this.renderWithTrad = true; + return this; + } + + withTheme() { + this.renderWithTheme = true; + return this; + } + + render(ui: React.ReactElement) { + let newUi = this.renderWithTrad ? renderWithTranslation(ui) : ui; + newUi = this.renderWithTheme ? renderWithTheme(newUi) : newUi; + return rtlRender(newUi); + } +} diff --git a/tsconfig.json b/tsconfig.json index 9411442b..0febda27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,5 +16,6 @@ "noEmit": true, "jsx": "react-jsx" }, - "include": ["src", "demo"] // we can let demo because the file generation is managed my vite and we have noEmit anyway + "types":["node","jest", "@testing-library/jest-dom"], + "include": ["src", "demo","jest.setup.ts"] // we can let demo because the file generation is managed my vite and we have noEmit anyway } From 1a74e16f84bfdf7c46123521f107986535ace5e6 Mon Sep 17 00:00:00 2001 From: capyq Date: Fri, 20 Sep 2024 11:40:05 +0200 Subject: [PATCH 2/3] tests: add card error boundary tests Signed-off-by: capyq --- .../tests/CardErrorBoundary.test.tsx | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx diff --git a/src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx b/src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx new file mode 100644 index 00000000..5773e071 --- /dev/null +++ b/src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +import { screen } from '@testing-library/react'; +import { it } from '@jest/globals'; +import CardErrorBoundary from '../CardErrorBoundary'; +import { RenderBuilder } from '../../../tests/testsUtils'; + +const RenderBuilderInstance = new RenderBuilder().withTrad(); +it('renders the child component when there is no error', () => { + RenderBuilderInstance.render( + +
Child Component
+
+ ); + + const childComponent = screen.getByText('Child Component'); + expect(childComponent).toBeInTheDocument(); +}); + +it('renders an error message when there is an error', () => { + const errorMessage = 'Something went wrong'; + const ErrorComponent = () => { + throw new Error(errorMessage); + }; + + RenderBuilderInstance.render( + + + + ); + + const errorText = screen.getByText(errorMessage); + expect(errorText).toBeInTheDocument(); +}); From 0fa51c4d5bc9fc9f1bcbb8f52bac61ef6d33244b Mon Sep 17 00:00:00 2001 From: capyq Date: Fri, 20 Sep 2024 11:44:20 +0200 Subject: [PATCH 3/3] tests: update test Signed-off-by: capyq --- .../tests/CardErrorBoundary.test.tsx | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx b/src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx index 5773e071..296daaa5 100644 --- a/src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx +++ b/src/components/cardErrorBoundary/tests/CardErrorBoundary.test.tsx @@ -10,29 +10,32 @@ import CardErrorBoundary from '../CardErrorBoundary'; import { RenderBuilder } from '../../../tests/testsUtils'; const RenderBuilderInstance = new RenderBuilder().withTrad(); -it('renders the child component when there is no error', () => { - RenderBuilderInstance.render( - -
Child Component
-
- ); - const childComponent = screen.getByText('Child Component'); - expect(childComponent).toBeInTheDocument(); -}); +describe('CardErrorBoundary', () => { + it('renders the child component when there is no error', () => { + RenderBuilderInstance.render( + +
Child Component
+
+ ); + + const childComponent = screen.getByText('Child Component'); + expect(childComponent).toBeInTheDocument(); + }); -it('renders an error message when there is an error', () => { - const errorMessage = 'Something went wrong'; - const ErrorComponent = () => { - throw new Error(errorMessage); - }; + it('renders an error message when there is an error', () => { + const errorMessage = 'Something went wrong'; + const ErrorComponent = () => { + throw new Error(errorMessage); + }; - RenderBuilderInstance.render( - - - - ); + RenderBuilderInstance.render( + + + + ); - const errorText = screen.getByText(errorMessage); - expect(errorText).toBeInTheDocument(); + const errorText = screen.getByText(errorMessage); + expect(errorText).toBeInTheDocument(); + }); });