From aae713e464d46213f6d260400cd02e43dd3c55e4 Mon Sep 17 00:00:00 2001 From: Syed Ali Abbas Zaidi Date: Thu, 18 Jan 2024 13:16:36 +0500 Subject: [PATCH 1/2] feat: migrate enzyme to react-unit-test-utils --- jest.config.js | 3 - package-lock.json | 326 +----------------- package.json | 5 +- src/App.test.jsx | 37 +- src/__snapshots__/App.test.jsx.snap | 4 +- .../BulkManagementAlerts.test.jsx | 30 +- .../HistoryTable.test.jsx | 12 +- .../ResultsSummary.test.jsx | 19 +- .../BulkManagementHistoryView/index.test.jsx | 21 +- src/components/EdxHeader/test.jsx | 4 +- .../AssignmentFilter/index.test.jsx | 6 +- .../AssignmentGradeFilter/index.test.jsx | 16 +- .../AssignmentTypeFilter/index.test.jsx | 6 +- .../CourseGradeFilter/index.test.jsx | 14 +- .../GradebookFilters/PercentGroup.test.jsx | 6 +- .../GradebookFilters/SelectGroup.test.jsx | 6 +- .../StudentGroupsFilter/index.test.jsx | 8 +- .../GradebookFilters/index.test.jsx | 16 +- src/components/GradebookHeader/index.test.jsx | 14 +- .../BulkManagementControls/index.test.jsx | 4 +- .../EditModal/HistoryHeader.test.jsx | 4 +- .../EditModal/ModalHeaders.test.jsx | 12 +- .../AdjustedGradeInput/index.test.jsx | 12 +- .../OverrideTable/ReasonInput/index.test.jsx | 10 +- .../EditModal/OverrideTable/index.test.jsx | 10 +- .../GradesView/EditModal/index.test.jsx | 60 ++-- .../GradesView/FilterBadges/FilterBadge.jsx | 4 +- .../FilterBadges/FilterBadge.test.jsx | 16 +- .../__snapshots__/FilterBadge.test.jsx.snap | 16 +- .../GradesView/FilterBadges/test.jsx | 12 +- .../FilterMenuToggle/index.test.jsx | 10 +- .../FilteredUsersLabel/index.test.jsx | 6 +- .../GradesView/GradebookTable/Fields.test.jsx | 25 +- .../GradebookTable/GradeButton.test.jsx | 14 +- .../GradebookTable/LabelReplacements.test.jsx | 14 +- .../__snapshots__/Fields.test.jsx.snap | 187 ++++++++-- .../GradesView/GradebookTable/hooks.test.jsx | 2 +- .../GradesView/GradebookTable/index.test.jsx | 12 +- .../ImportSuccessToast/index.test.jsx | 14 +- .../InterventionsReport/index.test.jsx | 6 +- .../GradesView/PageButtons/index.test.jsx | 20 +- .../GradesView/ScoreViewInput/index.test.jsx | 24 +- .../GradesView/SearchControls/index.test.jsx | 8 +- .../GradesView/SpinnerIcon.test.jsx | 4 +- .../GradesView/StatusAlerts/index.test.jsx | 16 +- src/components/GradesView/index.test.jsx | 6 +- src/components/NetworkButton/test.jsx | 14 +- .../WithSidebar/__snapshots__/test.jsx.snap | 4 +- src/components/WithSidebar/test.jsx | 22 +- .../GradebookPage/__snapshots__/test.jsx.snap | 6 +- src/containers/GradebookPage/test.jsx | 41 ++- src/head/Head.test.jsx | 14 +- src/setupTest.js | 7 - src/utils/hoc.test.jsx | 12 +- 54 files changed, 504 insertions(+), 697 deletions(-) diff --git a/jest.config.js b/jest.config.js index 4e02eec8..c736757d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,9 +5,6 @@ module.exports = createConfig('jest', { '/src/setupTest.js', ], modulePaths: ['/src/'], - snapshotSerializers: [ - 'enzyme-to-json/serializer', - ], coveragePathIgnorePatterns: [ 'src/segment.js', 'src/postcss.config.js', diff --git a/package-lock.json b/package-lock.json index 7e1ccaac..da7922f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@edx/frontend-component-header": "4.6.0", "@edx/frontend-platform": "5.5.4", "@edx/paragon": "20.45.0", - "@edx/react-unit-test-utils": "1.7.0", + "@edx/react-unit-test-utils": "1.7.1", "@edx/reactifex": "^2.1.1", "@fortawesome/fontawesome-svg-core": "^1.2.25", "@fortawesome/free-brands-svg-icons": "^5.11.2", @@ -25,8 +25,6 @@ "classnames": "^2.2.6", "core-js": "3.6.5", "email-prop-type": "^1.1.7", - "enzyme": "^3.10.0", - "enzyme-to-json": "^3.6.2", "font-awesome": "4.7.0", "history": "4.10.1", "prop-types": "15.8.1", @@ -51,7 +49,6 @@ "@edx/browserslist-config": "^1.1.1", "@edx/frontend-build": "13.0.1", "@testing-library/react": "12.1.5", - "@wojtekmaj/enzyme-adapter-react-17": "0.8.0", "axios": "0.21.2", "axios-mock-adapter": "^1.17.0", "es-check": "^2.3.0", @@ -2609,9 +2606,9 @@ } }, "node_modules/@edx/react-unit-test-utils": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/@edx/react-unit-test-utils/-/react-unit-test-utils-1.7.0.tgz", - "integrity": "sha512-wuUIelYGa9P5/n4+qDGevWH+cQS8iUOzTHpoc5yujqDED85i733U2Yt6cI+jSTAfQtCzPBn2pkGYdCLz5zL+hw==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/@edx/react-unit-test-utils/-/react-unit-test-utils-1.7.1.tgz", + "integrity": "sha512-EEMoy0SIZOpJAsrr8BNxW+ZL13UzqCw0z5MFNO1AGgElsUbiXiVY/ReRkstLJjf4CFiXro6mFhtKMFmz1Wg2cQ==", "dependencies": { "@edx/browserslist-config": "^1.1.1", "@edx/frontend-platform": "4.6.0", @@ -5655,14 +5652,6 @@ "@types/node": "*" } }, - "node_modules/@types/cheerio": { - "version": "0.22.31", - "resolved": "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.31.tgz", - "integrity": "sha512-Kt7Cdjjdi2XWSfrZ53v4Of0wG3ZcmaegFXjMmz9tfNrZSkzzo36G0AL1YqSdcIA78Etjt6E609pt5h1xnQkPUw==", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/connect": { "version": "3.4.36", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.36.tgz", @@ -6197,46 +6186,6 @@ } } }, - "node_modules/@wojtekmaj/enzyme-adapter-react-17": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@wojtekmaj/enzyme-adapter-react-17/-/enzyme-adapter-react-17-0.8.0.tgz", - "integrity": "sha512-zeUGfQRziXW7R7skzNuJyi01ZwuKCH8WiBNnTgUJwdS/CURrJwAhWsfW7nG7E30ak8Pu3ZwD9PlK9skBfAoOBw==", - "dev": true, - "dependencies": { - "@wojtekmaj/enzyme-adapter-utils": "^0.2.0", - "enzyme-shallow-equal": "^1.0.0", - "has": "^1.0.0", - "prop-types": "^15.7.0", - "react-is": "^17.0.0", - "react-test-renderer": "^17.0.0" - }, - "funding": { - "url": "https://github.com/wojtekmaj/enzyme-adapter-react-17?sponsor=1" - }, - "peerDependencies": { - "enzyme": "^3.0.0", - "react": "^17.0.0-0", - "react-dom": "^17.0.0-0" - } - }, - "node_modules/@wojtekmaj/enzyme-adapter-utils": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@wojtekmaj/enzyme-adapter-utils/-/enzyme-adapter-utils-0.2.0.tgz", - "integrity": "sha512-ZvZm9kZxZEKAbw+M1/Q3iDuqQndVoN8uLnxZ8bzxm7KgGTBejrGRoJAp8f1EN8eoO3iAjBNEQnTDW/H4Ekb0FQ==", - "dev": true, - "dependencies": { - "function.prototype.name": "^1.1.0", - "has": "^1.0.0", - "object.fromentries": "^2.0.0", - "prop-types": "^15.7.0" - }, - "funding": { - "url": "https://github.com/wojtekmaj/enzyme-adapter-utils?sponsor=1" - }, - "peerDependencies": { - "react": "^17.0.0-0" - } - }, "node_modules/@xtuc/ieee754": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", @@ -6610,24 +6559,6 @@ "node": ">=0.10.0" } }, - "node_modules/array.prototype.filter": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/array.prototype.filter/-/array.prototype.filter-1.0.2.tgz", - "integrity": "sha512-us+UrmGOilqttSOgoWZTpOvHu68vZT2YCjc/H4vhu56vzZpaDFBhB+Se2UwqWzMKbDv7Myq5M5pcZLAtUvTQdQ==", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.4", - "es-abstract": "^1.20.4", - "es-array-method-boxes-properly": "^1.0.0", - "is-string": "^1.0.7" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/array.prototype.flat": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz", @@ -7923,42 +7854,6 @@ "node": ">=10" } }, - "node_modules/cheerio": { - "version": "1.0.0-rc.12", - "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz", - "integrity": "sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==", - "dependencies": { - "cheerio-select": "^2.1.0", - "dom-serializer": "^2.0.0", - "domhandler": "^5.0.3", - "domutils": "^3.0.1", - "htmlparser2": "^8.0.1", - "parse5": "^7.0.0", - "parse5-htmlparser2-tree-adapter": "^7.0.0" - }, - "engines": { - "node": ">= 6" - }, - "funding": { - "url": "https://github.com/cheeriojs/cheerio?sponsor=1" - } - }, - "node_modules/cheerio-select": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", - "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", - "dependencies": { - "boolbase": "^1.0.0", - "css-select": "^5.1.0", - "css-what": "^6.1.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3", - "domutils": "^3.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, "node_modules/chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", @@ -9437,11 +9332,6 @@ "node": ">=8" } }, - "node_modules/discontinuous-range": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", - "integrity": "sha512-c68LpLbO+7kP/b1Hr1qs8/BJ09F5khZGTxqxZuhzxpmwJKOgRFHJWIb9/KmqnqHhLdO55aOxFH/EGBvUQbL/RQ==" - }, "node_modules/dns-equal": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/dns-equal/-/dns-equal-1.0.0.tgz", @@ -9814,71 +9704,6 @@ "node": ">=4" } }, - "node_modules/enzyme": { - "version": "3.11.0", - "resolved": "https://registry.npmjs.org/enzyme/-/enzyme-3.11.0.tgz", - "integrity": "sha512-Dw8/Gs4vRjxY6/6i9wU0V+utmQO9kvh9XLnz3LIudviOnVYDEe2ec+0k+NQoMamn1VrjKgCUOWj5jG/5M5M0Qw==", - "dependencies": { - "array.prototype.flat": "^1.2.3", - "cheerio": "^1.0.0-rc.3", - "enzyme-shallow-equal": "^1.0.1", - "function.prototype.name": "^1.1.2", - "has": "^1.0.3", - "html-element-map": "^1.2.0", - "is-boolean-object": "^1.0.1", - "is-callable": "^1.1.5", - "is-number-object": "^1.0.4", - "is-regex": "^1.0.5", - "is-string": "^1.0.5", - "is-subset": "^0.1.1", - "lodash.escape": "^4.0.1", - "lodash.isequal": "^4.5.0", - "object-inspect": "^1.7.0", - "object-is": "^1.0.2", - "object.assign": "^4.1.0", - "object.entries": "^1.1.1", - "object.values": "^1.1.1", - "raf": "^3.4.1", - "rst-selector-parser": "^2.2.3", - "string.prototype.trim": "^1.2.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/enzyme-shallow-equal": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/enzyme-shallow-equal/-/enzyme-shallow-equal-1.0.5.tgz", - "integrity": "sha512-i6cwm7hN630JXenxxJFBKzgLC3hMTafFQXflvzHgPmDhOBhxUWDe8AeRv1qp2/uWJ2Y8z5yLWMzmAfkTOiOCZg==", - "dependencies": { - "has": "^1.0.3", - "object-is": "^1.1.5" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/enzyme-to-json": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/enzyme-to-json/-/enzyme-to-json-3.6.2.tgz", - "integrity": "sha512-Ynm6Z6R6iwQ0g2g1YToz6DWhxVnt8Dy1ijR2zynRKxTyBGA8rCDXU3rs2Qc4OKvUvc2Qoe1bcFK6bnPs20TrTg==", - "dependencies": { - "@types/cheerio": "^0.22.22", - "lodash": "^4.17.21", - "react-is": "^16.12.0" - }, - "engines": { - "node": ">=6.0.0" - }, - "peerDependencies": { - "enzyme": "^3.4.0" - } - }, - "node_modules/enzyme-to-json/node_modules/react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" - }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -9947,11 +9772,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/es-array-method-boxes-properly": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-array-method-boxes-properly/-/es-array-method-boxes-properly-1.0.0.tgz", - "integrity": "sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==" - }, "node_modules/es-check": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/es-check/-/es-check-2.3.0.tgz", @@ -12553,18 +12373,6 @@ "wbuf": "^1.1.0" } }, - "node_modules/html-element-map": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/html-element-map/-/html-element-map-1.3.1.tgz", - "integrity": "sha512-6XMlxrAFX4UEEGxctfFnmrFaaZFNf9i5fNuV5wZ3WWQ4FVaNP1aX1LkX9j2mfEx1NpjeE/rL3nmgEn23GdFmrg==", - "dependencies": { - "array.prototype.filter": "^1.0.0", - "call-bind": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/html-encoding-sniffer": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz", @@ -12646,24 +12454,6 @@ "webpack": "^5.20.0" } }, - "node_modules/htmlparser2": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz", - "integrity": "sha512-GYdjWKDkbRLkZ5geuHs5NY1puJ+PXwP7+fHPRz06Eirsb9ugf6d8kkXav6ADhcODhFFPMIXyxkxSuMf3D6NCFA==", - "funding": [ - "https://github.com/fb55/htmlparser2?sponsor=1", - { - "type": "github", - "url": "https://github.com/sponsors/fb55" - } - ], - "dependencies": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3", - "domutils": "^3.0.1", - "entities": "^4.4.0" - } - }, "node_modules/http-deceiver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz", @@ -13804,11 +13594,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-subset": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz", - "integrity": "sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==" - }, "node_modules/is-symbol": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", @@ -16878,21 +16663,11 @@ "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", "integrity": "sha512-C5N2Z3DgnnKr0LOpv/hKCgKdb7ZZwafIrsesve6lmzvZIRZRGaZ/l6Q8+2W7NaT+ZwO3fFlSCzCzrDCFdJfZ4g==" }, - "node_modules/lodash.flattendeep": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", - "integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==" - }, "node_modules/lodash.invokemap": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.invokemap/-/lodash.invokemap-4.6.0.tgz", "integrity": "sha512-CfkycNtMqgUlfjfdh2BhKO/ZXrP8ePOX5lEU/g0R3ItJcnuxWDwokMGKx1hWcfOikmyOVx6X9IwWnDGlgKl61w==" }, - "node_modules/lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==" - }, "node_modules/lodash.ismatch": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz", @@ -17491,11 +17266,6 @@ "node": ">=0.10.0" } }, - "node_modules/moo": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz", - "integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==" - }, "node_modules/mrmime": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-1.0.1.tgz", @@ -17575,32 +17345,6 @@ "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==" }, - "node_modules/nearley": { - "version": "2.20.1", - "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.20.1.tgz", - "integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==", - "dependencies": { - "commander": "^2.19.0", - "moo": "^0.5.0", - "railroad-diagrams": "^1.0.0", - "randexp": "0.4.6" - }, - "bin": { - "nearley-railroad": "bin/nearley-railroad.js", - "nearley-test": "bin/nearley-test.js", - "nearley-unparse": "bin/nearley-unparse.js", - "nearleyc": "bin/nearleyc.js" - }, - "funding": { - "type": "individual", - "url": "https://nearley.js.org/#give-to-nearley" - } - }, - "node_modules/nearley/node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" - }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -20942,29 +20686,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/parse5": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", - "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", - "dependencies": { - "entities": "^4.4.0" - }, - "funding": { - "url": "https://github.com/inikulin/parse5?sponsor=1" - } - }, - "node_modules/parse5-htmlparser2-tree-adapter": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", - "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", - "dependencies": { - "domhandler": "^5.0.2", - "parse5": "^7.0.0" - }, - "funding": { - "url": "https://github.com/inikulin/parse5?sponsor=1" - } - }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -21038,11 +20759,6 @@ "node": ">=8" } }, - "node_modules/performance-now": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", - "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" - }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -22248,31 +21964,6 @@ "node": ">=8" } }, - "node_modules/raf": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", - "integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==", - "dependencies": { - "performance-now": "^2.1.0" - } - }, - "node_modules/railroad-diagrams": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", - "integrity": "sha512-cz93DjNeLY0idrCNOH6PviZGRN9GJhsdm9hpn1YCS879fj4W+x5IFJhhkRZcwVgMmFF7R82UA/7Oh+R8lLZg6A==" - }, - "node_modules/randexp": { - "version": "0.4.6", - "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", - "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", - "dependencies": { - "discontinuous-range": "1.0.0", - "ret": "~0.1.10" - }, - "engines": { - "node": ">=0.12" - } - }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -23609,15 +23300,6 @@ "rimraf": "bin.js" } }, - "node_modules/rst-selector-parser": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz", - "integrity": "sha512-nDG1rZeP6oFTLN6yNDV/uiAvs1+FS/KlrEwh7+y7dpuApDBy6bI2HTBcc0/V8lv9OTqfyD34eF7au2pm8aBbhA==", - "dependencies": { - "lodash.flattendeep": "^4.4.0", - "nearley": "^2.7.10" - } - }, "node_modules/rsvp": { "version": "4.8.5", "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz", diff --git a/package.json b/package.json index 498a6a22..ec30edaf 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@edx/frontend-component-header": "4.6.0", "@edx/frontend-platform": "5.5.4", "@edx/paragon": "20.45.0", - "@edx/react-unit-test-utils": "1.7.0", + "@edx/react-unit-test-utils": "1.7.1", "@edx/reactifex": "^2.1.1", "@fortawesome/fontawesome-svg-core": "^1.2.25", "@fortawesome/free-brands-svg-icons": "^5.11.2", @@ -44,8 +44,6 @@ "classnames": "^2.2.6", "core-js": "3.6.5", "email-prop-type": "^1.1.7", - "enzyme": "^3.10.0", - "enzyme-to-json": "^3.6.2", "font-awesome": "4.7.0", "history": "4.10.1", "prop-types": "15.8.1", @@ -70,7 +68,6 @@ "@edx/browserslist-config": "^1.1.1", "@edx/frontend-build": "13.0.1", "@testing-library/react": "12.1.5", - "@wojtekmaj/enzyme-adapter-react-17": "0.8.0", "axios": "0.21.2", "axios-mock-adapter": "^1.17.0", "es-check": "^2.3.0", diff --git a/src/App.test.jsx b/src/App.test.jsx index 79fbff88..c2a3a5f4 100644 --- a/src/App.test.jsx +++ b/src/App.test.jsx @@ -1,21 +1,19 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; -import { Route, Routes } from 'react-router-dom'; -import { AppProvider } from '@edx/frontend-platform/react'; +import { Route } from 'react-router-dom'; import Footer from '@edx/frontend-component-footer'; -import Header from '@edx/frontend-component-header'; import store from 'data/store'; import GradebookPage from 'containers/GradebookPage'; import App from './App'; -import Head from './head/Head'; jest.mock('react-router-dom', () => ({ BrowserRouter: () => 'BrowserRouter', Route: () => 'Route', + Routes: () => 'Routes', })); jest.mock('@edx/frontend-platform/react', () => ({ AppProvider: () => 'AppProvider', @@ -24,6 +22,7 @@ jest.mock('@edx/frontend-component-footer', () => 'Footer'); jest.mock('data/store', () => 'testStore'); jest.mock('containers/GradebookPage', () => 'GradebookPage'); jest.mock('@edx/frontend-component-header', () => 'Header'); +jest.mock('./head/Head', () => 'Head'); const logo = 'fakeLogo.png'; let el; @@ -31,45 +30,41 @@ let secondChild; describe('App router component', () => { test('snapshot', () => { - expect(shallow()).toMatchSnapshot(); + expect(shallow().snapshot).toMatchSnapshot(); }); describe('component', () => { beforeEach(() => { process.env.LOGO_POWERED_BY_OPEN_EDX_URL_SVG = logo; el = shallow(); - secondChild = el.childAt(1); + secondChild = el.instance.children; }); describe('AppProvider', () => { test('AppProvider is the parent component, passed the redux store props', () => { - expect(el.type()).toBe(AppProvider); - expect(el.props().store).toEqual(store); + expect(el.instance.type).toBe('AppProvider'); + expect(el.instance.props.store).toEqual(store); }); }); describe('Head', () => { test('first child of AppProvider', () => { - expect(el.childAt(0).type()).toBe(Head); + expect(el.instance.children[0].type).toBe('Head'); }); }); describe('Router', () => { test('second child of AppProvider', () => { - expect(secondChild.type()).toBe('div'); + expect(secondChild[1].type).toBe('div'); }); test('Header is above/outside-of the routing', () => { - expect(secondChild.childAt(0).type()).toBe(Header); - expect(secondChild.childAt(1).type()).toBe('main'); + expect(secondChild[1].children[0].type).toBe('Header'); + expect(secondChild[1].children[1].type).toBe('main'); }); test('Routing - GradebookPage is only route', () => { - expect(secondChild.find('main')).toEqual(shallow( -
- - } /> - -
, - )); + expect(secondChild[1].findByType(Route)).toHaveLength(1); + expect(secondChild[1].findByType(Route)[0].props.path).toEqual('/:courseId'); + expect(secondChild[1].findByType(Route)[0].props.element.type).toEqual(GradebookPage); }); }); test('Footer logo drawn from env variable', () => { - expect(secondChild.find(Footer).props().logo).toEqual(logo); + expect(secondChild[1].findByType(Footer)[0].props.logo).toEqual(logo); }); }); }); diff --git a/src/__snapshots__/App.test.jsx.snap b/src/__snapshots__/App.test.jsx.snap index 8f8ccf73..1dd88d5f 100644 --- a/src/__snapshots__/App.test.jsx.snap +++ b/src/__snapshots__/App.test.jsx.snap @@ -8,12 +8,12 @@ exports[`App router component snapshot 1`] = `
- + } path="/:courseId" /> - +
diff --git a/src/components/BulkManagementHistoryView/BulkManagementAlerts.test.jsx b/src/components/BulkManagementHistoryView/BulkManagementAlerts.test.jsx index 51a2794f..cdd468cf 100644 --- a/src/components/BulkManagementHistoryView/BulkManagementAlerts.test.jsx +++ b/src/components/BulkManagementHistoryView/BulkManagementAlerts.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { Alert } from '@edx/paragon'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; @@ -35,17 +35,17 @@ describe('BulkManagementAlerts', () => { el = shallow(); }); test('snapshot - bulkImportError closed, success closed', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('closed danger alert', () => { - expect(el.childAt(0).is(Alert)).toEqual(true); - expect(el.childAt(0).props().show).toEqual(false); - expect(el.childAt(0).props().variant).toEqual('danger'); + expect(el.shallowWrapper.props.children[0].type).toBe(Alert); + expect(el.instance.findByType(Alert)[0].props.show).toEqual(false); + expect(el.instance.findByType(Alert)[0].props.variant).toEqual('danger'); }); test('closed success alert', () => { - expect(el.childAt(1).is(Alert)).toEqual(true); - expect(el.childAt(1).props().show).toEqual(false); - expect(el.childAt(1).props().variant).toEqual('success'); + expect(el.shallowWrapper.props.children[1].type).toBe(Alert); + expect(el.instance.findByType(Alert)[1].props.show).toEqual(false); + expect(el.instance.findByType(Alert)[1].props.variant).toEqual('success'); }); }); describe('no errer, no upload success', () => { @@ -57,19 +57,19 @@ describe('BulkManagementAlerts', () => { 'success alert open with messages.successDialog', ]; test(`snapshot - ${assertions.join(', ')}`, () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('open danger alert with bulkImportError content', () => { - expect(el.childAt(0).is(Alert)).toEqual(true); - expect(el.childAt(0).children().text()).toEqual(errorMessage); - expect(el.childAt(0).props().show).toEqual(true); + expect(el.shallowWrapper.props.children[0].type).toBe(Alert); + expect(el.instance.findByType(Alert)[0].children[0].el).toEqual(errorMessage); + expect(el.instance.findByType(Alert)[0].props.show).toEqual(true); }); test('open success alert with messages.successDialog content', () => { - expect(el.childAt(1).is(Alert)).toEqual(true); - expect(el.childAt(1).children().getElement()).toEqual( + expect(el.shallowWrapper.props.children[1].type).toBe(Alert); + expect(el.shallowWrapper.props.children[1].props.children).toEqual( , ); - expect(el.childAt(1).props().show).toEqual(true); + expect(el.shallowWrapper.props.children[1].props.show).toEqual(true); }); }); }); diff --git a/src/components/BulkManagementHistoryView/HistoryTable.test.jsx b/src/components/BulkManagementHistoryView/HistoryTable.test.jsx index 96f5ec44..2a9dd956 100644 --- a/src/components/BulkManagementHistoryView/HistoryTable.test.jsx +++ b/src/components/BulkManagementHistoryView/HistoryTable.test.jsx @@ -1,6 +1,6 @@ /* eslint-disable import/no-named-as-default */ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { DataTable } from '@edx/paragon'; import selectors from 'data/selectors'; @@ -56,12 +56,12 @@ describe('HistoryTable', () => { el = shallow(); }); test('snapshot - loads formatted table', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); describe('history table', () => { let table; beforeEach(() => { - table = el.find(DataTable); + table = el.instance.findByType(DataTable); }); describe('data (from bulkManagementHistory.map(this.formatHistoryRow)', () => { const fieldAssertions = [ @@ -70,10 +70,10 @@ describe('HistoryTable', () => { 'forwards the rest', ]; test(`snapshot: ${fieldAssertions.join(', ')}`, () => { - expect(table.props().data).toMatchSnapshot(); + expect(table[0].props.data).toMatchSnapshot(); }); test(fieldAssertions.join(', '), () => { - const rows = table.props().data; + const rows = table[0].props.data; expect(rows[0].resultsSummary).toEqual(); expect(rows[0].user).toEqual({entry1.user}); expect( @@ -87,7 +87,7 @@ describe('HistoryTable', () => { }); }); test('columns from bulkManagementColumns', () => { - expect(table.props().columns).toEqual(bulkManagementColumns); + expect(table[0].props.columns).toEqual(bulkManagementColumns); }); }); }); diff --git a/src/components/BulkManagementHistoryView/ResultsSummary.test.jsx b/src/components/BulkManagementHistoryView/ResultsSummary.test.jsx index 268a71e0..4d658ead 100644 --- a/src/components/BulkManagementHistoryView/ResultsSummary.test.jsx +++ b/src/components/BulkManagementHistoryView/ResultsSummary.test.jsx @@ -1,7 +1,6 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; -import { Icon } from '@edx/paragon'; import { Download } from '@edx/paragon/icons'; import lms from 'data/services/lms'; @@ -35,19 +34,19 @@ describe('ResultsSummary component', () => { el = shallow(); }); test(`snapshot - ${assertions.join(', ')}`, () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('Hyperlink has target="_blank" and rel="noopener noreferrer"', () => { - expect(el.props().target).toEqual('_blank'); - expect(el.props().rel).toEqual('noopener noreferrer'); + expect(el.instance.props.target).toEqual('_blank'); + expect(el.instance.props.rel).toEqual('noopener noreferrer'); }); test('Hyperlink has href to bulkGradesUrl', () => { - expect(el.props().href).toEqual(lms.urls.bulkGradesUrlByRow(props.rowId)); + expect(el.instance.props.href).toEqual(lms.urls.bulkGradesUrlByRow(props.rowId)); }); test('displays Download Icon and text', () => { - const icon = el.childAt(0); - expect(icon.is(Icon)).toEqual(true); - expect(icon.props().src).toEqual(Download); - expect(el.childAt(1).text()).toEqual(props.text); + const icon = el.instance.children[0]; + expect(icon.type).toEqual('Icon'); + expect(icon.props.src).toEqual(Download); + expect(el.instance.children[1].el).toEqual(props.text); }); }); diff --git a/src/components/BulkManagementHistoryView/index.test.jsx b/src/components/BulkManagementHistoryView/index.test.jsx index 5ada740e..c6071363 100644 --- a/src/components/BulkManagementHistoryView/index.test.jsx +++ b/src/components/BulkManagementHistoryView/index.test.jsx @@ -1,6 +1,6 @@ /* eslint-disable import/no-named-as-default */ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; import { BulkManagementHistoryView } from '.'; @@ -24,20 +24,23 @@ describe('BulkManagementHistoryView', () => { '', ]; test(`snapshot - loads ${snapshotSegments.join(', ')}`, () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('heading - h4 loaded from messages', () => { - const heading = el.find('h4'); - expect(heading.getElement()).toEqual(( + const heading = el.instance.findByType('h4')[0]; + const expectedHeading = shallow(

-

- )); + , + ); + + expect(heading.el.type).toEqual(expectedHeading.type); + expect(heading.el.props).toEqual(expectedHeading.props); }); test('heading, then alerts, then upload form, then table', () => { - expect(el.childAt(0).is('h4')).toEqual(true); - expect(el.childAt(2).is(BulkManagementAlerts)).toEqual(true); - expect(el.childAt(3).is(HistoryTable)).toEqual(true); + expect(el.instance.children[0].type).toEqual('h4'); + expect(el.instance.children[2].type).toEqual(BulkManagementAlerts); + expect(el.instance.children[3].type).toEqual(HistoryTable); }); }); }); diff --git a/src/components/EdxHeader/test.jsx b/src/components/EdxHeader/test.jsx index 75ac944c..d5806e63 100644 --- a/src/components/EdxHeader/test.jsx +++ b/src/components/EdxHeader/test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { getConfig } from '@edx/frontend-platform'; @@ -16,6 +16,6 @@ describe('Header', () => { test('snapshot - has edx link with logo url', () => { const url = 'www.ourLogo.url'; getConfig.mockReturnValue({ LOGO_URL: url }); - expect(shallow(
)).toMatchSnapshot(); + expect(shallow(
).snapshot).toMatchSnapshot(); }); }); diff --git a/src/components/GradebookFilters/AssignmentFilter/index.test.jsx b/src/components/GradebookFilters/AssignmentFilter/index.test.jsx index ceec6358..1c5e8a70 100644 --- a/src/components/GradebookFilters/AssignmentFilter/index.test.jsx +++ b/src/components/GradebookFilters/AssignmentFilter/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import SelectGroup from '../SelectGroup'; @@ -38,10 +38,10 @@ describe('AssignmentFilter component', () => { }); describe('render', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('filter options', () => { - const { options } = el.find(SelectGroup).props(); + const { options } = el.instance.findByType(SelectGroup)[0].props; expect(options.length).toEqual(5); const testOption = assignmentFilterOptions[0]; const optionProps = options[1].props; diff --git a/src/components/GradebookFilters/AssignmentGradeFilter/index.test.jsx b/src/components/GradebookFilters/AssignmentGradeFilter/index.test.jsx index 332da15e..be5d12b0 100644 --- a/src/components/GradebookFilters/AssignmentGradeFilter/index.test.jsx +++ b/src/components/GradebookFilters/AssignmentGradeFilter/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import { Button } from '@edx/paragon'; @@ -37,20 +37,20 @@ describe('AssignmentFilter component', () => { describe('render', () => { describe('with selected assignment', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); it('renders a PercentGroup for both Max and Min filters', () => { - let props = el.find(PercentGroup).at(0).props(); + let { props } = el.instance.findByType(PercentGroup)[0]; expect(props.value).toEqual(hookData.assignmentGradeMin); expect(props.disabled).toEqual(false); expect(props.onChange).toEqual(hookData.handleSetMin); - props = el.find(PercentGroup).at(1).props(); + props = el.instance.findByType(PercentGroup)[1].props; expect(props.value).toEqual(hookData.assignmentGradeMax); expect(props.disabled).toEqual(false); expect(props.onChange).toEqual(hookData.handleSetMax); }); it('renders a submit button', () => { - const props = el.find(Button).props(); + const { props } = el.instance.findByType(Button)[0]; expect(props.disabled).toEqual(false); expect(props.onClick).toEqual(hookData.handleSubmit); }); @@ -64,12 +64,12 @@ describe('AssignmentFilter component', () => { el = shallow(); }); test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); it('disables controls', () => { - let props = el.find(PercentGroup).at(0).props(); + let { props } = el.instance.findByType(PercentGroup)[0]; expect(props.disabled).toEqual(true); - props = el.find(PercentGroup).at(1).props(); + props = el.instance.findByType(PercentGroup)[1].props; expect(props.disabled).toEqual(true); }); }); diff --git a/src/components/GradebookFilters/AssignmentTypeFilter/index.test.jsx b/src/components/GradebookFilters/AssignmentTypeFilter/index.test.jsx index b1a9cb0a..7486bdce 100644 --- a/src/components/GradebookFilters/AssignmentTypeFilter/index.test.jsx +++ b/src/components/GradebookFilters/AssignmentTypeFilter/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import SelectGroup from '../SelectGroup'; @@ -34,10 +34,10 @@ describe('AssignmentFilterType component', () => { }); describe('render', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('filter options', () => { - const { options } = el.find(SelectGroup).props(); + const { options } = el.instance.findByType(SelectGroup)[0].props; expect(options.length).toEqual(5); const optionProps = options[1].props; expect(optionProps.value).toEqual(assignmentTypes[0]); diff --git a/src/components/GradebookFilters/CourseGradeFilter/index.test.jsx b/src/components/GradebookFilters/CourseGradeFilter/index.test.jsx index 881cb218..a707d7c7 100644 --- a/src/components/GradebookFilters/CourseGradeFilter/index.test.jsx +++ b/src/components/GradebookFilters/CourseGradeFilter/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import { Button } from '@edx/paragon'; @@ -42,18 +42,18 @@ describe('CourseFilter component', () => { describe('render', () => { describe('with selected assignment', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); it('renders a PercentGroup for both Max and Min filters', () => { - let props = el.find(PercentGroup).at(0).props(); + let { props } = el.instance.findByType(PercentGroup)[0]; expect(props.value).toEqual(hookData.min.value); expect(props.onChange).toEqual(hookData.min.onChange); - props = el.find(PercentGroup).at(1).props(); + props = el.instance.findByType(PercentGroup)[1].props; expect(props.value).toEqual(hookData.max.value); expect(props.onChange).toEqual(hookData.max.onChange); }); it('renders a submit button', () => { - const props = el.find(Button).props(); + const { props } = el.instance.findByType(Button)[0]; expect(props.disabled).toEqual(false); expect(props.onClick).toEqual(hookData.handleApplyClick); }); @@ -64,10 +64,10 @@ describe('CourseFilter component', () => { el = shallow(); }); test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); it('disables submit', () => { - const props = el.find(Button).props(); + const { props } = el.instance.findByType(Button)[0]; expect(props.disabled).toEqual(true); }); }); diff --git a/src/components/GradebookFilters/PercentGroup.test.jsx b/src/components/GradebookFilters/PercentGroup.test.jsx index 023e17d5..dad676d1 100644 --- a/src/components/GradebookFilters/PercentGroup.test.jsx +++ b/src/components/GradebookFilters/PercentGroup.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import PercentGroup from './PercentGroup'; @@ -22,11 +22,11 @@ describe('PercentGroup', () => { describe('snapshots', () => { test('basic snapshot', () => { const el = shallow(); - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('disabled', () => { const el = shallow(); - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); }); }); diff --git a/src/components/GradebookFilters/SelectGroup.test.jsx b/src/components/GradebookFilters/SelectGroup.test.jsx index 5c991269..fd1bbb16 100644 --- a/src/components/GradebookFilters/SelectGroup.test.jsx +++ b/src/components/GradebookFilters/SelectGroup.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import SelectGroup from './SelectGroup'; @@ -27,11 +27,11 @@ describe('SelectGroup', () => { describe('snapshots', () => { test('basic snapshot', () => { const el = shallow(); - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('disabled', () => { const el = shallow(); - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); }); }); diff --git a/src/components/GradebookFilters/StudentGroupsFilter/index.test.jsx b/src/components/GradebookFilters/StudentGroupsFilter/index.test.jsx index ee339d4a..7f2fa529 100644 --- a/src/components/GradebookFilters/StudentGroupsFilter/index.test.jsx +++ b/src/components/GradebookFilters/StudentGroupsFilter/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import SelectGroup from '../SelectGroup'; @@ -48,14 +48,14 @@ describe('StudentGroupsFilter component', () => { }); describe('render', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('track options', () => { const { options, onChange, value, - } = el.find(SelectGroup).at(0).props(); + } = el.instance.findByType(SelectGroup)[0].props; expect(value).toEqual(props.tracks.value); expect(onChange).toEqual(props.tracks.handleChange); expect(options.length).toEqual(5); @@ -70,7 +70,7 @@ describe('StudentGroupsFilter component', () => { onChange, disabled, value, - } = el.find(SelectGroup).at(1).props(); + } = el.instance.findByType(SelectGroup)[1].props; expect(value).toEqual(props.cohorts.value); expect(disabled).toEqual(false); expect(onChange).toEqual(props.cohorts.handleChange); diff --git a/src/components/GradebookFilters/index.test.jsx b/src/components/GradebookFilters/index.test.jsx index be5235a4..2fe26257 100644 --- a/src/components/GradebookFilters/index.test.jsx +++ b/src/components/GradebookFilters/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import { Collapsible } from '@edx/paragon'; @@ -49,10 +49,10 @@ describe('GradebookFilters', () => { }); describe('render', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('Assignment filters', () => { - expect(el.find(Collapsible).at(0).children()).toMatchObject(shallow( + expect(el.instance.findByType(Collapsible)[0].children[0]).toMatchObject(shallow(
@@ -61,22 +61,22 @@ describe('GradebookFilters', () => { )); }); test('CourseGrade filters', () => { - expect(el.find(Collapsible).at(1).children()).toMatchObject(shallow( + expect(el.instance.findByType(Collapsible)[1].children[0]).toMatchObject(shallow( , )); }); test('StudentGroups filters', () => { - expect(el.find(Collapsible).at(2).children()).toMatchObject(shallow( + expect(el.instance.findByType(Collapsible)[2].children[0]).toMatchObject(shallow( , )); }); test('includeCourseTeamMembers', () => { - const checkbox = el.find(Collapsible).at(3).children(); - expect(checkbox.props()).toEqual({ + const checkbox = el.instance.findByType(Collapsible)[3].children[0]; + expect(checkbox.props).toEqual({ checked: true, onChange: hookProps.includeCourseTeamMembers.handleChange, - children: formatMessage(messages.includeCourseTeamMembers), }); + expect(checkbox.children[0].el).toEqual(formatMessage(messages.includeCourseTeamMembers)); }); }); }); diff --git a/src/components/GradebookHeader/index.test.jsx b/src/components/GradebookHeader/index.test.jsx index 369bdbb4..071f1683 100644 --- a/src/components/GradebookHeader/index.test.jsx +++ b/src/components/GradebookHeader/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import { Button } from '@edx/paragon'; @@ -40,7 +40,7 @@ describe('GradebookHeader component', () => { describe('render', () => { describe('default view', () => { test('shapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); }); describe('show bulk management', () => { @@ -49,10 +49,10 @@ describe('GradebookHeader component', () => { el = shallow(); }); test('snapshot: show toggle view message button with handleToggleViewClick method', () => { - expect(el).toMatchSnapshot(); - const { onClick, children } = el.find(Button).props(); + expect(el.snapshot).toMatchSnapshot(); + const { onClick } = el.instance.findByType(Button)[0].props; expect(onClick).toEqual(hookProps.handleToggleViewClick); - expect(children).toEqual(formatMessage(hookProps.toggleViewMessage)); + expect(el.instance.findByType(Button)[0].children[0].el).toEqual(formatMessage(hookProps.toggleViewMessage)); }); }); describe('frozen grades', () => { @@ -61,7 +61,7 @@ describe('GradebookHeader component', () => { el = shallow(); }); test('snapshot: show frozen warning', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); }); describe('user cannot view gradebook', () => { @@ -70,7 +70,7 @@ describe('GradebookHeader component', () => { el = shallow(); }); test('snapshot: show unauthorized warning', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); }); }); diff --git a/src/components/GradesView/BulkManagementControls/index.test.jsx b/src/components/GradesView/BulkManagementControls/index.test.jsx index e5e3ca65..3a7ca391 100644 --- a/src/components/GradesView/BulkManagementControls/index.test.jsx +++ b/src/components/GradesView/BulkManagementControls/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import useBulkManagementControlsData from './hooks'; import BulkManagementControls from '.'; @@ -22,7 +22,7 @@ describe('BulkManagementControls', () => { }); describe('render', () => { test('snapshot - show - network and import buttons', () => { - expect(shallow()).toMatchSnapshot(); + expect(shallow().snapshot).toMatchSnapshot(); }); test('snapshot - empty if show is not truthy', () => { useBulkManagementControlsData.mockReturnValueOnce({ ...hookProps, show: false }); diff --git a/src/components/GradesView/EditModal/HistoryHeader.test.jsx b/src/components/GradesView/EditModal/HistoryHeader.test.jsx index 89e70796..63b28650 100644 --- a/src/components/GradesView/EditModal/HistoryHeader.test.jsx +++ b/src/components/GradesView/EditModal/HistoryHeader.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import HistoryHeader from './HistoryHeader'; @@ -11,7 +11,7 @@ describe('HistoryHeader', () => { }; describe('Component', () => { test('snapshot', () => { - expect(shallow()).toMatchSnapshot(); + expect(shallow().snapshot).toMatchSnapshot(); }); }); }); diff --git a/src/components/GradesView/EditModal/ModalHeaders.test.jsx b/src/components/GradesView/EditModal/ModalHeaders.test.jsx index 382eb6a8..14d5ffe8 100644 --- a/src/components/GradesView/EditModal/ModalHeaders.test.jsx +++ b/src/components/GradesView/EditModal/ModalHeaders.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { useIntl } from '@edx/frontend-platform/i18n'; import { selectors } from 'data/redux/hooks'; @@ -47,10 +47,10 @@ describe('ModalHeaders', () => { }); describe('render', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); test('assignment header', () => { - const headerProps = el.find(HistoryHeader).at(0).props(); + const headerProps = el.instance.findByType(HistoryHeader)[0].props; expect(headerProps).toMatchObject({ id: HistoryKeys.assignment, label: formatMessage(messages.assignmentHeader), @@ -58,7 +58,7 @@ describe('ModalHeaders', () => { }); }); test('student header', () => { - const headerProps = el.find(HistoryHeader).at(1).props(); + const headerProps = el.instance.findByType(HistoryHeader)[1].props; expect(headerProps).toMatchObject({ id: HistoryKeys.student, label: formatMessage(messages.studentHeader), @@ -66,7 +66,7 @@ describe('ModalHeaders', () => { }); }); test('originalGrade header', () => { - const headerProps = el.find(HistoryHeader).at(2).props(); + const headerProps = el.instance.findByType(HistoryHeader)[2].props; expect(headerProps).toMatchObject({ id: HistoryKeys.originalGrade, label: formatMessage(messages.originalGradeHeader), @@ -74,7 +74,7 @@ describe('ModalHeaders', () => { }); }); test('currentGrade header', () => { - const headerProps = el.find(HistoryHeader).at(3).props(); + const headerProps = el.instance.findByType(HistoryHeader)[3].props; expect(headerProps).toMatchObject({ id: HistoryKeys.currentGrade, label: formatMessage(messages.currentGradeHeader), diff --git a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.test.jsx b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.test.jsx index 895dc6ff..2e5248d1 100644 --- a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.test.jsx +++ b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { Form } from '@edx/paragon'; @@ -28,11 +28,11 @@ describe('AdjustedGradeInput component', () => { }); describe('render', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); - const control = el.find(Form.Control); - expect(control.props().value).toEqual(hookProps.value); - expect(control.props().onChange).toEqual(hookProps.onChange); - expect(el.contains(hookProps.hintText)).toEqual(true); + expect(el.snapshot).toMatchSnapshot(); + const control = el.instance.findByType(Form.Control)[0]; + expect(control.props.value).toEqual(hookProps.value); + expect(control.props.onChange).toEqual(hookProps.onChange); + expect(el.instance.children[1].el).toContain(hookProps.hintText); }); }); }); diff --git a/src/components/GradesView/EditModal/OverrideTable/ReasonInput/index.test.jsx b/src/components/GradesView/EditModal/OverrideTable/ReasonInput/index.test.jsx index 8cf81342..2d06f3a6 100644 --- a/src/components/GradesView/EditModal/OverrideTable/ReasonInput/index.test.jsx +++ b/src/components/GradesView/EditModal/OverrideTable/ReasonInput/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { Form } from '@edx/paragon'; @@ -28,10 +28,10 @@ describe('ReasonInput component', () => { }); describe('render', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); - const control = el.find(Form.Control); - expect(control.props().value).toEqual(hookProps.value); - expect(control.props().onChange).toEqual(hookProps.onChange); + expect(el.snapshot).toMatchSnapshot(); + const control = el.instance.findByType(Form.Control)[0]; + expect(control.props.value).toEqual(hookProps.value); + expect(control.props.onChange).toEqual(hookProps.onChange); }); }); }); diff --git a/src/components/GradesView/EditModal/OverrideTable/index.test.jsx b/src/components/GradesView/EditModal/OverrideTable/index.test.jsx index 79210fb7..28c61954 100644 --- a/src/components/GradesView/EditModal/OverrideTable/index.test.jsx +++ b/src/components/GradesView/EditModal/OverrideTable/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { DataTable } from '@edx/paragon'; @@ -48,10 +48,10 @@ describe('OverrideTable component', () => { expect(el.isEmptyRender()).toEqual(true); }); test('snapshot', () => { - expect(el).toMatchSnapshot(); - const table = el.find(DataTable); - expect(table.props().columns).toEqual(hookProps.columns); - const data = [...table.props().data]; + expect(el.snapshot).toMatchSnapshot(); + const table = el.instance.findByType(DataTable)[0]; + expect(table.props.columns).toEqual(hookProps.columns); + const data = [...table.props.data]; const inputRow = data.pop(); const formattedDate = formatDateForDisplay(new Date()); expect(data).toEqual(hookProps.data); diff --git a/src/components/GradesView/EditModal/index.test.jsx b/src/components/GradesView/EditModal/index.test.jsx index 8a69126f..bd115d29 100644 --- a/src/components/GradesView/EditModal/index.test.jsx +++ b/src/components/GradesView/EditModal/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { ActionRow, @@ -43,60 +43,56 @@ describe('EditModal component', () => { }); describe('render', () => { test('modal props', () => { - const modalProps = el.find(ModalDialog).props(); + const modalProps = el.instance.findByType(ModalDialog)[0].props; expect(modalProps.title).toEqual(formatMessage(messages.title)); expect(modalProps.isOpen).toEqual(hookProps.isOpen); expect(modalProps.onClose).toEqual(hookProps.onClose); }); const loadBody = () => { - const body = el.find(ModalDialog).children().at(0); - const children = body.find('div').children(); + const body = el.instance.findByType(ModalDialog)[0].children[0]; + const { children } = body.children[0]; return { body, children }; }; const testBody = () => { test('type', () => { const { body } = loadBody(); - expect(body.type()).toEqual('ModalDialog.Body'); + expect(body.type).toEqual('ModalDialog.Body'); }); test('headers row', () => { const { children } = loadBody(); - expect(children.at(0)).toMatchObject(shallow()); + expect(children[0]).toMatchObject(shallow()); }); test('table row', () => { const { children } = loadBody(); - expect(children.at(2)).toMatchObject(shallow()); + expect(children[2]).toMatchObject(shallow()); }); test('messages', () => { const { children } = loadBody(); - expect( - children.at(3).contains(formatMessage(messages.visibility)), - ).toEqual(true); - expect( - children.at(4).contains(formatMessage(messages.saveVisibility)), - ).toEqual(true); + expect(children[3].children[0].el).toEqual(formatMessage(messages.visibility)); + expect(children[4].children[0].el).toEqual(formatMessage(messages.saveVisibility)); }); }; const testFooter = () => { let footer; beforeEach(() => { - footer = el.find(ModalDialog).children().at(1); + footer = el.instance.findByType(ModalDialog)[0].children; }); test('type', () => { - expect(footer.type()).toEqual('ModalDialog.Footer'); + expect(footer[1].type).toEqual('ModalDialog.Footer'); }); test('contains action row', () => { - expect(footer.children().at(0).type()).toEqual('ActionRow'); + expect(footer[1].children[0].type).toEqual('ActionRow'); }); test('close button', () => { - const button = footer.find(ActionRow).children().at(0); - expect(button.contains(formatMessage(messages.closeText))).toEqual(true); - expect(button.type()).toEqual('ModalDialog.CloseButton'); + const button = footer[1].findByType(ActionRow)[0].children[0]; + expect(button.children[0].el).toEqual(formatMessage(messages.closeText)); + expect(button.type).toEqual('ModalDialog.CloseButton'); }); test('adjusted grade button', () => { - const button = footer.find(ActionRow).children().at(1); - expect(button.contains(formatMessage(messages.saveGrade))).toEqual(true); - expect(button.type()).toEqual('Button'); - expect(button.props().onClick).toEqual(hookProps.handleAdjustedGradeClick); + const button = footer[1].findByType(ActionRow)[0].children[1]; + expect(button.children[0].el).toEqual(formatMessage(messages.saveGrade)); + expect(button.type).toEqual('Button'); + expect(button.props.onClick).toEqual(hookProps.handleAdjustedGradeClick); }); }; describe('without error', () => { @@ -105,26 +101,26 @@ describe('EditModal component', () => { el = shallow(); }); test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); testBody(); testFooter(); test('alert row', () => { - const alert = loadBody().children.at(1); - expect(alert.type()).toEqual('Alert'); - expect(alert.props().show).toEqual(false); + const alert = loadBody().children[1]; + expect(alert.type).toEqual('Alert'); + expect(alert.props.show).toEqual(false); }); }); describe('with error', () => { test('snapshot', () => { - expect(el).toMatchSnapshot(); + expect(el.snapshot).toMatchSnapshot(); }); testBody(); test('alert row', () => { - const alert = loadBody().children.at(1); - expect(alert.type()).toEqual('Alert'); - expect(alert.props().show).toEqual(true); - expect(alert.contains(hookProps.error)).toEqual(true); + const alert = loadBody().children[1]; + expect(alert.type).toEqual('Alert'); + expect(alert.props.show).toEqual(true); + expect(alert.children[0].el).toEqual(hookProps.error); }); testFooter(); }); diff --git a/src/components/GradesView/FilterBadges/FilterBadge.jsx b/src/components/GradesView/FilterBadges/FilterBadge.jsx index 48e6862b..8d21aca3 100644 --- a/src/components/GradesView/FilterBadges/FilterBadge.jsx +++ b/src/components/GradesView/FilterBadges/FilterBadge.jsx @@ -32,8 +32,8 @@ export const FilterBadge = ({ return (
- {formatMessage(displayName)} - + {formatMessage(displayName)} + {!hideValue ? `: ${value}` : ''}