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 88f7013..f4e8aec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6895,17 +6895,18 @@ } }, "@testing-library/jest-dom": { - "version": "6.4.2", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.4.2.tgz", - "integrity": "sha512-CzqH0AFymEMG48CpzXFriYYkOjk6ZGPCLMhW9e9jg3KMCn5OfJecF8GtGW7yGfR/IgCe3SX8BSwjdzI6BBbZLw==", + "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.3.2", + "@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.6.3", + "dom-accessibility-api": "^0.5.6", "lodash": "^4.17.15", "redent": "^3.0.0" }, @@ -6953,12 +6954,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "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 - }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -7321,23 +7316,6 @@ "tslib": "^2.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" - } - }, "@theforeman/builder": { "version": "13.0.0", "resolved": "https://registry.npmjs.org/@theforeman/builder/-/builder-13.0.0.tgz", @@ -7434,49 +7412,6 @@ "yup": "^0.29.3" } }, - "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", @@ -7489,12 +7424,6 @@ "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", @@ -7512,15 +7441,6 @@ "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" - } } } }, diff --git a/package.json b/package.json index 107d4a9..880dee8 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "devDependencies": { "@babel/core": "^7.7.0", "@sheerun/mutationobserver-shim": "^0.3.3", - "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^10.4.9", "@theforeman/builder": "^10.1.3", "@theforeman/eslint-plugin-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..6574901 --- /dev/null +++ b/webpack/components/ResourceQuotaForm/components/Properties/StatusPropertiesLabel.test.js @@ -0,0 +1,50 @@ +/* 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'; + +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..a24b849 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,15 +38,14 @@ 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