From 0c2ba054c98f30d3744511ec8762a19767c73ce4 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 10 Jan 2019 19:39:49 +0200 Subject: [PATCH 1/7] Setup enzyme and initial ScheduleDialog test --- .../app/components/queries/ScheduleDialog.jsx | 4 +- .../components/queries/ScheduleDialog.test.js | 44 ++ .../__snapshots__/ScheduleDialog.test.js.snap | 257 ++++++++ client/app/jest_setup.js | 4 + package-lock.json | 559 ++++++++++++++++++ package.json | 16 + 6 files changed, 882 insertions(+), 2 deletions(-) create mode 100644 client/app/components/queries/ScheduleDialog.test.js create mode 100644 client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap create mode 100644 client/app/jest_setup.js diff --git a/client/app/components/queries/ScheduleDialog.jsx b/client/app/components/queries/ScheduleDialog.jsx index 7455e14c5e..f264882c34 100644 --- a/client/app/components/queries/ScheduleDialog.jsx +++ b/client/app/components/queries/ScheduleDialog.jsx @@ -18,7 +18,7 @@ const DATE_FORMAT = 'YYYY-MM-DD'; const HOUR_FORMAT = 'HH:mm'; const { Option, OptGroup } = Select; -class ScheduleDialog extends React.Component { +export class ScheduleDialog extends React.Component { static propTypes = { show: PropTypes.bool.isRequired, // eslint-disable-next-line react/forbid-prop-types @@ -178,7 +178,7 @@ class ScheduleDialog extends React.Component { >
Refresh every
-
+
+ + + + +
+`; diff --git a/client/app/jest_setup.js b/client/app/jest_setup.js new file mode 100644 index 0000000000..8dd51397ba --- /dev/null +++ b/client/app/jest_setup.js @@ -0,0 +1,4 @@ +import { configure } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; + +configure({ adapter: new Adapter() }); diff --git a/package-lock.json b/package-lock.json index ccdebe1a68..2f81b34e73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1035,6 +1035,74 @@ "integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=", "dev": true }, + "array.prototype.flat": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.2.1.tgz", + "integrity": "sha512-rVqIs330nLJvfC7JqYvEWwqVr5QjYF1ib02i3YJtR/fICO6527Tjpc/e4Mvmxh3GIePPreRXMdaGyC99YphWEw==", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "es-abstract": "^1.10.0", + "function-bind": "^1.1.1" + }, + "dependencies": { + "es-abstract": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", + "integrity": "sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.0", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "is-callable": "^1.1.4", + "is-regex": "^1.0.4", + "object-keys": "^1.0.12" + } + }, + "es-to-primitive": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", + "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "dev": true + }, + "is-symbol": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", + "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.0" + } + }, + "object-keys": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz", + "integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==", + "dev": true + } + } + }, "arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", @@ -3099,6 +3167,74 @@ "integrity": "sha1-Ro9XGkQ1wkJI9f0MsOjYfDw0Hn0=", "dev": true }, + "cheerio": { + "version": "1.0.0-rc.2", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.2.tgz", + "integrity": "sha1-S59TqBsn5NXawxwP/Qz6A8xoMNs=", + "dev": true, + "requires": { + "css-select": "~1.2.0", + "dom-serializer": "~0.1.0", + "entities": "~1.1.1", + "htmlparser2": "^3.9.1", + "lodash": "^4.15.0", + "parse5": "^3.0.1" + }, + "dependencies": { + "domhandler": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz", + "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==", + "dev": true, + "requires": { + "domelementtype": "1" + } + }, + "htmlparser2": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.0.tgz", + "integrity": "sha512-J1nEUGv+MkXS0weHNWVKJJ+UrLfePxRWpN3C9bEi9fLxL2+ggW94DQvgYVXsaT30PGwYRIZKNZXuyMhp3Di4bQ==", + "dev": true, + "requires": { + "domelementtype": "^1.3.0", + "domhandler": "^2.3.0", + "domutils": "^1.5.1", + "entities": "^1.1.1", + "inherits": "^2.0.1", + "readable-stream": "^3.0.6" + } + }, + "parse5": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz", + "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "readable-stream": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.1.1.tgz", + "integrity": "sha512-DkN66hPyqDhnIQ6Jcsvx9bFjhw214O4poMBcIMgPVpQvNy9a0e0Uhg5SqySyDKAmUlwt8LonTBz1ezOnM8pUdA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "string_decoder": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.2.0.tgz", + "integrity": "sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, "chokidar": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.0.4.tgz", @@ -4493,6 +4629,12 @@ } } }, + "discontinuous-range": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", + "integrity": "sha1-44Mx8IRLukm5qctxx3FYWqsbxlo=", + "dev": true + }, "dns-equal": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/dns-equal/-/dns-equal-1.0.0.tgz", @@ -4843,6 +4985,122 @@ "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=", "dev": true }, + "enzyme": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/enzyme/-/enzyme-3.8.0.tgz", + "integrity": "sha512-bfsWo5nHyZm1O1vnIsbwdfhU989jk+squU9NKvB+Puwo5j6/Wg9pN5CO0YJelm98Dao3NPjkDZk+vvgwpMwYxw==", + "dev": true, + "requires": { + "array.prototype.flat": "^1.2.1", + "cheerio": "^1.0.0-rc.2", + "function.prototype.name": "^1.1.0", + "has": "^1.0.3", + "is-boolean-object": "^1.0.0", + "is-callable": "^1.1.4", + "is-number-object": "^1.0.3", + "is-string": "^1.0.4", + "is-subset": "^0.1.1", + "lodash.escape": "^4.0.1", + "lodash.isequal": "^4.5.0", + "object-inspect": "^1.6.0", + "object-is": "^1.0.1", + "object.assign": "^4.1.0", + "object.entries": "^1.0.4", + "object.values": "^1.0.4", + "raf": "^3.4.0", + "rst-selector-parser": "^2.2.3", + "string.prototype.trim": "^1.1.2" + }, + "dependencies": { + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "dev": true + } + } + }, + "enzyme-adapter-react-16": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.7.1.tgz", + "integrity": "sha512-OQXKgfHWyHN3sFu2nKj3mhgRcqIPIJX6aOzq5AHVFES4R9Dw/vCBZFMPyaG81g2AZ5DogVh39P3MMNUbqNLTcw==", + "dev": true, + "requires": { + "enzyme-adapter-utils": "^1.9.0", + "function.prototype.name": "^1.1.0", + "object.assign": "^4.1.0", + "object.values": "^1.0.4", + "prop-types": "^15.6.2", + "react-is": "^16.6.1", + "react-test-renderer": "^16.0.0-0" + }, + "dependencies": { + "prop-types": { + "version": "15.6.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", + "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", + "dev": true, + "requires": { + "loose-envify": "^1.3.1", + "object-assign": "^4.1.1" + } + }, + "react-is": { + "version": "16.7.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.7.0.tgz", + "integrity": "sha512-Z0VRQdF4NPDoI0tsXVMLkJLiwEBa+RP66g0xDHxgxysxSoCUccSten4RTF/UFvZF1dZvZ9Zu1sx+MDXwcOR34g==", + "dev": true + } + } + }, + "enzyme-adapter-utils": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/enzyme-adapter-utils/-/enzyme-adapter-utils-1.9.1.tgz", + "integrity": "sha512-LWc88BbKztLXlpRf5Ba/pSMJRaNezAwZBvis3N/IuB65ltZEh2E2obWU9B36pAbw7rORYeBUuqc79OL17ZzN1A==", + "dev": true, + "requires": { + "function.prototype.name": "^1.1.0", + "object.assign": "^4.1.0", + "prop-types": "^15.6.2", + "semver": "^5.6.0" + }, + "dependencies": { + "prop-types": { + "version": "15.6.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", + "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", + "dev": true, + "requires": { + "loose-envify": "^1.3.1", + "object-assign": "^4.1.1" + } + }, + "semver": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "dev": true + } + } + }, + "enzyme-to-json": { + "version": "3.3.5", + "resolved": "https://registry.npmjs.org/enzyme-to-json/-/enzyme-to-json-3.3.5.tgz", + "integrity": "sha512-DmH1wJ68HyPqKSYXdQqB33ZotwfUhwQZW3IGXaNXgR69Iodaoj8TF/D9RjLdz4pEhGq2Tx2zwNUIjBuqoZeTgA==", + "dev": true, + "requires": { + "lodash": "^4.17.4" + } + }, "errno": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.4.tgz", @@ -6928,6 +7186,17 @@ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, + "function.prototype.name": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.0.tgz", + "integrity": "sha512-Bs0VRrTz4ghD8pTmbJQD1mZ8A/mN0ur/jGz+A6FBxPDUPkm1tNfF6bhTYPA7i7aF4lZJVr+OXTNNrnnIl58Wfg==", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "is-callable": "^1.1.3" + } + }, "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", @@ -7873,6 +8142,12 @@ } } }, + "harmony-reflect": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/harmony-reflect/-/harmony-reflect-1.6.1.tgz", + "integrity": "sha512-WJTeyp0JzGtHcuMsi7rw2VwtkvLa+JyfEKJCFyfcS0+CDkjQ5lHPu7zEhFZP+PDSRrEgXa5Ah0l1MbgbE41XjA==", + "dev": true + }, "has": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has/-/has-1.0.1.tgz", @@ -7912,6 +8187,12 @@ "is-browser": "^2.0.1" } }, + "has-symbols": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", + "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", + "dev": true + }, "has-value": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/has-value/-/has-value-1.0.0.tgz", @@ -8328,6 +8609,15 @@ } } }, + "identity-obj-proxy": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/identity-obj-proxy/-/identity-obj-proxy-3.0.0.tgz", + "integrity": "sha1-lNK9qWCERT7zb7xarsN+D3nx/BQ=", + "dev": true, + "requires": { + "harmony-reflect": "^1.4.6" + } + }, "ieee754": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz", @@ -8642,6 +8932,12 @@ "binary-extensions": "^1.0.0" } }, + "is-boolean-object": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.0.0.tgz", + "integrity": "sha1-mPiygDBoQhmpXzdc+9iM40Bd/5M=", + "dev": true + }, "is-browser": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-browser/-/is-browser-2.1.0.tgz", @@ -8792,6 +9088,12 @@ "kind-of": "^3.0.2" } }, + "is-number-object": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.3.tgz", + "integrity": "sha1-8mWrian0RQNO9q/xWo8AsA9VF5k=", + "dev": true + }, "is-obj": { "version": "1.0.1", "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", @@ -8881,6 +9183,18 @@ "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" }, + "is-string": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.4.tgz", + "integrity": "sha1-zDqbaYV9Yh6WNyWiTK7shzuCbmQ=", + "dev": true + }, + "is-subset": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz", + "integrity": "sha1-ilkRfZMt4d4A8kX83TnOQ/HpOaY=", + "dev": true + }, "is-svg": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-svg/-/is-svg-2.1.0.tgz", @@ -10686,6 +11000,18 @@ "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=" }, + "lodash.escape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-4.0.1.tgz", + "integrity": "sha1-yQRGkMIeBClL6qUXcS/e0fqI3pg=", + "dev": true + }, + "lodash.flattendeep": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", + "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", + "dev": true + }, "lodash.frompairs": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.frompairs/-/lodash.frompairs-4.0.1.tgz", @@ -10711,6 +11037,12 @@ "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz", "integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=" }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=", + "dev": true + }, "lodash.keys": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz", @@ -11462,6 +11794,12 @@ "robust-orientation": "^1.1.3" } }, + "moo": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/moo/-/moo-0.4.3.tgz", + "integrity": "sha512-gFD2xGCl8YFgGHsqJ9NKRVdwlioeW3mI1iqfLNYQOv0+6JRwG58Zk9DIGQgyIaffSYaO1xsKnMaYzzNr1KyIAw==", + "dev": true + }, "mouse-change": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/mouse-change/-/mouse-change-1.4.0.tgz", @@ -11729,6 +12067,27 @@ "ndarray-linear-interpolate": "^1.0.0" } }, + "nearley": { + "version": "2.16.0", + "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.16.0.tgz", + "integrity": "sha512-Tr9XD3Vt/EujXbZBv6UAHYoLUSMQAxSsTnm9K3koXzjzNWY195NqALeyrzLZBKzAkL3gl92BcSogqrHjD8QuUg==", + "dev": true, + "requires": { + "commander": "^2.19.0", + "moo": "^0.4.3", + "railroad-diagrams": "^1.0.0", + "randexp": "0.4.6", + "semver": "^5.4.1" + }, + "dependencies": { + "commander": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", + "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==", + "dev": true + } + } + }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", @@ -12059,6 +12418,12 @@ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz", "integrity": "sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ==" }, + "object-is": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.0.1.tgz", + "integrity": "sha1-CqYOyZiaCz7Xlc9NBvYs8a1lObY=", + "dev": true + }, "object-keys": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.11.tgz", @@ -12073,6 +12438,96 @@ "isobject": "^3.0.0" } }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.0", + "object-keys": "^1.0.11" + } + }, + "object.entries": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.0.tgz", + "integrity": "sha512-l+H6EQ8qzGRxbkHOd5I/aHRhHDKoQXQ8g0BYt4uSweQU1/J6dZUOyWh9a2Vky35YCKjzmgxOzta2hH6kf9HuXA==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.12.0", + "function-bind": "^1.1.1", + "has": "^1.0.3" + }, + "dependencies": { + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "dev": true, + "requires": { + "object-keys": "^1.0.12" + } + }, + "es-abstract": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", + "integrity": "sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.0", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "is-callable": "^1.1.4", + "is-regex": "^1.0.4", + "object-keys": "^1.0.12" + } + }, + "es-to-primitive": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", + "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "dev": true + }, + "is-symbol": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", + "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.0" + } + }, + "object-keys": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz", + "integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==", + "dev": true + } + } + }, "object.getownpropertydescriptors": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", @@ -12102,6 +12557,84 @@ "isobject": "^3.0.1" } }, + "object.values": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.0.tgz", + "integrity": "sha512-8mf0nKLAoFX6VlNVdhGj31SVYpaNFtUnuoOXWyFEstsWRgU837AK+JYM0iAxwkSzGRbwn8cbFmgbyxj1j4VbXg==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.12.0", + "function-bind": "^1.1.1", + "has": "^1.0.3" + }, + "dependencies": { + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "dev": true, + "requires": { + "object-keys": "^1.0.12" + } + }, + "es-abstract": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", + "integrity": "sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.0", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "is-callable": "^1.1.4", + "is-regex": "^1.0.4", + "object-keys": "^1.0.12" + } + }, + "es-to-primitive": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", + "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "dev": true + }, + "is-symbol": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", + "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.0" + } + }, + "object-keys": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz", + "integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==", + "dev": true + } + } + }, "obuf": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz", @@ -13777,6 +14310,22 @@ "performance-now": "^2.1.0" } }, + "railroad-diagrams": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", + "integrity": "sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=", + "dev": true + }, + "randexp": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", + "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", + "dev": true, + "requires": { + "discontinuous-range": "1.0.0", + "ret": "~0.1.10" + } + }, "randomatic": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.0.tgz", @@ -15213,6 +15762,16 @@ "resolved": "https://registry.npmjs.org/robust-sum/-/robust-sum-1.0.0.tgz", "integrity": "sha1-FmRuUlKStNJdgnV6KGlV4Lv6U9k=" }, + "rst-selector-parser": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz", + "integrity": "sha1-gbIw6i/MYGbInjRy3nlChdmwPZE=", + "dev": true, + "requires": { + "lodash.flattendeep": "^4.4.0", + "nearley": "^2.7.10" + } + }, "rsvp": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-3.6.2.tgz", diff --git a/package.json b/package.json index a9b35b2958..45c5e51de5 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,9 @@ "babel-preset-stage-2": "^6.24.1", "copy-webpack-plugin": "^4.5.3", "css-loader": "^0.28.7", + "enzyme": "^3.8.0", + "enzyme-adapter-react-16": "^1.7.1", + "enzyme-to-json": "^3.3.5", "eslint": "^4.19.1", "eslint-config-airbnb": "^16.1.0", "eslint-config-airbnb-base": "^12.0.1", @@ -107,6 +110,7 @@ "eslint-plugin-react": "^7.7.0", "file-loader": "^2.0.0", "html-webpack-plugin": "^3.2.0", + "identity-obj-proxy": "^3.0.0", "jest": "^23.6.0", "less": "^2.7.3", "less-loader": "^4.1.0", @@ -125,5 +129,17 @@ }, "optionalDependencies": { "fsevents": "^1.2.4" + }, + "jest": { + "setupFiles": [ + "./client/app/jest_setup.js" + ], + "snapshotSerializers": [ + "enzyme-to-json/serializer" + ], + "moduleNameMapper": { + "^@/(.*)": "/client/app/$1", + "\\.(css|less)$": "identity-obj-proxy" + } } } From 9fdc38a6f44100bc33d907d0ee29726468638031 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 10 Jan 2019 19:53:51 +0200 Subject: [PATCH 2/7] Added tests for each schedule setting --- .../app/components/queries/ScheduleDialog.jsx | 28 +- .../components/queries/ScheduleDialog.test.js | 77 +- .../__snapshots__/ScheduleDialog.test.js.snap | 2548 +++++++++++++++++ 3 files changed, 2639 insertions(+), 14 deletions(-) diff --git a/client/app/components/queries/ScheduleDialog.jsx b/client/app/components/queries/ScheduleDialog.jsx index f264882c34..d33b961e76 100644 --- a/client/app/components/queries/ScheduleDialog.jsx +++ b/client/app/components/queries/ScheduleDialog.jsx @@ -194,7 +194,7 @@ export class ScheduleDialog extends React.Component { {[IntervalEnum.DAYS, IntervalEnum.WEEKS].indexOf(interval) !== -1 ? (
On time
-
+
On day
- - {WEEKDAYS_SHORT.map(day => ( - - {day[0]} - - ))} - +
+ + {WEEKDAYS_SHORT.map(day => ( + + {day[0]} + + ))} + +
) : null} {interval !== IntervalEnum.NEVER ? (
Ends
-
+
), props]; } +function findByTestID(wrapper, id) { + return wrapper.find(`[data-testid="${id}"]`); +} + describe('ScheduleDialog', () => { + beforeAll(() => { + // mock date string so snapshots don't get invalidated + window.Date.prototype.toISOString = jest.fn(() => 'mocked ISO'); + }); + describe('Sets correct schedule settings', () => { test('Sets to "Never"', () => { const [wrapper] = getWrapper(); - const el = wrapper.find('[data-testid="interval"]'); + const el = findByTestID(wrapper, 'interval'); expect(el).toMatchSnapshot(); }); + + test('Sets to "5 Minutes"', () => { + const [wrapper] = getWrapper({ interval: 300 }); + const el = findByTestID(wrapper, 'interval'); + expect(el).toMatchSnapshot(); + }); + + test('Sets to "2 Hours"', () => { + const [wrapper] = getWrapper({ interval: 7200 }); + const el = findByTestID(wrapper, 'interval'); + expect(el).toMatchSnapshot(); + }); + + describe('Sets to "1 Day 22:15"', () => { + const [wrapper] = getWrapper({ + interval: 86400, + time: '22:15', + }); + + test('Sets to correct interval', () => { + const el = findByTestID(wrapper, 'interval'); + expect(el).toMatchSnapshot(); + }); + + test('Sets to correct time', () => { + const el = findByTestID(wrapper, 'time'); + expect(el).toMatchSnapshot(); + }); + }); + + describe('Sets to "2 Weeks 22:15 Tuesday"', () => { + const [wrapper] = getWrapper({ + interval: 1209600, + time: '22:15', + day_of_week: 2, + }); + + test('Sets to correct interval', () => { + const el = findByTestID(wrapper, 'interval'); + expect(el).toMatchSnapshot(); + }); + + test('Sets to correct time', () => { + const el = findByTestID(wrapper, 'time'); + expect(el).toMatchSnapshot(); + }); + + test('Sets to correct weekday', () => { + const el = findByTestID(wrapper, 'weekday'); + expect(el).toMatchSnapshot(); + }); + }); + + describe('Until feature', () => { + test('Until not set', () => { + const [wrapper] = getWrapper({ interval: 300 }); + const el = findByTestID(wrapper, 'ends'); + expect(el).toMatchSnapshot(); + }); + + test('Until is set', () => { + const [wrapper] = getWrapper({ interval: 300, until: '2030-01-01' }); + const el = findByTestID(wrapper, 'ends'); + expect(el).toMatchSnapshot(); + }); + }); }); }); diff --git a/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap b/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap index 4c104f2a4a..3e86802c66 100644 --- a/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap +++ b/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap @@ -1,5 +1,1936 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Sets to correct interval 1`] = ` +
+ + + + } + popupAlign={Object {}} + popupClassName="ant-select-dropdown--single" + popupPlacement="bottomLeft" + popupStyle={Object {}} + popupTransitionName="slide-up" + popupVisible={false} + prefixCls="ant-select-dropdown" + showAction={ + Array [ + "click", + ] + } + showSearch={false} + transitionName="slide-up" + value={ + Array [ + 86400, + ] + } + visible={false} + > +
+
+
+
+ 1 day +
+
+ + + +
+
+
+
+ + + +
+`; + +exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Sets to correct time 1`] = ` +
+ + + + + } + popupAlign={ + Object { + "offset": Array [ + 0, + -2, + ], + } + } + popupClassName=" ant-time-picker-panel-narrow ant-time-picker-panel-column-2" + popupPlacement="bottomLeft" + popupStyle={Object {}} + popupTransitionName="slide-up" + popupVisible={false} + prefixCls="ant-time-picker-panel" + showAction={Array []} + > + + + + + + + + +
+`; + +exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Hours" 1`] = ` +
+ + + + } + popupAlign={Object {}} + popupClassName="ant-select-dropdown--single" + popupPlacement="bottomLeft" + popupStyle={Object {}} + popupTransitionName="slide-up" + popupVisible={false} + prefixCls="ant-select-dropdown" + showAction={ + Array [ + "click", + ] + } + showSearch={false} + transitionName="slide-up" + value={ + Array [ + 7200, + ] + } + visible={false} + > +
+
+
+
+ 7200 +
+
+ + + +
+
+
+
+ + + +
+`; + +exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tuesday" Sets to correct interval 1`] = ` +
+ + + + } + popupAlign={Object {}} + popupClassName="ant-select-dropdown--single" + popupPlacement="bottomLeft" + popupStyle={Object {}} + popupTransitionName="slide-up" + popupVisible={false} + prefixCls="ant-select-dropdown" + showAction={ + Array [ + "click", + ] + } + showSearch={false} + transitionName="slide-up" + value={ + Array [ + 1209600, + ] + } + visible={false} + > +
+
+
+
+ 2 weeks +
+
+ + + +
+
+
+
+ + + +
+`; + +exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tuesday" Sets to correct time 1`] = ` +
+ + + + + } + popupAlign={ + Object { + "offset": Array [ + 0, + -2, + ], + } + } + popupClassName=" ant-time-picker-panel-narrow ant-time-picker-panel-column-2" + popupPlacement="bottomLeft" + popupStyle={Object {}} + popupTransitionName="slide-up" + popupVisible={false} + prefixCls="ant-time-picker-panel" + showAction={Array []} + > + + + + + + + + +
+`; + +exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tuesday" Sets to correct weekday 1`] = ` +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+`; + +exports[`ScheduleDialog Sets correct schedule settings Sets to "5 Minutes" 1`] = ` +
+ + + + } + popupAlign={Object {}} + popupClassName="ant-select-dropdown--single" + popupPlacement="bottomLeft" + popupStyle={Object {}} + popupTransitionName="slide-up" + popupVisible={false} + prefixCls="ant-select-dropdown" + showAction={ + Array [ + "click", + ] + } + showSearch={false} + transitionName="slide-up" + value={ + Array [ + 300, + ] + } + visible={false} + > +
+
+
+
+ 5 minutes +
+
+ + + +
+
+
+
+ + + +
+`; + exports[`ScheduleDialog Sets correct schedule settings Sets to "Never" 1`] = `
`; + +exports[`ScheduleDialog Sets correct schedule settings Until feature Until is set 1`] = ` +
+ +
+ + + + + + +
+
+ + + + + + } + className="datepicker" + defaultOpen={false} + format="YYYY-MM-DD" + inputPrefixCls="ant-input" + locale={ + Object { + "lang": Object { + "backToToday": "Back to today", + "clear": "Clear", + "dateFormat": "M/D/YYYY", + "dateSelect": "select date", + "dateTimeFormat": "M/D/YYYY HH:mm:ss", + "dayFormat": "D", + "decadeSelect": "Choose a decade", + "month": "Month", + "monthBeforeYear": true, + "monthSelect": "Choose a month", + "nextCentury": "Next century", + "nextDecade": "Next decade", + "nextMonth": "Next month (PageDown)", + "nextYear": "Next year (Control + right)", + "now": "Now", + "ok": "Ok", + "placeholder": "Select date", + "previousCentury": "Last century", + "previousDecade": "Last decade", + "previousMonth": "Previous month (PageUp)", + "previousYear": "Last year (Control + left)", + "rangePlaceholder": Array [ + "Start date", + "End date", + ], + "timeSelect": "select time", + "today": "Today", + "weekSelect": "Choose a week", + "year": "Year", + "yearFormat": "YYYY", + "yearSelect": "Choose a year", + }, + "timePickerLocale": Object { + "placeholder": "Select time", + }, + } + } + onBlur={[Function]} + onChange={[Function]} + onFocus={[Function]} + onOk={[Function]} + onOpenChange={[Function]} + pickerClass="ant-calendar-picker ant-calendar-picker-small" + pickerInputClass="ant-calendar-picker-input ant-input ant-input-sm" + placement="bottomLeft" + popupStyle={Object {}} + prefixCls="ant-calendar-picker-container" + showToday={true} + size="small" + style={Object {}} + timePicker={null} + transitionName="slide-up" + value={"mocked ISO"} + > + + } + popupAlign={Object {}} + popupClassName="" + popupPlacement="bottomLeft" + popupStyle={Object {}} + popupTransitionName="slide-up" + popupVisible={false} + prefixCls="ant-calendar-picker-container" + showAction={Array []} + > +
+ + +
+
+
+
+
+
+
+
+`; + +exports[`ScheduleDialog Sets correct schedule settings Until feature Until not set 1`] = ` +
+ +
+ + + + + + +
+
+
+`; From a0be1ebdf87242626eb8ef4666226fc14b08acda Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 10 Jan 2019 20:01:37 +0200 Subject: [PATCH 3/7] Added refreshOptions tests --- .../components/queries/ScheduleDialog.test.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/client/app/components/queries/ScheduleDialog.test.js b/client/app/components/queries/ScheduleDialog.test.js index b7c48a41f6..2f388c9b9a 100644 --- a/client/app/components/queries/ScheduleDialog.test.js +++ b/client/app/components/queries/ScheduleDialog.test.js @@ -37,6 +37,26 @@ function findByTestID(wrapper, id) { return wrapper.find(`[data-testid="${id}"]`); } +function getSelectOptions(wrapper) { + jest.useFakeTimers(); + + // click select + wrapper.find('.ant-select').simulate('click'); + + // run timers + jest.runAllTimers(); + jest.useRealTimers(); + + // get dropdown menu + const dropdown = mount(wrapper + .find('Trigger') + .instance() + .getComponent()); + + // get menu items + return dropdown.find('MenuItem'); +} + describe('ScheduleDialog', () => { beforeAll(() => { // mock date string so snapshots don't get invalidated @@ -116,4 +136,35 @@ describe('ScheduleDialog', () => { }); }); }); + + describe('Adheres to user permissions', () => { + test('Shows correct interval options', () => { + const refreshOptions = [60, 3600]; // 1 min, 1 hour + const [wrapper] = getWrapper(null, { refreshOptions }); + const selectWrapper = findByTestID(wrapper, 'select-interval'); + const options = getSelectOptions(selectWrapper); + + const texts = options.map(node => node.text()); + const expected = ['Never', 'minute(s)', 'hour(s)']; + + // eslint-disable-next-line jest/prefer-to-have-length + expect(options.length).toEqual(expected.length); + expect(texts).toEqual(expected); + }); + + // skipped due to issue #3263 https://git.io/fhZcG + // eslint-disable-next-line jest/no-disabled-tests + test.skip('Shows correct count options', () => { + const [wrapper] = getWrapper({ interval: 300 }); + const selectWrapper = findByTestID(wrapper, 'select-count'); + const options = getSelectOptions(selectWrapper); + + const texts = options.map(node => node.text()); + const expected = ['1', '5', '10']; + + // eslint-disable-next-line jest/prefer-to-have-length + expect(options.length).toEqual(expected.length); + expect(texts).toEqual(expected); + }); + }); }); From 382e0a9c3117c65d9a09a36b0ce573c7aa71d013 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 10 Jan 2019 20:08:46 +0200 Subject: [PATCH 4/7] Added count out-of-range tests --- .../components/queries/ScheduleDialog.test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/client/app/components/queries/ScheduleDialog.test.js b/client/app/components/queries/ScheduleDialog.test.js index 2f388c9b9a..e7a565cfb6 100644 --- a/client/app/components/queries/ScheduleDialog.test.js +++ b/client/app/components/queries/ScheduleDialog.test.js @@ -167,4 +167,31 @@ describe('ScheduleDialog', () => { expect(texts).toEqual(expected); }); }); + + test('Resets selected count value if out-of-range', () => { + // init + const initProps = { interval: 600 }; + const [wrapper] = getWrapper(initProps); + + const intervalWrapper = findByTestID(wrapper, 'select-interval'); + const options = getSelectOptions(intervalWrapper); + + // change to 'hours(s)' + options + .filterWhere(node => node.text() === 'hour(s)') + .simulate('click'); + wrapper.update(); + + // should stay '10' + expect(wrapper.state('count')).toBe('10'); + + // change to 'week(s)' + options + .filterWhere(node => node.text() === 'week(s)') + .simulate('click'); + wrapper.update(); + + // should have changed to '1' + expect(wrapper.state('count')).toBe('1'); + }); }); From 6af9186cf0fdae05547576509532191960d9a009 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 10 Jan 2019 20:10:27 +0200 Subject: [PATCH 5/7] Added modal confirm/cancel tests --- .../components/queries/ScheduleDialog.test.js | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/client/app/components/queries/ScheduleDialog.test.js b/client/app/components/queries/ScheduleDialog.test.js index e7a565cfb6..4dc11de458 100644 --- a/client/app/components/queries/ScheduleDialog.test.js +++ b/client/app/components/queries/ScheduleDialog.test.js @@ -194,4 +194,69 @@ describe('ScheduleDialog', () => { // should have changed to '1' expect(wrapper.state('count')).toBe('1'); }); + + describe('Modal Confirm/Cancel feature', () => { + const confirmCb = jest.fn().mockName('confirmCb'); + const closeCb = jest.fn().mockName('closeCb'); + const initProps = { updateQuery: confirmCb, onClose: closeCb }; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + test('Query saved on confirm if state changed', () => { + // init + const [wrapper, props] = getWrapper(null, initProps); + + // change state + const change = { time: '22:15' }; + const newSchedule = Object.assign({}, props.schedule, change); + wrapper.setState({ newSchedule }); + + // click confirm button + wrapper + .find('.ant-modal-footer') + .find('.ant-btn-primary') + .simulate('click'); + + // expect calls + expect(confirmCb).toBeCalled(); + expect(closeCb).toBeCalled(); + }); + + test('Query not saved on confirm if state unchanged', () => { + // init + const [wrapper] = getWrapper(null, initProps); + + // click confirm button + wrapper + .find('.ant-modal-footer') + .find('.ant-btn-primary') + .simulate('click'); + + // expect calls + expect(confirmCb).not.toBeCalled(); + expect(closeCb).toBeCalled(); + }); + + test('Cancel closes modal and query unsaved', () => { + // init + const [wrapper, props] = getWrapper(null, initProps); + + // change state + const change = { time: '22:15' }; + const newSchedule = Object.assign({}, props.schedule, change); + wrapper.setState({ newSchedule }); + + // click cancel button + wrapper + .find('.ant-modal-footer') + .find('button:not(.ant-btn-primary)') + .simulate('click'); + + // expect calls + expect(confirmCb).not.toBeCalled(); + expect(closeCb).toBeCalled(); + }); + }); }); From a746c6f08b93461529a99a0e08c6f7e8d3a21218 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 10 Jan 2019 20:44:33 +0200 Subject: [PATCH 6/7] Fixed tests failing due to server timezone difference --- .../enzyme_setup.js} | 2 +- client/app/__tests__/mocks.js | 5 +++ .../components/queries/ScheduleDialog.test.js | 5 --- .../__snapshots__/ScheduleDialog.test.js.snap | 36 +++++++++---------- package-lock.json | 6 ++++ package.json | 11 ++++-- 6 files changed, 38 insertions(+), 27 deletions(-) rename client/app/{jest_setup.js => __tests__/enzyme_setup.js} (70%) create mode 100644 client/app/__tests__/mocks.js diff --git a/client/app/jest_setup.js b/client/app/__tests__/enzyme_setup.js similarity index 70% rename from client/app/jest_setup.js rename to client/app/__tests__/enzyme_setup.js index 8dd51397ba..82edfc9e5a 100644 --- a/client/app/jest_setup.js +++ b/client/app/__tests__/enzyme_setup.js @@ -1,4 +1,4 @@ -import { configure } from 'enzyme'; +import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() }); diff --git a/client/app/__tests__/mocks.js b/client/app/__tests__/mocks.js new file mode 100644 index 0000000000..14fccbe90b --- /dev/null +++ b/client/app/__tests__/mocks.js @@ -0,0 +1,5 @@ +import MockDate from 'mockdate'; + +const date = new Date('2000-01-01T02:00:00.000'); + +MockDate.set(date); diff --git a/client/app/components/queries/ScheduleDialog.test.js b/client/app/components/queries/ScheduleDialog.test.js index 4dc11de458..beb9730fb7 100644 --- a/client/app/components/queries/ScheduleDialog.test.js +++ b/client/app/components/queries/ScheduleDialog.test.js @@ -58,11 +58,6 @@ function getSelectOptions(wrapper) { } describe('ScheduleDialog', () => { - beforeAll(() => { - // mock date string so snapshots don't get invalidated - window.Date.prototype.toISOString = jest.fn(() => 'mocked ISO'); - }); - describe('Sets correct schedule settings', () => { test('Sets to "Never"', () => { const [wrapper] = getWrapper(); diff --git a/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap b/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap index 3e86802c66..db4c3e1f00 100644 --- a/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap +++ b/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap @@ -270,7 +270,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Set } } allowEmpty={false} - defaultValue={"mocked ISO"} + defaultValue={"1999-12-31T22:15:00.000Z"} disabled={false} focusOnOpen={true} format="HH:mm" @@ -304,7 +304,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Set className="" clearText="clear" defaultOpen={false} - defaultOpenValue={"mocked ISO"} + defaultOpenValue={"2000-01-01T00:00:00.000Z"} disabled={false} disabledHours={[Function]} disabledMinutes={[Function]} @@ -331,7 +331,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Set style={Object {}} transitionName="slide-up" use12Hours={false} - value={"mocked ISO"} + value={"1999-12-31T22:15:00.000Z"} > } popupAlign={ @@ -1030,7 +1030,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tu } } allowEmpty={false} - defaultValue={"mocked ISO"} + defaultValue={"1999-12-31T22:15:00.000Z"} disabled={false} focusOnOpen={true} format="HH:mm" @@ -1064,7 +1064,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tu className="" clearText="clear" defaultOpen={false} - defaultOpenValue={"mocked ISO"} + defaultOpenValue={"2000-01-01T00:00:00.000Z"} disabled={false} disabledHours={[Function]} disabledMinutes={[Function]} @@ -1091,7 +1091,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tu style={Object {}} transitionName="slide-up" use12Hours={false} - value={"mocked ISO"} + value={"1999-12-31T22:15:00.000Z"} > } popupAlign={ @@ -2308,7 +2308,7 @@ exports[`ScheduleDialog Sets correct schedule settings Until feature Until is se prefixCls="ant-calendar" size="small" transitionName="slide-up" - value={"mocked ISO"} + value={"2029-12-31T22:00:00.000Z"} > } @@ -2500,7 +2500,7 @@ exports[`ScheduleDialog Sets correct schedule settings Until feature Until is se style={Object {}} timePicker={null} transitionName="slide-up" - value={"mocked ISO"} + value={"2029-12-31T22:00:00.000Z"} > } diff --git a/package-lock.json b/package-lock.json index 2f81b34e73..b2d7f5c025 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11781,6 +11781,12 @@ } } }, + "mockdate": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/mockdate/-/mockdate-2.0.2.tgz", + "integrity": "sha1-WuDA6vj+I+AJzQH5iJtCxPY0rxI=", + "dev": true + }, "moment": { "version": "2.19.3", "resolved": "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz", diff --git a/package.json b/package.json index 45c5e51de5..c56347ee7a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "watch": "webpack --watch --progress --colors -d", "analyze": "npm run clean && BUNDLE_ANALYZER=on webpack", "analyze:build": "npm run clean && NODE_ENV=production BUNDLE_ANALYZER=on webpack", - "test": "jest", + "test": "TZ=Asia/Jerusalem jest", "test:watch": "jest --watch", "cypress:install": "npm install --no-save cypress @percy/cypress", "cypress": "node cypress/cypress.js" @@ -116,6 +116,7 @@ "less-loader": "^4.1.0", "less-plugin-autoprefix": "^1.5.1", "mini-css-extract-plugin": "^0.4.4", + "mockdate": "^2.0.2", "raw-loader": "^0.5.1", "react-test-renderer": "^16.5.2", "request": "^2.88.0", @@ -132,7 +133,8 @@ }, "jest": { "setupFiles": [ - "./client/app/jest_setup.js" + "./client/app/__tests__/enzyme_setup.js", + "./client/app/__tests__/mocks.js" ], "snapshotSerializers": [ "enzyme-to-json/serializer" @@ -140,6 +142,9 @@ "moduleNameMapper": { "^@/(.*)": "/client/app/$1", "\\.(css|less)$": "identity-obj-proxy" - } + }, + "testPathIgnorePatterns": [ + "/client/app/__tests__/" + ] } } From 8b25d8a7801a10b7723b58b046eedd489798defa Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Sun, 13 Jan 2019 15:05:15 +0200 Subject: [PATCH 7/7] Rebased to master --- .../components/queries/ScheduleDialog.test.js | 76 +++---------------- 1 file changed, 12 insertions(+), 64 deletions(-) diff --git a/client/app/components/queries/ScheduleDialog.test.js b/client/app/components/queries/ScheduleDialog.test.js index beb9730fb7..cb0fc8ee2b 100644 --- a/client/app/components/queries/ScheduleDialog.test.js +++ b/client/app/components/queries/ScheduleDialog.test.js @@ -37,26 +37,6 @@ function findByTestID(wrapper, id) { return wrapper.find(`[data-testid="${id}"]`); } -function getSelectOptions(wrapper) { - jest.useFakeTimers(); - - // click select - wrapper.find('.ant-select').simulate('click'); - - // run timers - jest.runAllTimers(); - jest.useRealTimers(); - - // get dropdown menu - const dropdown = mount(wrapper - .find('Trigger') - .instance() - .getComponent()); - - // get menu items - return dropdown.find('MenuItem'); -} - describe('ScheduleDialog', () => { describe('Sets correct schedule settings', () => { test('Sets to "Never"', () => { @@ -134,28 +114,23 @@ describe('ScheduleDialog', () => { describe('Adheres to user permissions', () => { test('Shows correct interval options', () => { - const refreshOptions = [60, 3600]; // 1 min, 1 hour + const refreshOptions = [60, 300, 3600, 7200]; // 1 min, 1 hour const [wrapper] = getWrapper(null, { refreshOptions }); - const selectWrapper = findByTestID(wrapper, 'select-interval'); - const options = getSelectOptions(selectWrapper); - const texts = options.map(node => node.text()); - const expected = ['Never', 'minute(s)', 'hour(s)']; - - // eslint-disable-next-line jest/prefer-to-have-length - expect(options.length).toEqual(expected.length); - expect(texts).toEqual(expected); - }); + // click select + findByTestID(wrapper, 'interval') + .find('.ant-select') + .simulate('click'); - // skipped due to issue #3263 https://git.io/fhZcG - // eslint-disable-next-line jest/no-disabled-tests - test.skip('Shows correct count options', () => { - const [wrapper] = getWrapper({ interval: 300 }); - const selectWrapper = findByTestID(wrapper, 'select-count'); - const options = getSelectOptions(selectWrapper); + // get dropdown menu items + const options = mount(wrapper + .find('Trigger') + .instance() + .getComponent()) + .find('MenuItem'); const texts = options.map(node => node.text()); - const expected = ['1', '5', '10']; + const expected = ['Never', '1 minute', '5 minutes', '1 hour', '2 hours']; // eslint-disable-next-line jest/prefer-to-have-length expect(options.length).toEqual(expected.length); @@ -163,33 +138,6 @@ describe('ScheduleDialog', () => { }); }); - test('Resets selected count value if out-of-range', () => { - // init - const initProps = { interval: 600 }; - const [wrapper] = getWrapper(initProps); - - const intervalWrapper = findByTestID(wrapper, 'select-interval'); - const options = getSelectOptions(intervalWrapper); - - // change to 'hours(s)' - options - .filterWhere(node => node.text() === 'hour(s)') - .simulate('click'); - wrapper.update(); - - // should stay '10' - expect(wrapper.state('count')).toBe('10'); - - // change to 'week(s)' - options - .filterWhere(node => node.text() === 'week(s)') - .simulate('click'); - wrapper.update(); - - // should have changed to '1' - expect(wrapper.state('count')).toBe('1'); - }); - describe('Modal Confirm/Cancel feature', () => { const confirmCb = jest.fn().mockName('confirmCb'); const closeCb = jest.fn().mockName('closeCb');