From 483d16de7fb3cc979a1ee6ed7f69199ecf3b3ce6 Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Wed, 27 Mar 2024 20:46:01 +0100 Subject: [PATCH] Add theforeman github actions for JS tests * Adapt jest.config.js for JS test suite * Fix webpack/lib katello tests * Upgrade @testing-library/react to 14.2.2 * Add preliminary test for StatusPropertiesLabel --- .github/workflows/js_tests.yml | 26 +- jest.config.js | 57 ++-- package-lock.json | 310 ++++++++++++------ package.json | 4 +- .../Properties/StatusPropertiesLabel.test.js | 56 ++++ .../EditableTextInput/EditableTextInput.js | 14 +- .../__tests__/editableTextInput.test.js | 10 +- .../react-testing-lib-wrapper.js | 0 8 files changed, 320 insertions(+), 157 deletions(-) create mode 100644 webpack/components/ResourceQuotaForm/components/Properties/StatusPropertiesLabel.test.js rename webpack/lib/{EditableTextInput/__tests__ => }/react-testing-lib-wrapper.js (100%) diff --git a/.github/workflows/js_tests.yml b/.github/workflows/js_tests.yml index 4a74e94..df123da 100644 --- a/.github/workflows/js_tests.yml +++ b/.github/workflows/js_tests.yml @@ -9,20 +9,14 @@ on: - 'package.json' - 'package-lock.json' - '.github/workflows/js_tests.yml' + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + jobs: - test_js: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - node-version: [12, 14] - steps: - - uses: actions/checkout@v2 - - name: Setup Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Npm install - run: npm install - - name: Run plugin linter - run: npm run lint + test: + name: JavaScript + uses: theforeman/actions/.github/workflows/foreman_plugin_js.yml@v0 + with: + plugin: foreman_resource_quota diff --git a/jest.config.js b/jest.config.js index 40f5d28..7417b5a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,35 +1,30 @@ -const { foremanLocation, foremanRelativePath } = require('@theforeman/find-foreman') +const tfmConfig = require('@theforeman/test/src/pluginConfig'); +const { + foremanRelativePath, + foremanLocation, +} = require('@theforeman/find-foreman'); + const foremanReactRelative = 'webpack/assets/javascripts/react_app'; const foremanFull = foremanLocation(); const foremanReactFull = foremanRelativePath(foremanReactRelative); -// Jest configuration -module.exports = { - testURL: 'http://localhost/', - setupFiles: [ - './webpack/test_setup.js', - ], - setupFilesAfterEnv: [ - './webpack/global_test_setup.js', - '@testing-library/jest-dom' - ], - testPathIgnorePatterns: [ - '/node_modules/', - '/foreman/', - '/.+fixtures.+', - '/engines', - ], - moduleDirectories: [ - `${foremanFull}/node_modules`, - `${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`, - 'node_modules', - 'webpack/test-utils', - ], - modulePathIgnorePatterns: [ - '/foreman/', - ], - moduleNameMapper: { - '^.+\\.(css|scss)$': 'identity-obj-proxy', - '^foremanReact(.*)$': `${foremanReactFull}/$1`, - }, -}; +// Find correct path to foremanReact so we do not have to mock it in tests +tfmConfig.moduleNameMapper['^foremanReact(.*)$'] = `${foremanReactFull}/$1`; + +tfmConfig.setupFiles = ['./webpack/test_setup.js']; +tfmConfig.setupFilesAfterEnv = [ + './webpack/global_test_setup.js', + '@testing-library/jest-dom', +]; + +// Do not use default resolver +tfmConfig.resolver = null; +// Specify module dirs instead +tfmConfig.moduleDirectories = [ + `${foremanFull}/node_modules`, + `${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`, + 'node_modules', + 'webpack/test-utils', +]; + +module.exports = tfmConfig; diff --git a/package-lock.json b/package-lock.json index f4e8aec..891cb38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1536,9 +1536,9 @@ } }, "@babel/runtime-corejs3": { - "version": "7.23.8", - "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.23.8.tgz", - "integrity": "sha512-2ZzmcDugdm0/YQKFVYsXiwUN7USPX8PM7cytpb4PFl87fM+qYPSvTZX//8tyeJB1j0YDmafBJEbl5f8NfLyuKw==", + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.24.1.tgz", + "integrity": "sha512-T9ko/35G+Bkl+win48GduaPlhSlOjjE5s1TeiEcD+QpxlLQnoEfb/nO/T+TQqkm+ipFwORn+rB8w14iJ/uD0bg==", "dev": true, "requires": { "core-js-pure": "^3.30.2", @@ -6828,19 +6828,19 @@ } }, "@testing-library/dom": { - "version": "7.31.2", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-7.31.2.tgz", - "integrity": "sha512-3UqjCpey6HiTZT92vODYLPxTBWlM8ZOOjr3LX5F37/VRipW2M1kX6I/Cm4VXzteZqfGfagg8yXywpcOgQBlNsQ==", + "version": "9.3.4", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.4.tgz", + "integrity": "sha512-FlS4ZWlp97iiNWig0Muq8p+3rVDjRiYE+YKGbAqXOu9nwJFFOdL00kFpz42M+4huzYi86vAK1sOOfyOG45muIQ==", "dev": true, "requires": { "@babel/code-frame": "^7.10.4", "@babel/runtime": "^7.12.5", - "@types/aria-query": "^4.2.0", - "aria-query": "^4.2.2", + "@types/aria-query": "^5.0.1", + "aria-query": "5.1.3", "chalk": "^4.1.0", - "dom-accessibility-api": "^0.5.6", - "lz-string": "^1.4.4", - "pretty-format": "^26.6.2" + "dom-accessibility-api": "^0.5.9", + "lz-string": "^1.5.0", + "pretty-format": "^27.0.2" }, "dependencies": { "ansi-styles": { @@ -6883,81 +6883,29 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, - "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, - "requires": { - "has-flag": "^4.0.0" - } - } - } - }, - "@testing-library/jest-dom": { - "version": "5.17.0", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.17.0.tgz", - "integrity": "sha512-ynmNeT7asXyH3aSVv4vvX4Rb+0qjOhdNHnO/3vuZNqPmhDpV/+rCSGwQ7bLcmU2cJ4dvoheIO85LQj0IbJHEtg==", - "dev": true, - "requires": { - "@adobe/css-tools": "^4.0.1", - "@babel/runtime": "^7.9.2", - "@types/testing-library__jest-dom": "^5.9.1", - "aria-query": "^5.0.0", - "chalk": "^3.0.0", - "css.escape": "^1.5.1", - "dom-accessibility-api": "^0.5.6", - "lodash": "^4.17.15", - "redent": "^3.0.0" - }, - "dependencies": { - "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, - "requires": { - "color-convert": "^2.0.1" - } - }, - "aria-query": { - "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, - "requires": { - "dequal": "^2.0.3" - } - }, - "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", - "dev": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "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==", + "pretty-format": { + "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, "requires": { - "color-name": "~1.1.4" + "ansi-regex": "^5.0.1", + "ansi-styles": "^5.0.0", + "react-is": "^17.0.1" + }, + "dependencies": { + "ansi-styles": { + "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 + } } }, - "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 - }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "react-is": { + "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 }, "supports-color": { @@ -6972,13 +6920,14 @@ } }, "@testing-library/react": { - "version": "10.4.9", - "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-10.4.9.tgz", - "integrity": "sha512-pHZKkqUy0tmiD81afs8xfiuseXfU/N7rAX3iKjeZYje86t9VaB0LrxYVa+OOsvkrveX5jCK3IjajVn2MbePvqA==", + "version": "14.2.2", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-14.2.2.tgz", + "integrity": "sha512-SOUuM2ysCvjUWBXTNfQ/ztmnKDmqaiPV3SvoIuyxMUca45rbSWWAT/qB8CUs/JQ/ux/8JFs9DNdFQ3f6jH3crA==", "dev": true, "requires": { - "@babel/runtime": "^7.10.3", - "@testing-library/dom": "^7.22.3" + "@babel/runtime": "^7.12.5", + "@testing-library/dom": "^9.0.0", + "@types/react-dom": "^18.0.0" } }, "@testing-library/react-hooks": { @@ -7316,6 +7265,71 @@ "tslib": "^2.0.0" } }, + "@testing-library/dom": { + "version": "7.31.2", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-7.31.2.tgz", + "integrity": "sha512-3UqjCpey6HiTZT92vODYLPxTBWlM8ZOOjr3LX5F37/VRipW2M1kX6I/Cm4VXzteZqfGfagg8yXywpcOgQBlNsQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.10.4", + "@babel/runtime": "^7.12.5", + "@types/aria-query": "^4.2.0", + "aria-query": "^4.2.2", + "chalk": "^4.1.0", + "dom-accessibility-api": "^0.5.6", + "lz-string": "^1.4.4", + "pretty-format": "^26.6.2" + }, + "dependencies": { + "aria-query": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-4.2.2.tgz", + "integrity": "sha512-o/HelwhuKpTj/frsOsbNLNgnNGVIFsVP/SW2BSF14gVl7kAfMOJ6/8wUAUvG1R1NHKrfG+2sHZTu0yauT1qBrA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.10.2", + "@babel/runtime-corejs3": "^7.10.2" + } + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } + } + }, + "@testing-library/jest-dom": { + "version": "5.17.0", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.17.0.tgz", + "integrity": "sha512-ynmNeT7asXyH3aSVv4vvX4Rb+0qjOhdNHnO/3vuZNqPmhDpV/+rCSGwQ7bLcmU2cJ4dvoheIO85LQj0IbJHEtg==", + "dev": true, + "requires": { + "@adobe/css-tools": "^4.0.1", + "@babel/runtime": "^7.9.2", + "@types/testing-library__jest-dom": "^5.9.1", + "aria-query": "^5.0.0", + "chalk": "^3.0.0", + "css.escape": "^1.5.1", + "dom-accessibility-api": "^0.5.6", + "lodash": "^4.17.15", + "redent": "^3.0.0" + } + }, + "@testing-library/react": { + "version": "10.4.9", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-10.4.9.tgz", + "integrity": "sha512-pHZKkqUy0tmiD81afs8xfiuseXfU/N7rAX3iKjeZYje86t9VaB0LrxYVa+OOsvkrveX5jCK3IjajVn2MbePvqA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.10.3", + "@testing-library/dom": "^7.22.3" + } + }, "@theforeman/builder": { "version": "13.0.0", "resolved": "https://registry.npmjs.org/@theforeman/builder/-/builder-13.0.0.tgz", @@ -7412,6 +7426,55 @@ "yup": "^0.29.3" } }, + "@types/aria-query": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.2.tgz", + "integrity": "sha512-HnYpAE1Y6kRyKM/XkEuiRQhTHvkzMBurTHnpFLYLBGPIylZNPs9jJcuOOYWxPLJCSEtmZT0Y8rHDokKN7rRTig==", + "dev": true + }, + "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, + "requires": { + "color-convert": "^2.0.1" + } + }, + "aria-query": { + "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, + "requires": { + "dequal": "^2.0.3" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "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, + "requires": { + "color-name": "~1.1.4" + } + }, + "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 + }, "commander": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", @@ -7424,6 +7487,12 @@ "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", "dev": true }, + "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 + }, "react-diff-view": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/react-diff-view/-/react-diff-view-2.6.0.tgz", @@ -7441,6 +7510,15 @@ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", "dev": true + }, + "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, + "requires": { + "has-flag": "^4.0.0" + } } } }, @@ -7581,9 +7659,9 @@ "dev": true }, "@types/aria-query": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.2.tgz", - "integrity": "sha512-HnYpAE1Y6kRyKM/XkEuiRQhTHvkzMBurTHnpFLYLBGPIylZNPs9jJcuOOYWxPLJCSEtmZT0Y8rHDokKN7rRTig==", + "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 }, "@types/asap": { @@ -8185,6 +8263,15 @@ "csstype": "^3.0.2" } }, + "@types/react-dom": { + "version": "18.2.22", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.22.tgz", + "integrity": "sha512-fHkBXPeNtfvri6gdsMYyW+dW7RXFo6Ad09nLFK0VQWR7yGLai/Cyvyj696gbwYvBnhGtevUG9cET0pmUbMtoPQ==", + "dev": true, + "requires": { + "@types/react": "*" + } + }, "@types/react-redux": { "version": "7.1.33", "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.1.33.tgz", @@ -8848,13 +8935,46 @@ "optional": true }, "aria-query": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-4.2.2.tgz", - "integrity": "sha512-o/HelwhuKpTj/frsOsbNLNgnNGVIFsVP/SW2BSF14gVl7kAfMOJ6/8wUAUvG1R1NHKrfG+2sHZTu0yauT1qBrA==", + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.1.3.tgz", + "integrity": "sha512-R5iJ5lkuHybztUfuOAznmboyjWq8O6sqNqtK7CLOqdydi54VNbORp49mb14KbWgG1QD3JFO9hJdZ+y4KutfdOQ==", "dev": true, "requires": { - "@babel/runtime": "^7.10.2", - "@babel/runtime-corejs3": "^7.10.2" + "deep-equal": "^2.0.5" + }, + "dependencies": { + "deep-equal": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.3.tgz", + "integrity": "sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==", + "dev": true, + "requires": { + "array-buffer-byte-length": "^1.0.0", + "call-bind": "^1.0.5", + "es-get-iterator": "^1.1.3", + "get-intrinsic": "^1.2.2", + "is-arguments": "^1.1.1", + "is-array-buffer": "^3.0.2", + "is-date-object": "^1.0.5", + "is-regex": "^1.1.4", + "is-shared-array-buffer": "^1.0.2", + "isarray": "^2.0.5", + "object-is": "^1.1.5", + "object-keys": "^1.1.1", + "object.assign": "^4.1.4", + "regexp.prototype.flags": "^1.5.1", + "side-channel": "^1.0.4", + "which-boxed-primitive": "^1.0.2", + "which-collection": "^1.0.1", + "which-typed-array": "^1.1.13" + } + }, + "isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "dev": true + } } }, "arr-diff": { diff --git a/package.json b/package.json index 9af202a..1e966b8 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "lint": "tfm-lint --plugin -d /webpack", - "test": "tfm-test --config jest.config.js", + "test": "tfm-test --plugin --config jest.config.js", "test:watch": "tfm-test --plugin --watchAll", "test:current": "tfm-test --plugin --watch", "publish-coverage": "tfm-publish-coverage", @@ -27,7 +27,7 @@ "devDependencies": { "@babel/core": "^7.7.0", "@sheerun/mutationobserver-shim": "^0.3.3", - "@testing-library/react": "^10.4.9", + "@testing-library/react": "^14.2.2", "@theforeman/builder": "^10.1.3", "@theforeman/eslint-plugin-foreman": "13.0.0", "@theforeman/find-foreman": "^13.0.0", diff --git a/webpack/components/ResourceQuotaForm/components/Properties/StatusPropertiesLabel.test.js b/webpack/components/ResourceQuotaForm/components/Properties/StatusPropertiesLabel.test.js new file mode 100644 index 0000000..e70b0c5 --- /dev/null +++ b/webpack/components/ResourceQuotaForm/components/Properties/StatusPropertiesLabel.test.js @@ -0,0 +1,56 @@ +/* eslint-disable promise/prefer-await-to-then */ +// Configure Enzyme +import { mount } from '@theforeman/test'; +import React from 'react'; +import { Provider } from 'react-redux'; +import store from 'foremanReact/redux'; +import LabelIcon from 'foremanReact/components/common/LabelIcon'; +import StatusPropertiesLabel from './StatusPropertiesLabel'; + +// jest.mock('foremanReact/common/withReactRoutes', () => Component => props => ( +//
+// +//
+// )); + +const defaultProps = { + color: 'blue', + iconChild: , + statusContent: 'some content', + linkUrl: '/test/link', + tooltipText: 'Some nice tooltip', +}; + +describe('StatusPropertiesLabel', () => { + const wrapper = mount( + + + + ); + + it('includes components', () => { + expect(wrapper.find('Tooltip').exists()).toBe(true); + expect(wrapper.find('Tooltip')).toHaveLength(1); + expect(wrapper.find('Label').exists()).toBe(true); + expect(wrapper.find('Label')).toHaveLength(1); + expect(wrapper.find('Link').exists()).toBe(true); + expect(wrapper.find('Link')).toHaveLength(1); + }); + + it('passes properties', () => { + // ToolTip + const tooltip = wrapper.find('Tooltip'); + expect(tooltip.props()).toHaveProperty('content'); + expect(tooltip.prop('content')).toContain(defaultProps.tooltipText); + // Label + const label = wrapper.find('Label'); + expect(label.props()).toHaveProperty('icon'); + expect(label.prop('icon')).toEqual(defaultProps.iconChild); + expect(label.props()).toHaveProperty('color'); + expect(label.prop('color')).toEqual(defaultProps.color); + // Link + const link = wrapper.find('Link'); + expect(link.props()).toHaveProperty('to'); + expect(link.prop('to')).toEqual(defaultProps.linkUrl); + }); +}); diff --git a/webpack/lib/EditableTextInput/EditableTextInput.js b/webpack/lib/EditableTextInput/EditableTextInput.js index 9c9aea8..918cea9 100644 --- a/webpack/lib/EditableTextInput/EditableTextInput.js +++ b/webpack/lib/EditableTextInput/EditableTextInput.js @@ -58,16 +58,14 @@ const EditableTextInput = ({ setCurrentAttribute(attribute); }; - const onSubmit = async event => { - if (!event.shiftKey) { - setEditing(false); - if (isPassword) { - if (inputValue?.length > 0) { - setPasswordPlaceholder(PASSWORD_MASK); - } + const onSubmit = async () => { + setEditing(false); + if (isPassword) { + if (inputValue?.length > 0) { + setPasswordPlaceholder(PASSWORD_MASK); } - await onEdit(inputValue, attribute); } + await onEdit(inputValue, attribute); }; const onClear = () => { diff --git a/webpack/lib/EditableTextInput/__tests__/editableTextInput.test.js b/webpack/lib/EditableTextInput/__tests__/editableTextInput.test.js index 20a914f..d93671d 100644 --- a/webpack/lib/EditableTextInput/__tests__/editableTextInput.test.js +++ b/webpack/lib/EditableTextInput/__tests__/editableTextInput.test.js @@ -5,7 +5,7 @@ import { render, patientlyWaitFor, fireEvent, -} from './react-testing-lib-wrapper'; +} from '../../react-testing-lib-wrapper'; import EditableTextInput from '../EditableTextInput'; const actualValue = 'burger'; @@ -38,16 +38,16 @@ test('Passed function is called after editing and hitting enter', async () => { ); getByLabelText(`edit ${attribute}`).click(); - const textInputLabel = `${attribute} text input`; - fireEvent.change(getByLabelText(textInputLabel), { + const textInputLabel = getByLabelText(`${attribute} text input`); + fireEvent.change(textInputLabel, { target: { value: actualValue }, }); - fireEvent.keyUp(getByLabelText(textInputLabel), { + fireEvent.keyUp(textInputLabel, { key: 'Enter', code: 'Enter', }); - await patientlyWaitFor(() => expect(mockEdit.mock.calls).toHaveLength(1)); + expect(head(mockEdit.mock.calls)).toContain(actualValue); // first arg }); diff --git a/webpack/lib/EditableTextInput/__tests__/react-testing-lib-wrapper.js b/webpack/lib/react-testing-lib-wrapper.js similarity index 100% rename from webpack/lib/EditableTextInput/__tests__/react-testing-lib-wrapper.js rename to webpack/lib/react-testing-lib-wrapper.js