From c86310058ac465edb1eb7f4b7ed30555b060e181 Mon Sep 17 00:00:00 2001 From: Nazehs Abel Date: Thu, 12 Oct 2023 10:07:49 +0100 Subject: [PATCH] bug: fix bug with export and test --- package-lock.json | 322 +++++++++++++++++------- package.json | 24 +- src/js/data-store.js | 6 +- src/js/iconify.js | 20 +- src/js/modal-download.js | 20 +- src/js/modal-maintenance.js | 10 +- test/src/js/data-store.spec.js | 344 +++++++++++++++----------- test/src/js/iconify.spec.js | 88 ++----- test/src/js/modal-download.spec.js | 25 -- test/src/js/modal-maintenance.spec.js | 49 +--- 10 files changed, 502 insertions(+), 406 deletions(-) diff --git a/package-lock.json b/package-lock.json index c5dd315..a1a4305 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,14 +8,14 @@ "name": "@financial-times/n-syndication", "version": "0.0.0", "dependencies": { - "next-session-client": "^4.0.0", + "next-session-client": "^5.0.0", "superstore": "^2.1.0" }, "devDependencies": { - "@babel/runtime": "^7.10.2", - "@financial-times/eslint-config-next": "^7.0.0", + "@babel/runtime": "^7.23.1", + "@financial-times/eslint-config-next": "^7.1.0", "@financial-times/n-gage": "^9.0.1", - "@financial-times/n-heroku-tools": "^14.0.0", + "@financial-times/n-heroku-tools": "^15.0.0", "@financial-times/o-buttons": "^7.3.0", "@financial-times/o-colors": "^6.4.2", "@financial-times/o-icons": "^7.2.1", @@ -27,8 +27,8 @@ "@sucrase/jest-plugin": "^3.0.0", "autoprefixer": "^10.2.5", "babel-core": "^6.26.3", - "babel-loader": "^7.1.5", - "babel-plugin-add-module-exports": "^0.2.1", + "babel-loader": "^8.0.0", + "babel-plugin-add-module-exports": "^1.0.4", "babel-plugin-transform-async-to-generator": "^6.24.1", "babel-plugin-transform-es2015-classes": "^6.24.1", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", @@ -37,17 +37,17 @@ "babel-preset-react": "^6.24.1", "check-engine": "^1.10.1", "eslint": "^8.0.1", - "extract-css-block-webpack-plugin": "^1.3.0", - "extract-text-webpack-plugin": "3.0.2", + "extract-css-block-webpack-plugin": "^1.3.1", + "extract-text-webpack-plugin": "^3.0.2", "jest": "^29.3.1", "jest-environment-jsdom": "^29.3.1", "lintspaces-cli": "^0.6.0", "sass-lint": "^1.13.1", "snyk": "^1.167.2", - "webpack": "^3.1.0", - "webpack-merge": "^4.1.0", - "webpack-sources": "^1.4.3", - "webpack-stats-plugin": "^0.3.0" + "webpack": "^3.12.0", + "webpack-merge": "^5.9.0", + "webpack-sources": "^3.2.3", + "webpack-stats-plugin": "^1.1.3" }, "engines": { "node": "16.x || 18.x", @@ -1536,11 +1536,10 @@ } }, "node_modules/@financial-times/n-heroku-tools": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/@financial-times/n-heroku-tools/-/n-heroku-tools-14.0.1.tgz", - "integrity": "sha512-uatOAyakCBiXOB+LcjwmYI3w6IsqL1NZHKVP1Z7VenqeMH9XTz/vVrT6oBmG80M6213ynTfy7BFRVDrOvLkZ8A==", + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/@financial-times/n-heroku-tools/-/n-heroku-tools-15.0.0.tgz", + "integrity": "sha512-8Vb6fMJFnqPPD+1dmBzQhJppCd/qxkHGmgE3cW7e4eseS2rtiwsb5uAn0h9CC0BIKCcArvUYVsEdIrkgXnvW7A==", "dev": true, - "hasInstallScript": true, "dependencies": { "aws-sdk": "^2.1.19", "co": "^4.6.0", @@ -1566,8 +1565,8 @@ "nht": "bin/n-heroku-tools.js" }, "engines": { - "node": "14.x || 16.x", - "npm": "7.x || 8.x" + "node": "16.x || 18.x", + "npm": "7.x || 8.x || 9.x" } }, "node_modules/@financial-times/n-pa11y-config": { @@ -3503,6 +3502,25 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/array.prototype.reduce": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/array.prototype.reduce/-/array.prototype.reduce-1.0.6.tgz", + "integrity": "sha512-UW+Mz8LG/sPSU8jRDCjVr6J/ZKAGpHfwrZ6kWTG5qCxIEiXdVshqGnu5vEZA8S1y6X4aCSbQZ0/EEsfvEvBiSg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1", + "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/arraybuffer.prototype.slice": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/arraybuffer.prototype.slice/-/arraybuffer.prototype.slice-1.0.2.tgz", @@ -4026,21 +4044,22 @@ } }, "node_modules/babel-loader": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-7.1.5.tgz", - "integrity": "sha512-iCHfbieL5d1LfOQeeVJEUyD9rTwBcP/fcEbRCfempxTDuqrKpu0AZjLAQHEQa3Yqyj9ORKe2iHfoj4rHLf7xpw==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.0.0.tgz", + "integrity": "sha512-lBUGBz411lSfT+8MHPEaqIVQ44odS1D/wxuTMhijqHc9arZR6jhJEaJa0RpZlCSITZoeK6xoDXTaVTrSoFD7IQ==", "dev": true, "dependencies": { "find-cache-dir": "^1.0.0", "loader-utils": "^1.0.2", - "mkdirp": "^0.5.1" + "mkdirp": "^0.5.1", + "util.promisify": "^1.0.0" }, "engines": { - "node": ">=4" + "node": ">= 6.9" }, "peerDependencies": { - "babel-core": "6", - "webpack": "2 || 3 || 4" + "@babel/core": "^7.0.0", + "webpack": ">=2" } }, "node_modules/babel-messages": { @@ -4053,9 +4072,9 @@ } }, "node_modules/babel-plugin-add-module-exports": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-0.2.1.tgz", - "integrity": "sha512-3AN/9V/rKuv90NG65m4tTHsI04XrCKsWbztIcW7a8H5iIN7WlvWucRtVV0V/rT4QvtA11n5Vmp20fLwfMWqp6g==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-1.0.4.tgz", + "integrity": "sha512-g+8yxHUZ60RcyaUpfNzy56OtWW+x9cyEe9j+CranqLiqbju2yf/Cy6ZtYK40EZxtrdHllzlVZgLmcOUCTlJ7Jg==", "dev": true }, "node_modules/babel-plugin-check-es2015-constants": { @@ -5936,6 +5955,20 @@ "node": ">=8" } }, + "node_modules/clone-deep": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz", + "integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==", + "dev": true, + "dependencies": { + "is-plain-object": "^2.0.4", + "kind-of": "^6.0.2", + "shallow-clone": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/clone-regexp": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clone-regexp/-/clone-regexp-2.2.0.tgz", @@ -8149,6 +8182,61 @@ "webpack": "^3.1.0" } }, + "node_modules/extract-text-webpack-plugin/node_modules/ajv": { + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", + "integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", + "dev": true, + "dependencies": { + "co": "^4.6.0", + "fast-deep-equal": "^1.0.0", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.3.0" + } + }, + "node_modules/extract-text-webpack-plugin/node_modules/fast-deep-equal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "integrity": "sha512-fueX787WZKCV0Is4/T2cyAdM4+x1S3MXXOAhavE1ys/W42SHAPacLTQhucja22QBYrfGw50M2sRiXPtTGv9Ymw==", + "dev": true + }, + "node_modules/extract-text-webpack-plugin/node_modules/json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha512-4JD/Ivzg7PoW8NzdrBSr3UFwC9mHgvI7Z6z3QGBsSHgKaRTUDmyZAAKJo2UbG1kUVfS9WS8bi36N49U1xw43DA==", + "dev": true + }, + "node_modules/extract-text-webpack-plugin/node_modules/schema-utils": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-0.3.0.tgz", + "integrity": "sha512-QaVYBaD9U8scJw2EBWnCBY+LJ0AD+/2edTaigDs0XLDLBfJmSUK9KGqktg1rb32U3z4j/XwvFwHHH1YfbYFd7Q==", + "dev": true, + "dependencies": { + "ajv": "^5.0.0" + }, + "engines": { + "node": ">= 4.3 < 5.0.0 || >= 5.10" + } + }, + "node_modules/extract-text-webpack-plugin/node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/extract-text-webpack-plugin/node_modules/webpack-sources": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz", + "integrity": "sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==", + "dev": true, + "dependencies": { + "source-list-map": "^2.0.0", + "source-map": "~0.6.1" + } + }, "node_modules/extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", @@ -14236,12 +14324,12 @@ "dev": true }, "node_modules/next-session-client": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/next-session-client/-/next-session-client-4.0.0.tgz", - "integrity": "sha512-S7mcZoOu6WjUIhyt6MtHGP9f2r9urSfqa40EJpmd68fOdG20qWo2QCCd3NpqHykPNyJtV2KSmqsi7ynMTcr4hg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/next-session-client/-/next-session-client-5.0.0.tgz", + "integrity": "sha512-xkXekXRDB2k8OWj/7WHh37mV6PdAfLAdFd8f5usWaZtq+0LKHyx6mvO79/JdFvvJUod8IHOkQ+An64TpokBCFw==", "hasInstallScript": true, "engines": { - "node": "14.x || 16.x", + "node": "16.x", "npm": "7.x || 8.x" } }, @@ -14771,6 +14859,25 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/object.getownpropertydescriptors": { + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.7.tgz", + "integrity": "sha512-PrJz0C2xJ58FNn11XV2lr4Jt5Gzl94qpy9Lu0JlfEj14z88sqbSBJCBEzdlNUCzY2gburhbrwOZ5BHCmuNUy0g==", + "dev": true, + "dependencies": { + "array.prototype.reduce": "^1.0.6", + "call-bind": "^1.0.2", + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1", + "safe-array-concat": "^1.0.0" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/object.pick": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/object.pick/-/object.pick-1.3.0.tgz", @@ -17827,42 +17934,6 @@ "node": ">=v12.22.7" } }, - "node_modules/schema-utils": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-0.3.0.tgz", - "integrity": "sha512-QaVYBaD9U8scJw2EBWnCBY+LJ0AD+/2edTaigDs0XLDLBfJmSUK9KGqktg1rb32U3z4j/XwvFwHHH1YfbYFd7Q==", - "dev": true, - "dependencies": { - "ajv": "^5.0.0" - }, - "engines": { - "node": ">= 4.3 < 5.0.0 || >= 5.10" - } - }, - "node_modules/schema-utils/node_modules/ajv": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", - "integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", - "dev": true, - "dependencies": { - "co": "^4.6.0", - "fast-deep-equal": "^1.0.0", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.3.0" - } - }, - "node_modules/schema-utils/node_modules/fast-deep-equal": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", - "integrity": "sha512-fueX787WZKCV0Is4/T2cyAdM4+x1S3MXXOAhavE1ys/W42SHAPacLTQhucja22QBYrfGw50M2sRiXPtTGv9Ymw==", - "dev": true - }, - "node_modules/schema-utils/node_modules/json-schema-traverse": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", - "integrity": "sha512-4JD/Ivzg7PoW8NzdrBSr3UFwC9mHgvI7Z6z3QGBsSHgKaRTUDmyZAAKJo2UbG1kUVfS9WS8bi36N49U1xw43DA==", - "dev": true - }, "node_modules/secure-json-parse": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", @@ -17993,6 +18064,18 @@ "sha.js": "bin.js" } }, + "node_modules/shallow-clone": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", + "integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==", + "dev": true, + "dependencies": { + "kind-of": "^6.0.2" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -20374,6 +20457,25 @@ "webpack": "^1.9 || ^2 || ^2.1.0-beta || ^2.2.0-rc || ^3.0.0" } }, + "node_modules/uglifyjs-webpack-plugin/node_modules/webpack-sources": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz", + "integrity": "sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==", + "dev": true, + "dependencies": { + "source-list-map": "^2.0.0", + "source-map": "~0.6.1" + } + }, + "node_modules/uglifyjs-webpack-plugin/node_modules/webpack-sources/node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -20771,6 +20873,24 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, + "node_modules/util.promisify": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/util.promisify/-/util.promisify-1.1.2.tgz", + "integrity": "sha512-PBdZ03m1kBnQ5cjjO0ZvJMJS+QsbyIcFwi4hY4U76OQsCO9JrOYjbCFgIF76ccFg9xnJo7ZHPkqyj1GqmdS7MA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.2.0", + "for-each": "^0.3.3", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "object.getownpropertydescriptors": "^2.1.6", + "safe-array-concat": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/uuid": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.0.0.tgz", @@ -21028,41 +21148,32 @@ } }, "node_modules/webpack-merge": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-4.2.2.tgz", - "integrity": "sha512-TUE1UGoTX2Cd42j3krGYqObZbOD+xF7u28WB7tfUordytSjbWTIjK/8V0amkBfTYN4/pB/GIDlJZZ657BGG19g==", + "version": "5.9.0", + "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.9.0.tgz", + "integrity": "sha512-6NbRQw4+Sy50vYNTw7EyOn41OZItPiXB8GNv3INSoe3PSFaHJEz3SHTrYVaRm2LilNGnFUzh0FAwqPEmU/CwDg==", "dev": true, "dependencies": { - "lodash": "^4.17.15" + "clone-deep": "^4.0.1", + "wildcard": "^2.0.0" + }, + "engines": { + "node": ">=10.0.0" } }, "node_modules/webpack-sources": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz", - "integrity": "sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==", - "dev": true, - "dependencies": { - "source-list-map": "^2.0.0", - "source-map": "~0.6.1" - } - }, - "node_modules/webpack-sources/node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", + "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", "dev": true, "engines": { - "node": ">=0.10.0" + "node": ">=10.13.0" } }, "node_modules/webpack-stats-plugin": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/webpack-stats-plugin/-/webpack-stats-plugin-0.3.2.tgz", - "integrity": "sha512-kxEtPQ6lBBik2qtJlsZkiaDMI6rGXe9w1kLH9ZCdt0wgCGVnbwwPlP60cMqG6tILNFYqXDxNt4+c4OIIuE+Fnw==", - "dev": true, - "engines": { - "node": ">=4" - } + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/webpack-stats-plugin/-/webpack-stats-plugin-1.1.3.tgz", + "integrity": "sha512-yUKYyy+e0iF/w31QdfioRKY+h3jDBRpthexBOWGKda99iu2l/wxYsI/XqdlP5IU58/0KB9CsJZgWNAl+/MPkRw==", + "dev": true }, "node_modules/webpack/node_modules/acorn": { "version": "5.7.4", @@ -21343,6 +21454,25 @@ "node": ">=4" } }, + "node_modules/webpack/node_modules/webpack-sources": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz", + "integrity": "sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==", + "dev": true, + "dependencies": { + "source-list-map": "^2.0.0", + "source-map": "~0.6.1" + } + }, + "node_modules/webpack/node_modules/webpack-sources/node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/webpack/node_modules/wrap-ansi": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", @@ -21569,6 +21699,12 @@ "node": ">=4" } }, + "node_modules/wildcard": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.1.tgz", + "integrity": "sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ==", + "dev": true + }, "node_modules/window-size": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", diff --git a/package.json b/package.json index ef41627..1d736f6 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "main": "main.js", "description": "Implementation for the syndication indicator, for users who subscribe to the new FT syndication platform", "devDependencies": { - "@babel/runtime": "^7.10.2", - "@financial-times/eslint-config-next": "^7.0.0", + "@babel/runtime": "^7.23.1", + "@financial-times/eslint-config-next": "^7.1.0", "@financial-times/n-gage": "^9.0.1", - "@financial-times/n-heroku-tools": "^14.0.0", + "@financial-times/n-heroku-tools": "^15.0.0", "@financial-times/o-buttons": "^7.3.0", "@financial-times/o-colors": "^6.4.2", "@financial-times/o-icons": "^7.2.1", @@ -19,8 +19,8 @@ "@sucrase/jest-plugin": "^3.0.0", "autoprefixer": "^10.2.5", "babel-core": "^6.26.3", - "babel-loader": "^7.1.5", - "babel-plugin-add-module-exports": "^0.2.1", + "babel-loader": "^8.0.0", + "babel-plugin-add-module-exports": "^1.0.4", "babel-plugin-transform-async-to-generator": "^6.24.1", "babel-plugin-transform-es2015-classes": "^6.24.1", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", @@ -29,20 +29,20 @@ "babel-preset-react": "^6.24.1", "check-engine": "^1.10.1", "eslint": "^8.0.1", - "extract-css-block-webpack-plugin": "^1.3.0", - "extract-text-webpack-plugin": "3.0.2", + "extract-css-block-webpack-plugin": "^1.3.1", + "extract-text-webpack-plugin": "^3.0.2", "jest": "^29.3.1", "jest-environment-jsdom": "^29.3.1", "lintspaces-cli": "^0.6.0", "sass-lint": "^1.13.1", "snyk": "^1.167.2", - "webpack": "^3.1.0", - "webpack-merge": "^4.1.0", - "webpack-sources": "^1.4.3", - "webpack-stats-plugin": "^0.3.0" + "webpack": "^3.12.0", + "webpack-merge": "^5.9.0", + "webpack-sources": "^3.2.3", + "webpack-stats-plugin": "^1.1.3" }, "dependencies": { - "next-session-client": "^4.0.0", + "next-session-client": "^5.0.0", "superstore": "^2.1.0" }, "peerDependencies": { diff --git a/src/js/data-store.js b/src/js/data-store.js index 3ba0992..5056d69 100644 --- a/src/js/data-store.js +++ b/src/js/data-store.js @@ -18,12 +18,12 @@ function init (user, data = null) { addEventListener( 'nSyndication.fetch', - (evt) => exports.refresh(evt.detail.response), + (evt) => refresh(evt.detail.response), true ); if (Array.isArray(data)) { - exports.refresh(data); + refresh(data); } } @@ -89,7 +89,7 @@ function getItemByHTMLElement (el) { const id = getContentIDFromHTMLElement(el); const lang = getContentAttributeFromHTMLElement(el, 'data-iso-lang') || 'en'; - return module.exports.getItemByID(id, lang); + return getItemByID(id, lang); } function getAllItemsForID (id) { diff --git a/src/js/iconify.js b/src/js/iconify.js index 38372e3..ffffa11 100644 --- a/src/js/iconify.js +++ b/src/js/iconify.js @@ -43,16 +43,16 @@ function init (user) { USER_DATA = user; addEventListener( 'asyncContentLoaded', - () => exports.syndicate(), + () => syndicate(), true ); addEventListener( 'nSyndication.dataChanged', - () => exports.updatePage(), + () => updatePage(), true ); - return exports.syndicate(); + return syndicate(); } function createElement (item) { @@ -138,21 +138,21 @@ function getSyndicatableItemIDs (items) { } function syndicate () { - const ELEMENTS = exports.getSyndicatableItems(); + const ELEMENTS = getSyndicatableItems(); + const ITEM_IDS = getSyndicatableItemIDs(ELEMENTS); - const ITEM_IDS = exports.getSyndicatableItemIDs(ELEMENTS); return fetchItems(ITEM_IDS); } function syndicateElement (item, el) { - const element = exports.findElementToSyndicate(el); + const element = findElementToSyndicate(el); if (element !== null && element.getAttribute('data-syndicated') !== 'true') { element.classList.add('n-syndication'); element.classList.add(`n-syndication-state-${item.canBeSyndicated}`); - prepend(element, exports.createElement(item)); + prepend(element, createElement(item)); element.setAttribute('data-content-type', item.type); element.setAttribute('data-syndicated', 'true'); @@ -169,12 +169,12 @@ function syndicateElements (item, els) { return; } - els.forEach((el) => exports.syndicateElement(item, el)); + els.forEach((el) => syndicateElement(item, el)); } function updatePage (els) { if (!Array.isArray(els)) { - els = exports.getSyndicatableItems(); + els = getSyndicatableItems(); } const elementsByContentID = Array.from(els).reduce((acc, el) => { @@ -190,7 +190,7 @@ function updatePage (els) { }, {}); DATA_STORE.forEach((item) => - exports.syndicateElements(item, elementsByContentID[item['id']]) + syndicateElements(item, elementsByContentID[item['id']]) ); broadcast('nSyndication.iconified'); diff --git a/src/js/modal-download.js b/src/js/modal-download.js index d006c3e..5b45826 100644 --- a/src/js/modal-download.js +++ b/src/js/modal-download.js @@ -21,9 +21,9 @@ const isDownloadPage = location.pathname.includes('/download'); const isSavePage = location.pathname.includes('/save'); function init (user) { - addEventListener('click', exports.actionModalFromClick, true); + addEventListener('click', actionModalFromClick, true); - addEventListener('keyup', exports.actionModalFromKeyboard, true); + addEventListener('keyup', actionModalFromKeyboard, true); addEventListener('resize', overlayManager.reposition, true); oViewport.listenTo('resize'); @@ -38,17 +38,17 @@ function actionModalFromClick (evt) { const trackingEvent = createTrackingEvent(evt, item, overlayManager); if (isSyndicationIcon(evt.target)) { - exports.show(evt); + show(evt); } else if (isDownloadButton(evt.target)) { evt.preventDefault(); - exports.show(evt); + show(evt); } else if (isSaveAction(evt.target)) { - exports.save(evt); + save(evt); overlayManager.hideOverlay(); - exports.show(evt); + show(evt); overlayManager.delayModalHide(); } else if (isDownloadAction(evt.target)) { - exports.download(evt); + download(evt); overlayManager.delayModalHide(); } else { const isOverlayVisible = overlayManager.isOverlayVisible(); @@ -85,7 +85,7 @@ function actionModalFromKeyboard (evt) { case ' ': case 'Enter': if (isSyndicationIcon(evt.target)) { - exports.show(evt); + show(evt); } break; } @@ -117,8 +117,8 @@ function isSaveDisabled (item) { function createElement (item) { try { - const disableDownloadButton = exports.isDownloadDisabled(item); - const disableSaveButton = exports.isSaveDisabled(item); + const disableDownloadButton = isDownloadDisabled(item); + const disableSaveButton = isSaveDisabled(item); const downloadHref = disableDownloadButton ? '#' : generateDownloadURI(item.id, item); diff --git a/src/js/modal-maintenance.js b/src/js/modal-maintenance.js index cc91fc7..04c6e33 100644 --- a/src/js/modal-maintenance.js +++ b/src/js/modal-maintenance.js @@ -17,9 +17,9 @@ const localStore = new Superstore('local', 'syndication'); const overlayManager = new OverlayVisibilityManager(); function init (user) { - addEventListener('click', exports.actionModalFromClick, true); + addEventListener('click', actionModalFromClick, true); - addEventListener('keyup', exports.actionModalFromKeyboard, true); + addEventListener('keyup', actionModalFromKeyboard, true); addEventListener('resize', overlayManager.reposition, true); oViewport.listenTo('resize'); @@ -45,10 +45,10 @@ function actionModalFromClick (evt) { const trackingEvent = createTrackingEvent(evt, item, overlayManager); if (isSyndicationIcon(evt.target)) { - exports.show(evt); + show(evt); }else if (isDownloadButton(evt.target)) { evt.preventDefault(); - exports.show(evt); + show(evt); } else if (isSaveAction(evt.target)) { overlayManager.delayModalHide(); } else { @@ -85,7 +85,7 @@ function actionModalFromKeyboard (evt) { case ' ': case 'Enter': if (isSyndicationIcon(evt.target)) { - exports.show(evt); + show(evt); } break; diff --git a/test/src/js/data-store.spec.js b/test/src/js/data-store.spec.js index 9e76cbf..0b34811 100644 --- a/test/src/js/data-store.spec.js +++ b/test/src/js/data-store.spec.js @@ -1,179 +1,235 @@ -const dataSource = require('../../../src/js/data-store'); - -describe('./src/js/data-store', function () { - const USER_DATA = { contract_id: '123', MAINTENANCE_MODE: false }; - beforeEach( () => { - dataSource.USER_DATA = USER_DATA; - jest.spyOn(dataSource, 'refresh'); +import { + DATA_STORE, + DATA_STORE_MAP, + USER_DATA, + fetchItems, + getAllItemsForID, + getItemByHTMLElement, + getItemByID, + getItemIndex, + getUserData, + init, + refresh, +} from '../../../src/js/data-store'; + +describe('Data Store Module', () => { + beforeEach(() => { + DATA_STORE.length = 0; + Object.keys(DATA_STORE_MAP).forEach((key) => delete DATA_STORE_MAP[key]); }); - afterEach(() => { jest.clearAllMocks(); }); + describe('init', () => { + it('should initialize USER_DATA and call refresh if data is provided', () => { + const user = { MAINTENANCE_MODE: true }; + const data = [{ id: 1 }]; + init(user, data); + + expect(USER_DATA).toEqual(user); + expect(DATA_STORE).toEqual(data); + }); + it('init should be a Function', function () { + expect(typeof init).toBe('function'); + }); + it('should register the "nSyndication.fetch" event listener', () => { + const user = { MAINTENANCE_MODE: false }; + const eventListenerSpy = jest.spyOn(window, 'addEventListener'); - test('init should be a Function', function () { - expect(typeof dataSource.init).toBe('function'); - }); - - test('init should initialize USER_DATA and call refresh with data when data is an array', function () { - const data = [ - { id: '1', lang: 'en' }, - { id: '2', lang: 'fr' }, - ]; - - dataSource.init(dataSource.USER_DATA, data); + init(user); - expect(dataSource.refresh).toHaveBeenCalledWith(data); - expect(dataSource.refresh).toHaveBeenCalledTimes(1); + expect(eventListenerSpy).toHaveBeenCalledWith( + 'nSyndication.fetch', + expect.any(Function), + true + ); + }); }); - test('init should initialize USER_DATA and not call refresh when data is not an array', function () { - const data = {}; - dataSource.init(dataSource.USER_DATA, data); - expect(dataSource.refresh).not.toHaveBeenCalled(); - }); + describe('fetchItems Function', () => { + it('fetchItems should return fake response when USER_DATA.MAINTENANCE_MODE is true', async function () { + USER_DATA.MAINTENANCE_MODE = true; + const itemIDs = ['1', '2', '3']; + const expectedResponse = [ + { + id: '1', + __id__: '1__en', + canBeSyndicated: 'maintenance', + messageCode: 'MSG_5100', + }, + { + id: '2', + __id__: '2__en', + canBeSyndicated: 'maintenance', + messageCode: 'MSG_5100', + }, + { + id: '3', + __id__: '3__en', + canBeSyndicated: 'maintenance', + messageCode: 'MSG_5100', + }, + ]; + + const mockResponse = { + ok: true, + status: 200, + }; + global.fetch = jest.fn().mockResolvedValue(mockResponse); - test('fetchItems should return fake response when USER_DATA.MAINTENANCE_MODE is true', async function () { - dataSource.USER_DATA.MAINTENANCE_MODE = true; - const itemIDs = ['1', '2', '3']; - const expectedResponse = [ - { - id: '1', - __id__: '1__en', - canBeSyndicated: 'maintenance', - messageCode: 'MSG_5100', - }, - { - id: '2', - __id__: '2__en', - canBeSyndicated: 'maintenance', - messageCode: 'MSG_5100', - }, - { - id: '3', - __id__: '3__en', - canBeSyndicated: 'maintenance', - messageCode: 'MSG_5100', - }, - ]; - - const mockResponse = { - ok: true, - status: 200, - }; - global.fetch = jest.fn().mockResolvedValue(mockResponse); - - const response = await dataSource.fetchItems(itemIDs); - expect(response).toEqual(expectedResponse); - expect(fetch).not.toHaveBeenCalled(); - }); + const response = await fetchItems(itemIDs); + expect(response).toEqual(expectedResponse); + expect(fetch).not.toHaveBeenCalled(); + }); - test('fetchItems should make a fetch request and return the response when USER_DATA.MAINTENANCE_MODE is false', async function () { - dataSource.USER_DATA.MAINTENANCE_MODE = false; - const itemIDs = ['1', '2', '3']; - const expectedResponse = [ - { id: '1', title: 'Item 1' }, - { id: '2', title: 'Item 2' }, - { id: '3', title: 'Item 3' }, - ]; - - global.fetch = jest.fn().mockImplementation(() => { - return Promise.resolve({ - ok: true, - json: () => Promise.resolve(expectedResponse), + it('fetchItems should make a fetch request and return the response when USER_DATA.MAINTENANCE_MODE is false', async function () { + USER_DATA.MAINTENANCE_MODE = false; + const itemIDs = ['1', '2', '3']; + const expectedResponse = [ + { id: '1', title: 'Item 1' }, + { id: '2', title: 'Item 2' }, + { id: '3', title: 'Item 3' }, + ]; + + global.fetch = jest.fn().mockImplementation(() => { + return Promise.resolve({ + ok: true, + json: () => Promise.resolve(expectedResponse), + }); }); + const response = await fetchItems(itemIDs); + expect(response).toEqual(expectedResponse); + expect(fetch).toHaveBeenCalledTimes(1); }); - const response = await dataSource.fetchItems(itemIDs); - expect(response).toEqual(expectedResponse); - expect(fetch).toHaveBeenCalledTimes(1); - }); - test('fetchItems should handle error when fetch request fails', async function () { - dataSource.USER_DATA.MAINTENANCE_MODE = false; - const itemIDs = ['1', '2', '3']; - global.fetch = jest.fn().mockImplementation(() => { - return Promise.resolve({ - ok: false, - text: () => Promise.reject(new Error('Network Error')), + it('fetchItems should handle error when fetch request fails', async function () { + USER_DATA.MAINTENANCE_MODE = false; + const itemIDs = ['1', '2', '3']; + global.fetch = jest.fn().mockImplementation(() => { + return Promise.resolve({ + ok: false, + text: () => Promise.reject(new Error('Network Error')), + }); }); + try { + await fetchItems(itemIDs); + } catch (e) { + expect(fetch).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ + method: 'POST', + body: JSON.stringify(itemIDs), + }) + ); + expect(fetch).toHaveBeenCalledTimes(1); + } }); - try { - await dataSource.fetchItems(itemIDs); - } catch (e) { - expect(fetch).toHaveBeenCalledWith( - expect.any(String), - expect.objectContaining({ - method: 'POST', - body: JSON.stringify(itemIDs), - }) - ); - expect(fetch).toHaveBeenCalledTimes(1); - } }); + describe('getItemByHTMLElement', () => { + it('should return the item corresponding to the given HTML element', () => { + const item = { id: '1', lang: 'en', title: 'item 1' }; + DATA_STORE.push(item); + const el = document.createElement('div'); + el.setAttribute('data-content-id', '1'); + + const result = getItemByHTMLElement(el); - test('getAllItemsForID should call the corresponding data store method', function () { - const itemID = '1'; - const expectedValue = [ - { - __id__: '1__en', - title: 'Item 1', - id: '1', - }, - ]; - dataSource.USER_DATA = [ - { - __id__: '1__en', - title: 'Item 1', - id: '1', - }, - ]; - - const result = dataSource.getAllItemsForID(itemID); - - expect(result).toEqual(expectedValue); + expect(result).toEqual(item); + }); }); - test('getItemByHTMLElement should call the corresponding data store method', function () { - const element = document.createElement('div'); - const expectedValue = { id: '1', title: 'Item 1' }; + describe('getAllItemsForID', () => { + it('should return an array of items with the given ID', () => { + const id = '1'; + const items = [{ id: '1' }, { id: '1', lang: 'en' }, { id: '2' }]; + DATA_STORE.push(...items); - jest.spyOn(dataSource, 'getItemByID').mockReturnValueOnce(expectedValue); - const result = dataSource.getItemByHTMLElement(element); + const result = getAllItemsForID(id); - expect(result).toEqual(expectedValue); - expect(dataSource.getItemByID).toHaveBeenCalled(); + expect(result).toEqual([items[0], items[1]]); + }); }); - test('getItemByID should call the corresponding data store method', function () { - const itemID = '1'; - const expectedValue = { - id: '1', - __id__: '1__en', - title: 'Item 1', - }; + describe('getItemByID', () => { + it('should return the item with the given ID and language', () => { + const id = '1'; + const lang = 'en'; + const item = { id: '1', lang: 'en' }; + DATA_STORE.push(item); + + const result = getItemByID(id, lang); - const result = dataSource.getItemByID(itemID); - expect(result).toEqual(expectedValue); + expect(result).toEqual(item); + }); + + it('should return the item with the given ID (default language "en")', () => { + const id = '1'; + const item = { id: '1', lang: 'en' }; + DATA_STORE.push(item); + + const result = getItemByID(id); + + expect(result).toEqual(item); + }); + + it('should return null if no matching item is found', () => { + const id = '1'; + const lang = 'en'; + + const result = getItemByID(id, lang); + + expect(result).toBeNull(); + }); }); - test('getItemIndex should call the corresponding data store method', function () { - const itemID = '1'; - const expectedValue = -1; + describe('getItemIndex', () => { + it('should return the index of the item in DATA_STORE', () => { + const item = { id: 1, lang: 'en' }; + DATA_STORE.push(item); - const result = dataSource.getItemIndex(itemID); + const result = getItemIndex(item); + + expect(result).toBe(0); + }); - expect(result).toEqual(expectedValue); + it('should return -1 if the item is not found in DATA_STORE', () => { + const item = { id: 1 }; + + const result = getItemIndex(item); + + expect(result).toBe(-1); + }); + }); + + describe('getUserData', () => { + it('should return the USER_DATA object', () => { + USER_DATA = { MAINTENANCE_MODE: false }; + const result = getUserData(); + + expect(result).toEqual(USER_DATA); + }); }); - test('getUserData should call the corresponding data store method', function () { - const expectedValue = { - MAINTENANCE_MODE: false, - contract_id: '123', - }; + describe('refresh', () => { + it('should update DATA_STORE and DATA_STORE_MAP with new data', () => { + const data = [{ id: 1 }, { id: 2 }]; - const result = dataSource.getUserData(); + const result = refresh(data); - expect(result).toEqual(expectedValue); + expect(DATA_STORE).toEqual(data); + expect(DATA_STORE_MAP).toEqual({ + '1__en': data[0], + '2__en': data[1], + }); + expect(result).toEqual({ + EXISTING: [], + DATA_STORE: data, + DATA_STORE_MAP: { + '1__en': data[0], + '2__en': data[1], + }, + }); + }); }); }); diff --git a/test/src/js/iconify.spec.js b/test/src/js/iconify.spec.js index 5d0b09b..cc4de1f 100644 --- a/test/src/js/iconify.spec.js +++ b/test/src/js/iconify.spec.js @@ -2,7 +2,6 @@ const iconifyModule = require('./../../../src/js/iconify'); import { toElement } from '../../../src/js/util'; -import { fetchItems } from '../../../src/js/data-store'; import { broadcast } from 'n-ui-foundations'; jest.mock('../../../src/js/data-store', () => ({ @@ -33,12 +32,14 @@ describe('./src/js/iconify', () => { afterEach(() => { jest.clearAllMocks(); }); - test('init should be a Function', () => { - expect(typeof iconifyModule.init).toBe('function'); + describe('init', () => { + it('init should be a Function', () => { + expect(typeof iconifyModule.init).toBe('function'); + }); }); describe('createElement', () => { - test('should create a syndication icon element with correct attributes', () => { + it('should create a syndication icon element with correct attributes', () => { const item = { messageCode: '123', lang: 'en', @@ -87,20 +88,20 @@ describe('./src/js/iconify', () => { describe('findElementToSyndicate', () => { beforeAll(() => { document.documentElement.innerHTML = ` -
+
- +
`; }); - test('should return null for non-matching rules or elements', () => { + it('should return null for non-matching rules or elements', () => { const element = document.createElement('div'); let foundElement = iconifyModule.findElementToSyndicate(element); @@ -112,7 +113,7 @@ describe('./src/js/iconify', () => { expect(foundElement).toBeNull(); }); - test('should return the correct element to syndicate for matching rules', () => { + it('should return the correct element to syndicate for matching rules', () => { const elements = { '.card__concept-article-link': document.querySelector( '.card__concept-article-link' @@ -137,44 +138,26 @@ describe('./src/js/iconify', () => { }); }); describe('syndicateElements', () => { - function createMockElement (tagName) { - return { - tagName: tagName, - classList: { - contains: jest.fn(() => true), - }, - getAttribute: jest.fn(), - setAttribute: jest.fn(), - querySelector: jest.fn(() => ({ - not: { - toBeNull: jest.fn(), - }, - })), - }; - } + it('should not call forEach/syndicateElement method when the array is empty', () => { + const emptyArray = { forEach: jest.fn(), length: 0 }; - test('should syndicate an item to multiple elements', () => { - const item = { - id: 'content-id', - type: 'article', - canBeSyndicated: true, - }; - jest.spyOn(iconifyModule, 'syndicateElement'); + const result = iconifyModule.syndicateElements({}, emptyArray); - const elements = [ - createMockElement('button'), - createMockElement('form'), - createMockElement('form'), - ]; + expect(emptyArray.forEach).not.toHaveBeenCalled(); + expect(result).toEqual(undefined); + }); - iconifyModule.syndicateElements(item, elements); + it('should call forEach/syndicateElement method when the array is not empty', () => { + const arrayItems = { forEach: jest.fn(), length: 2 }; + iconifyModule.syndicateElements({}, arrayItems); - expect(iconifyModule.syndicateElement).toHaveBeenCalled(); + expect(arrayItems.forEach).toHaveBeenCalled(); }); }); describe('updatePage', () => { - test('should update the page with syndicated elements', () => { + + it('should update the page with syndicated elements', () => { const elements = [ { classList: { contains: jest.fn(() => true) }, @@ -204,33 +187,4 @@ describe('./src/js/iconify', () => { expect(broadcast).toHaveBeenCalledWith('nSyndication.iconified'); }); }); - - describe('init', () => { - test('should call syndicate and updatePage functions and attach event listeners', () => { - const user = { id: 'user-id', contract_id: '123' }; - - jest.spyOn(iconifyModule, 'syndicate'); - const addEventListenerSpy = jest.spyOn(window, 'addEventListener'); - - const itemIDs = ['1', '2', '3']; - - fetchItems.mockReturnValue(itemIDs); - - iconifyModule.init(user); - - expect(addEventListenerSpy).toHaveBeenCalledTimes(2); - expect(addEventListenerSpy).toHaveBeenCalledWith( - 'asyncContentLoaded', - expect.any(Function), - true - ); - expect(addEventListenerSpy).toHaveBeenCalledWith( - 'nSyndication.dataChanged', - expect.any(Function), - true - ); - - expect(iconifyModule.syndicate).toHaveBeenCalled(); - }); - }); }); diff --git a/test/src/js/modal-download.spec.js b/test/src/js/modal-download.spec.js index 5a8fad9..a7a4a44 100644 --- a/test/src/js/modal-download.spec.js +++ b/test/src/js/modal-download.spec.js @@ -4,13 +4,10 @@ import Superstore from 'superstore'; const modalDownload = require('../../../src/js/modal-download'); import OverlayVisibilityManager from '../../../src/js/modal-state-manager'; - import { TRACKING } from '../../../src/js/config'; - jest.mock('n-ui-foundations', () => ({ broadcast: jest.fn(), })); - jest.mock('../../../src/js/config'); jest.mock('../../../src/js/data-store', () => ({ @@ -115,21 +112,6 @@ describe('./src/js/modal-download', () => { expect(broadcast).toHaveBeenCalledWith('oTracking.event', trackingEvent); }); - it('actionModalFromKeyboard should show the modal on "Enter" or "Space" key press for syndication icon', () => { - modalDownload.actionModalFromKeyboard({ - key: 'Enter', - target: { matches: jest.fn().mockReturnValueOnce(true) }, - }); - - expect(modalDownload.show).toHaveBeenCalled(); - - modalDownload.actionModalFromKeyboard({ - key: 'Space', - target: { matches: jest.fn().mockReturnValueOnce(true) }, - }); - expect(modalDownload.show).toHaveBeenCalledTimes(1); - }); - it('isDownloadDisabled should return false for valid download conditions', () => { const item = { type: 'article', @@ -160,7 +142,6 @@ describe('./src/js/modal-download', () => { }; modalDownload.actionModalFromClick(evt); - expect(modalDownload.show).toHaveBeenCalled(); expect(broadcast).toHaveBeenCalledWith('oTracking.event', { category: TRACKING.CATEGORY, @@ -194,8 +175,6 @@ describe('./src/js/modal-download', () => { expect(overlayManagerMockInstance.delayModalHide).toHaveBeenCalled(); expect(overlayManagerMockInstance.hideOverlay).toHaveBeenCalled(); - expect(modalDownload.save).toHaveBeenCalled(); - expect(modalDownload.show).toHaveBeenCalled(); }); it('actionModalFromClick should download and delay hide the modal for download action', () => { @@ -215,7 +194,6 @@ describe('./src/js/modal-download', () => { modalDownload.actionModalFromClick(evt); - expect(modalDownload.download).toHaveBeenCalled(); expect(overlayManagerMockInstance.delayModalHide).toHaveBeenCalled(); }); @@ -240,7 +218,6 @@ describe('./src/js/modal-download', () => { modalDownload.actionModalFromClick(evt); expect(evt.preventDefault).toHaveBeenCalled(); - expect(modalDownload.show).toHaveBeenCalledWith(evt); }); it('actionModalFromClick should hide the modal on click outside or close action', () => { @@ -257,8 +234,6 @@ describe('./src/js/modal-download', () => { }, preventDefault: jest.fn(), }; - // jest.spyOn(modalDownload, 'delayHide'); - overlayManagerMockInstance.isOverlayVisible.mockReturnValue(true); modalDownload.actionModalFromClick(evt); diff --git a/test/src/js/modal-maintenance.spec.js b/test/src/js/modal-maintenance.spec.js index c72c0e2..f3add26 100644 --- a/test/src/js/modal-maintenance.spec.js +++ b/test/src/js/modal-maintenance.spec.js @@ -8,13 +8,20 @@ jest.mock('n-ui-foundations', () => ({ broadcast: jest.fn(), })); jest.mock('../../../src/js/data-store', () => ({ - getItemByHTMLElement: jest.fn(), + getItemByHTMLElement: jest.fn().mockReturnValue({ + id: '123', + lang: 'en', + messageCode: 'test-message', + type: 'article', + test: 'icon test', + }), })); const USER_DATA = { contract_id: '123' }; const overlayManagerMockInstance = { isOverlayVisible: jest.fn(), hideOverlay: jest.fn(), delayModalHide: jest.fn(), + showOverlay: jest.fn(), USER_DATA, }; @@ -28,6 +35,7 @@ describe('modalMaintenance', () => { jest.spyOn(OverlayVisibilityManager.prototype, 'hideOverlay').mockImplementation(overlayManagerMockInstance.hideOverlay); jest.spyOn(OverlayVisibilityManager.prototype, 'isOverlayVisible').mockImplementation(overlayManagerMockInstance.isOverlayVisible); jest.spyOn(OverlayVisibilityManager.prototype, 'delayModalHide').mockImplementation(overlayManagerMockInstance.delayModalHide); + jest.spyOn(OverlayVisibilityManager.prototype, 'showOverlay').mockImplementation(overlayManagerMockInstance.showOverlay); }); afterEach(() => { @@ -92,7 +100,7 @@ describe('modalMaintenance', () => { describe('actionModalFromClick', () => { beforeEach(() => { - jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'log').mockImplementation(() => { }); }); afterEach(() => { document.body.innerHTML = ''; @@ -197,7 +205,7 @@ describe('modalMaintenance', () => { describe('actionModalFromKeyboard', () => { beforeEach(() => { - jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'log').mockImplementation(() => { }); }); afterEach(() => { document.body.innerHTML = ''; @@ -234,42 +242,9 @@ describe('modalMaintenance', () => { modalMaintenance.actionModalFromClick(evt); expect(evt.preventDefault).toHaveBeenCalled(); - expect(modalMaintenance.show).toHaveBeenCalledWith(evt); + expect(broadcast).toHaveBeenCalled(); }); - it('should call show when Enter key is pressed', () => { - const evt = { - key: 'Enter', - target: { - getAttribute: jest.fn().mockReturnValue('save'), - matches: jest.fn((selector) => { - if ( - selector === - '[data-content-id][data-syndicated="true"].n-syndication-icon' - ) { - return true; - } else { - return false; - } - }), - parentElement: { - getAttribute: jest.fn().mockReturnValue('en'), - dataset: { - messageCode: '12345', - id: 'item-id', - type: 'article', - }, - }, - }, - test:'dbbsf', - preventDefault: jest.fn(), - }; - - jest.spyOn(modalMaintenance, 'show'); - modalMaintenance.actionModalFromKeyboard(evt); - - expect(modalMaintenance.show).toHaveBeenCalledWith(evt); - }); it('actionModalFromClick should show the modal for save action', () => { const evt = { target: {