From cd43e0b66ebda27c57bec18f00ed0f5379f936fb Mon Sep 17 00:00:00 2001 From: mbucknell <mbucknell@usgs.gov> Date: Fri, 18 Dec 2020 08:57:20 -0600 Subject: [PATCH] Added jest eslint plugin and updated the tests to use best practices --- assets/.eslintrc | 19 +- assets/package-lock.json | 162 +++++++++++--- assets/package.json | 7 +- assets/src/scripts/ajax.test.js | 17 +- assets/src/scripts/d3-rendering/axes.test.js | 4 +- .../scripts/d3-rendering/tick-marks.test.js | 50 ++--- .../daily-value-hydrograph/index.test.js | 82 ++++--- .../selectors/legend-data.test.js | 6 +- .../selectors/time-series-data.test.js | 24 +-- .../time-series-graph.test.js | 16 +- .../hydrograph/download-links.test.js | 204 ++++++++++-------- .../hydrograph/graph-controls.test.js | 48 +++-- .../components/hydrograph/index.test.js | 149 +++++++------ .../components/hydrograph/legend.test.js | 10 +- .../hydrograph/method-picker.test.js | 14 +- .../hydrograph/selectors/drawing-data.test.js | 22 +- .../hydrograph/selectors/legend-data.test.js | 14 +- .../hydrograph/time-series-graph.test.js | 32 +-- .../components/hydrograph/tooltip.test.js | 38 ++-- .../components/map/flood-slider.test.js | 13 +- .../daily-value-time-series-selector.test.js | 6 +- .../selectors/time-series-selector.test.js | 4 +- .../store/daily-value-time-series.test.js | 33 ++- .../store/flood-inundation.test.js | 24 +-- ...tantaneous-value-time-series-data.test.js} | 160 ++++++-------- ...antaneous-value-time-series-state.test.js} | 20 +- .../monitoring-location/store/network.test.js | 14 +- .../store/nldi-data.test.js | 12 +- .../store/statistics-data.test.js | 10 +- .../store/time-zone.test.js | 10 +- .../monitoring-location/url-params.test.js | 30 +-- .../src/scripts/network/store/index.test.js | 18 +- assets/src/scripts/schema.test.js | 2 +- assets/src/scripts/utils.test.js | 16 +- .../scripts/web-services/flood-data.test.js | 40 ++-- .../src/scripts/web-services/models.test.js | 10 +- .../scripts/web-services/nldi-data.test.js | 56 ++--- .../scripts/web-services/observations.test.js | 95 ++++---- .../web-services/statistics-data.test.js | 5 +- 39 files changed, 810 insertions(+), 686 deletions(-) rename assets/src/scripts/monitoring-location/store/{instantaneous-value-time-series-data.spec.js => instantaneous-value-time-series-data.test.js} (83%) rename assets/src/scripts/monitoring-location/store/{instantaneous-value-time-series-state.spec.js => instantaneous-value-time-series-state.test.js} (95%) diff --git a/assets/.eslintrc b/assets/.eslintrc index 6a9ed0be1..6bab622d3 100644 --- a/assets/.eslintrc +++ b/assets/.eslintrc @@ -2,16 +2,14 @@ "env": { "commonjs": true, "es6": true, - "jasmine": true + "jest/globals": true }, "parserOptions": { "ecmaVersion": 2018, "sourceType": "module" }, - "plugins": [ - "jasmine" - ], - "extends": "eslint:recommended", + "plugins": ["jest"], + "extends": ["eslint:recommended", "plugin:jest/recommended"], "rules": { "array-bracket-spacing": ["error", "never"], "brace-style": ["error","1tbs", {}], @@ -26,9 +24,13 @@ "quotes": ["error", "single"], "semi": ["error", "always"], "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["error", "never"] + "space-before-function-paren": ["error", "never"], + "jest/no-disabled-tests": "warn", + "jest/no-focused-tests": "error", + "jest/no-identical-title": "error", + "jest/prefer-to-have-length": "warn", + "jest/valid-expect": "error" }, - "overrides": [ { "files": ["src/scripts/**/*.test.js"], @@ -45,7 +47,6 @@ "process": true, "XMLHttpRequest": true, "window": true, - "L": true, - "jest": true + "L": true } } diff --git a/assets/package-lock.json b/assets/package-lock.json index 6e05b5bd3..43c48edec 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -2592,6 +2592,12 @@ "@types/istanbul-lib-report": "*" } }, + "@types/json-schema": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.6.tgz", + "integrity": "sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==", + "dev": true + }, "@types/mdast": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-3.0.3.tgz", @@ -2671,6 +2677,108 @@ "integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==", "dev": true }, + "@typescript-eslint/experimental-utils": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.10.0.tgz", + "integrity": "sha512-opX+7ai1sdWBOIoBgpVJrH5e89ra1KoLrJTz0UtWAa4IekkKmqDosk5r6xqRaNJfCXEfteW4HXQAwMdx+jjEmw==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/scope-manager": "4.10.0", + "@typescript-eslint/types": "4.10.0", + "@typescript-eslint/typescript-estree": "4.10.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + } + }, + "@typescript-eslint/scope-manager": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.10.0.tgz", + "integrity": "sha512-WAPVw35P+fcnOa8DEic0tQUhoJJsgt+g6DEcz257G7vHFMwmag58EfowdVbiNcdfcV27EFR0tUBVXkDoIvfisQ==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.10.0", + "@typescript-eslint/visitor-keys": "4.10.0" + } + }, + "@typescript-eslint/types": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.10.0.tgz", + "integrity": "sha512-+dt5w1+Lqyd7wIPMa4XhJxUuE8+YF+vxQ6zxHyhLGHJjHiunPf0wSV8LtQwkpmAsRi1lEOoOIR30FG5S2HS33g==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.10.0.tgz", + "integrity": "sha512-mGK0YRp9TOk6ZqZ98F++bW6X5kMTzCRROJkGXH62d2azhghmq+1LNLylkGe6uGUOQzD452NOAEth5VAF6PDo5g==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.10.0", + "@typescript-eslint/visitor-keys": "4.10.0", + "debug": "^4.1.1", + "globby": "^11.0.1", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "globby": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.1.tgz", + "integrity": "sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.1.1", + "ignore": "^5.1.4", + "merge2": "^1.3.0", + "slash": "^3.0.0" + } + }, + "ignore": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", + "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", + "dev": true + }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, + "semver": { + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", + "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true + } + } + }, + "@typescript-eslint/visitor-keys": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.10.0.tgz", + "integrity": "sha512-hPyz5qmDMuZWFtHZkjcCpkAKHX8vdu1G3YsCLEd25ryZgnJfj6FQuJ5/O7R+dB1ueszilJmAFMtlU4CA6se3Jg==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.10.0", + "eslint-visitor-keys": "^2.0.0" + } + }, "abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -6012,11 +6120,14 @@ } } }, - "eslint-plugin-jasmine": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jasmine/-/eslint-plugin-jasmine-4.1.1.tgz", - "integrity": "sha512-uS7kvt7RPUB/gLDwhJ/Ax0APrmkj7In8VJWkiZLYHafz2Ix74mMRJx82YZZ3zHRa/YOuTL+ig6dW/aKwdNzUuw==", - "dev": true + "eslint-plugin-jest": { + "version": "24.1.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-24.1.3.tgz", + "integrity": "sha512-dNGGjzuEzCE3d5EPZQ/QGtmlMotqnYWD/QpCZ1UuZlrMAdhG5rldh0N0haCvhGnUkSeuORS5VNROwF9Hrgn3Lg==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "^4.0.1" + } }, "eslint-scope": { "version": "5.1.1", @@ -8791,32 +8902,6 @@ "istanbul-lib-report": "^3.0.0" } }, - "jasmine": { - "version": "3.6.3", - "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.6.3.tgz", - "integrity": "sha512-Th91zHsbsALWjDUIiU5d/W5zaYQsZFMPTdeNmi8GivZPmAaUAK8MblSG3yQI4VMGC/abF2us7ex60NH1AAIMTA==", - "dev": true, - "requires": { - "glob": "^7.1.6", - "jasmine-core": "~3.6.0" - }, - "dependencies": { - "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - } - } - }, "jasmine-ajax": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jasmine-ajax/-/jasmine-ajax-4.0.0.tgz", @@ -16833,6 +16918,21 @@ "integrity": "sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==", "dev": true }, + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, + "tsutils": { + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", + "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", diff --git a/assets/package.json b/assets/package.json index 1c36fdc9f..1bd1a222c 100644 --- a/assets/package.json +++ b/assets/package.json @@ -7,9 +7,7 @@ "test:one": "jest --coverage=false src/scripts/monitoring-location/components/hydrograph/index.test.js", "test:onedebug": "node --inspect-brk node_modules/.bin/jest --runInBand --coverage=false src/scripts/monitoring-location/components/hydrograph/index.test.js", "test": "jest scripts/.*\\.test.js$", - "test:chrome": "karma start --browsers Chrome", - "test:firefox": "karma start --browsers Firefox", - "test:watch": "jest --watch", + "test:watch": "jest --watch scripts/.*\\\\.test.js$\"", "clean": "rm -rf dist && mkdir dist", "build": "npm run clean && run-p build:* && npm run hash-assets", "build:css": "run-p build:css:*", @@ -84,11 +82,10 @@ "buble-jest": "^1.0.1", "concat": "^1.0.3", "eslint": "^7.15.0", - "eslint-plugin-jasmine": "^4.1.1", + "eslint-plugin-jest": "^24.1.3", "gulp": "^4.0.2", "gulp-rev-all": "^2.0.3", "isparta": "^4.1.1", - "jasmine": "^3.6.3", "jasmine-ajax": "^4.0.0", "jest": "^26.6.3", "jest-mock-console": "^1.0.1", diff --git a/assets/src/scripts/ajax.test.js b/assets/src/scripts/ajax.test.js index 1b1a0dd16..2d31f4008 100644 --- a/assets/src/scripts/ajax.test.js +++ b/assets/src/scripts/ajax.test.js @@ -21,42 +21,39 @@ describe('ajax module', () => { it('The url passed to the get command is used to make a request', () => { get(FAKE_SERVICE); - expect(fakeServer.requests.length).toBe(1); + expect(fakeServer.requests).toHaveLength(1); expect(fakeServer.requests[0].url).toBe(FAKE_SERVICE); expect(fakeServer.requests[0].method).toBe('GET'); }); - it('Successful request resolves the returned promise with the response', (done) => { + it('Successful request resolves the returned promise with the response', () => { fakeServer.respondWith(FAKE_SERVICE, [200, {}, 'Successful response']); let p = get(FAKE_SERVICE).then(resolveSpy, rejectSpy); fakeServer.respond(); - p.then(() => { + return p.then(() => { expect(resolveSpy).toHaveBeenCalledWith('Successful response'); expect(rejectSpy).not.toHaveBeenCalled(); - done(); }); }); - it('Failed request rejects the promise with the status code', (done) => { + it('Failed request rejects the promise with the status code', () => { fakeServer.respondWith(FAKE_SERVICE, [404, {}, 'Information not found']); let p = get(FAKE_SERVICE).then(resolveSpy, rejectSpy); fakeServer.respond(); - p.then(() => { + return p.then(() => { expect(resolveSpy).not.toHaveBeenCalled(); expect(rejectSpy).toHaveBeenCalled(); expect(rejectSpy.mock.calls[rejectSpy.mock.calls.length - 1][0].toString()).toContain('404'); - done(); }); }); - it('Network error rejects the promise', (done) => { + it('Network error rejects the promise', () => { let p = get(FAKE_SERVICE).then(resolveSpy, rejectSpy); fakeServer.requests[0].error(); - p.then(() => { + return p.then(() => { expect(resolveSpy).not.toHaveBeenCalled(); expect(rejectSpy).toHaveBeenCalled(); expect(rejectSpy.mock.calls[rejectSpy.mock.calls.length - 1][0].toString()).toContain('Network Error'); - done(); }); }); }); diff --git a/assets/src/scripts/d3-rendering/axes.test.js b/assets/src/scripts/d3-rendering/axes.test.js index c54833e31..e959139cb 100644 --- a/assets/src/scripts/d3-rendering/axes.test.js +++ b/assets/src/scripts/d3-rendering/axes.test.js @@ -44,7 +44,7 @@ describe('axes module', () => { }); // May need to think about how to mock yAxis better. - xdescribe('appendYAxis', () => { + describe.skip('appendYAxis', () => { let yAxis; beforeEach(() => { yAxis = jest.fn(); @@ -60,7 +60,7 @@ describe('axes module', () => { }); }); - xdescribe('appendSecondaryYAxis', () => { + describe.skip('appendSecondaryYAxis', () => { let yAxis; beforeEach(() => { yAxis = jest.fn(); diff --git a/assets/src/scripts/d3-rendering/tick-marks.test.js b/assets/src/scripts/d3-rendering/tick-marks.test.js index 73b7b6a06..5dafb2b39 100644 --- a/assets/src/scripts/d3-rendering/tick-marks.test.js +++ b/assets/src/scripts/d3-rendering/tick-marks.test.js @@ -10,7 +10,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({hours: 3}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Mar 08 02:08 PM', 'Mar 08 02:53 PM', 'Mar 08 03:38 PM', 'Mar 08 04:23 PM'] ); @@ -21,7 +21,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({hours: 5}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Mar 08 02:23 PM', 'Mar 08 03:38 PM', 'Mar 08 04:53 PM', 'Mar 08 06:08 PM'] ); @@ -32,7 +32,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 2}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Mar 08 07:45 PM', 'Mar 09 07:45 AM', 'Mar 09 07:45 PM', 'Mar 10 07:45 AM'] ); @@ -43,7 +43,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 7}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Mar 09', 'Mar 10', 'Mar 11', 'Mar 12', 'Mar 13', 'Mar 14', 'Mar 15'] ); @@ -54,7 +54,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 3}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(3); + expect(result.dates).toHaveLength(3); expect(result.dates.map(result.format)).toEqual( ['Mar 09', 'Mar 10', 'Mar 11'] ); @@ -65,7 +65,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 8}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Mar 09', 'Mar 11', 'Mar 13', 'Mar 15'] ); @@ -76,7 +76,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 14}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Mar 09', 'Mar 11', 'Mar 13', 'Mar 15', 'Mar 17', 'Mar 19', 'Mar 21'] ); @@ -87,7 +87,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 15}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Mar 09', 'Mar 13', 'Mar 17', 'Mar 21'] ); @@ -98,7 +98,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 28}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Mar 09', 'Mar 13', 'Mar 17', 'Mar 21', 'Mar 25', 'Mar 29', 'Apr 02'] ); @@ -109,7 +109,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 29}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Mar 11', 'Mar 18', 'Mar 25', 'Apr 01'] ); @@ -120,7 +120,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 50}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Mar 11', 'Mar 18', 'Mar 25', 'Apr 01', 'Apr 08', 'Apr 15', 'Apr 22'] ); @@ -131,7 +131,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 53}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Mar 15', 'Mar 29', 'Apr 12', 'Apr 26'] ); @@ -142,7 +142,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 98}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Mar 15', 'Mar 29', 'Apr 12', 'Apr 26', 'May 10', 'May 24', 'Jun 07'] ); @@ -153,7 +153,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({days: 126}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Apr 2018', 'May 2018', 'Jun 2018', 'Jul 2018'] ); @@ -164,7 +164,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 7, days: 1}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Apr 2018', 'May 2018', 'Jun 2018', 'Jul 2018', 'Aug 2018', 'Sep 2018', 'Oct 2018'] ); @@ -175,7 +175,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 8, days: 18}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['Apr 2018', 'Jun 2018', 'Aug 2018', 'Oct 2018'] ); @@ -186,7 +186,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 14, days: 18}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Apr 2018', 'Jun 2018', 'Aug 2018', 'Oct 2018', 'Dec 2018', 'Feb 2019', 'Apr 2019'] ); @@ -197,7 +197,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 15, days: 18}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(4); + expect(result.dates).toHaveLength(4); expect(result.dates.map(result.format)).toEqual( ['May 2018', 'Sep 2018', 'Jan 2019', 'May 2019'] ); @@ -208,7 +208,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 28, days: 18}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['May 2018', 'Sep 2018', 'Jan 2019', 'May 2019', 'Sep 2019', 'Jan 2020', 'May 2020'] ); @@ -219,7 +219,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 29, days: 18}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(5); + expect(result.dates).toHaveLength(5); expect(result.dates.map(result.format)).toEqual( ['Jun 2018', 'Dec 2018', 'Jun 2019', 'Dec 2019', 'Jun 2020'] ); @@ -230,7 +230,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 42, days: 18}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Jun 2018', 'Dec 2018', 'Jun 2019', 'Dec 2019', 'Jun 2020', 'Dec 2020', 'Jun 2021'] ); @@ -241,7 +241,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({month: 44, days: 18}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(3); + expect(result.dates).toHaveLength(3); expect(result.dates.map(result.format)).toEqual( ['Jan 2019', 'Jan 2020', 'Jan 2021'] ); @@ -253,7 +253,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({year: 7}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Jan 2019', 'Jan 2020', 'Jan 2021', 'Jan 2022', 'Jan 2023', 'Jan 2024', 'Jan 2025'] ); @@ -264,7 +264,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({year: 9}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Nov 2018', 'Mar 2020', 'Jun 2021', 'Oct 2022', 'Jan 2024', 'May 2025', 'Aug 2026'] ); @@ -275,7 +275,7 @@ describe('generateTimeTicks', () => { const endTime = DateTime.fromMillis(startTime).plus({year: 20}).toMillis(); const result = generateTimeTicks(startTime, endTime, timeZone); - expect(result.dates.length).toBe(7); + expect(result.dates).toHaveLength(7); expect(result.dates.map(result.format)).toEqual( ['Sep 2019', 'Jul 2022', 'May 2025', 'Apr 2028', 'Feb 2031', 'Dec 2033', 'Nov 2036'] ); diff --git a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/index.test.js b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/index.test.js index bb688874b..0a43cc428 100644 --- a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/index.test.js @@ -109,7 +109,7 @@ describe('monitoring-location/components/dailyValueHydrograph/index', () => { attachToNode(configureStore(), testDiv.node()); expect(testDiv.selectAll('.usa-alert--error').size()).toBe(1); - expect(fakeServer.requests.length).toBe(0); + expect(fakeServer.requests).toHaveLength(0); }); it('Expects that if siteno is defined, the available time series is fetched', () => { @@ -129,34 +129,38 @@ describe('monitoring-location/components/dailyValueHydrograph/index', () => { jest.spyOn(Actions, 'retrieveDVTimeSeries'); }); - it('Expects that once the available time series is fetched and contains a valid time series id, the time series is fetched', (done) => { + it('Expects that once the available time series is fetched and contains a valid time series id, the time series is fetched', () => { attachToNode(configureStore({ dailyValueTimeSeriesData: { availableDVTimeSeries: TEST_STATE.dailyValueTimeSeriesData.availableDVTimeSeries } }), testDiv.node(), {siteno: '12345'}); - window.requestAnimationFrame(() => { - expect(Actions.retrieveDVTimeSeries.mock.calls.length).toBe(2); - expect(Actions.retrieveDVTimeSeries.mock.calls[0]).toEqual(['USGS-12345', '1122']); - expect(Actions.retrieveDVTimeSeries.mock.calls[1]).toEqual(['USGS-12345', '1123']); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(Actions.retrieveDVTimeSeries.mock.calls).toHaveLength(2); + expect(Actions.retrieveDVTimeSeries.mock.calls[0]).toEqual(['USGS-12345', '1122']); + expect(Actions.retrieveDVTimeSeries.mock.calls[1]).toEqual(['USGS-12345', '1123']); - done(); + resolve(); + }); }); }); - it('Expects that if there is not a valid time series that the alert is shown indicating no data', (done) => { + it('Expects that if there is not a valid time series that the alert is shown indicating no data', () => { attachToNode(configureStore({ dailyValueTimeSeriesData: { availableDVTimeSeries: [] } }), testDiv.node(), {siteno: '12345'}); - window.requestAnimationFrame(() => { - expect(Actions.retrieveDVTimeSeries).not.toHaveBeenCalled(); - expect(testDiv.selectAll('.usa-alert--info').size()).toBe(1); - expect(testDiv.selectAll('.loading-indicator').size()).toBe(0); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(Actions.retrieveDVTimeSeries).not.toHaveBeenCalled(); + expect(testDiv.selectAll('.usa-alert--info').size()).toBe(1); + expect(testDiv.selectAll('.loading-indicator').size()).toBe(0); - done(); + resolve(); + }); }); }); }); @@ -174,63 +178,73 @@ describe('monitoring-location/components/dailyValueHydrograph/index', () => { store = configureStore(TEST_STATE); }); - it('Expect that a successful fetch of the dv series removes loading indicator and renders the expected elements', (done) => { + it('Expect that a successful fetch of the dv series removes loading indicator and renders the expected elements', () => { attachToNode(store, testDiv.node(), {siteno: '12345'}); - window.requestAnimationFrame(() => { + return new Promise(resolve => { window.requestAnimationFrame(() => { - expect(testDiv.selectAll('.loading-indicator').size()).toBe(0); - expect(testDiv.selectAll('.usa-alert--info').size()).toBe(0); + window.requestAnimationFrame(() => { + expect(testDiv.selectAll('.loading-indicator').size()).toBe(0); + expect(testDiv.selectAll('.usa-alert--info').size()).toBe(0); - done(); + resolve(); + }); }); }); }); - it('Expect that the hydrograph svg is rendered', (done) => { + it('Expect that the hydrograph svg is rendered', () => { attachToNode(store, testDiv.node(), {siteno: '12345'}); - window.requestAnimationFrame(() => { + return new Promise(resolve => { window.requestAnimationFrame(() => { - expect(testDiv.select('.graph-container').selectAll('.hydrograph-svg').size()).toBe(1); + window.requestAnimationFrame(() => { + expect(testDiv.select('.graph-container').selectAll('.hydrograph-svg').size()).toBe(1); - done(); + resolve(); + }); }); }); }); - it('Expect that the legend is rendered', (done) => { + it('Expect that the legend is rendered', () => { attachToNode(store, testDiv.node(), {siteno: '12345'}); - window.requestAnimationFrame(() => { + return new Promise(resolve => { window.requestAnimationFrame(() => { - expect(testDiv.select('.graph-container').selectAll('.dv-legend-container').size()).toBe(1); + window.requestAnimationFrame(() => { + expect(testDiv.select('.graph-container').selectAll('.dv-legend-container').size()).toBe(1); - done(); + resolve(); + }); }); }); }); - it('Expect that the brush is rendered', (done) => { + it('Expect that the brush is rendered', () => { attachToNode(store, testDiv.node(), {siteno: '12345'}); - window.requestAnimationFrame(() => { + return new Promise(resolve => { window.requestAnimationFrame(() => { - expect(testDiv.select('.graph-container').selectAll('.brush').size()).toBe(1); + window.requestAnimationFrame(() => { + expect(testDiv.select('.graph-container').selectAll('.brush').size()).toBe(1); - done(); + resolve(); + }); }); }); }); - it('Expect that the cursor slider is rendered', (done) => { + it('Expect that the cursor slider is rendered', () => { attachToNode(store, testDiv.node(), {siteno: '12345'}); - window.requestAnimationFrame(() => { + return new Promise(resolve => { window.requestAnimationFrame(() => { - expect(testDiv.select('.graph-container').selectAll('.cursor-slider-svg').size()).toBe(1); + window.requestAnimationFrame(() => { + expect(testDiv.select('.graph-container').selectAll('.cursor-slider-svg').size()).toBe(1); - done(); + resolve(); + }); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/legend-data.test.js b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/legend-data.test.js index 81bc8a1c3..7b0d811b5 100644 --- a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/legend-data.test.js +++ b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/legend-data.test.js @@ -66,8 +66,8 @@ describe('monitoring-location/components/daily-value-hydrograph/legend-data', () it('Should return markers for the selected variable', () => { const result = getLegendMarkers(TEST_STATE); - expect(result.length).toBe(2); - expect(result[0].length).toBe(4); + expect(result).toHaveLength(2); + expect(result[0]).toHaveLength(4); expect(result[0]).toContainEqual({ type: textOnlyMarker, domId: null, @@ -97,7 +97,7 @@ describe('monitoring-location/components/daily-value-hydrograph/legend-data', () }); - expect(result[1].length).toEqual(2); + expect(result[1]).toHaveLength(2); expect(result[1]).toContainEqual({ type: textOnlyMarker, domId: null, diff --git a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/time-series-data.test.js b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/time-series-data.test.js index 7aaa0b268..93c562376 100644 --- a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/time-series-data.test.js +++ b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/selectors/time-series-data.test.js @@ -147,8 +147,8 @@ describe('monitoring-location/components/daily-value-hydrograph/time-series-data label: 'Provisional', class: 'provisional' }); - expect(meanResult.length).toBe(0); - expect(maxResult.length).toBe(9); + expect(meanResult).toHaveLength(0); + expect(maxResult).toHaveLength(9); }); }); @@ -170,7 +170,7 @@ describe('monitoring-location/components/daily-value-hydrograph/time-series-data const meanResult = result.mean; const maxResult = result.max; - expect(minResult.length).toBe(5); + expect(minResult).toHaveLength(5); expect(minResult[0].isMasked).toBe(false); expect(minResult[0].label).toBe('Approved'); expect(minResult[0].class).toBe('approved'); @@ -210,8 +210,8 @@ describe('monitoring-location/components/daily-value-hydrograph/time-series-data expect(minResult[4].label).toBe('Provisional'); expect(minResult[4].class).toBe('provisional'); - expect(meanResult.length).toBe(0); - expect(maxResult.length).toBe(5); + expect(meanResult).toHaveLength(0); + expect(maxResult).toHaveLength(5); }); it('Should return a two line segments if time series has two day gap', () => { @@ -240,10 +240,10 @@ describe('monitoring-location/components/daily-value-hydrograph/time-series-data } } }); - expect(result.min.length).toBe(2); - expect(result.min.filter(segment => !segment.isMasked).length).toBe(2); - expect(result.min[0].points.length).toBe(1); - expect(result.min[1].points.length).toBe(3); + expect(result.min).toHaveLength(2); + expect(result.min.filter(segment => !segment.isMasked)).toHaveLength(2); + expect(result.min[0].points).toHaveLength(1); + expect(result.min[1].points).toHaveLength(3); }); }); @@ -285,7 +285,7 @@ describe('monitoring-location/components/daily-value-hydrograph/time-series-data } } }); - expect(result.min.length).toBe(2); + expect(result.min).toHaveLength(2); expect(result.min).toContainEqual({ isMasked: true, label: 'Ice affected', @@ -296,8 +296,8 @@ describe('monitoring-location/components/daily-value-hydrograph/time-series-data label: 'Approved', class: 'approved' }); - expect(result.mean.length).toBe(0); - expect(result.max.length).toBe(0); + expect(result.mean).toHaveLength(0); + expect(result.max).toHaveLength(0); }); }); diff --git a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/time-series-graph.test.js b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/time-series-graph.test.js index d3f090015..21d2ec47e 100644 --- a/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/time-series-graph.test.js +++ b/assets/src/scripts/monitoring-location/components/daily-value-hydrograph/time-series-graph.test.js @@ -91,7 +91,7 @@ describe('monitoring-location/components/dailyValueHydrograph/time-series-graph' expect(group.selectAll('.dv-mask-group').size()).toBe(1); }); - it('should render a circle if there is a one element line segment', (done) => { + it('should render a circle if there is a one element line segment', () => { store.dispatch(Actions.addDVTimeSeries('12345', { type: 'Feature', id: '12345', @@ -114,14 +114,16 @@ describe('monitoring-location/components/dailyValueHydrograph/time-series-graph' grades: [['50'], ['50'], ['50'], ['50'], ['50'], ['50']] } })); - window.requestAnimationFrame(() => { - const svg = testDiv.selectAll('svg'); - const group = svg.selectAll('#daily-values-lines-group'); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + const svg = testDiv.selectAll('svg'); + const group = svg.selectAll('#daily-values-lines-group'); - expect(group.selectAll('path').size()).toBe(2); - expect(group.selectAll('circle').size()).toBe(1); + expect(group.selectAll('path').size()).toBe(2); + expect(group.selectAll('circle').size()).toBe(1); - done(); + resolve(); + }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js index 33aad2183..0161e8746 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js @@ -20,7 +20,7 @@ describe('monitoring-location/components/hydrograph/download-links', () => { div.remove(); }); - it('creates an unordered list and the correct number of list items and hyperlinks when only current time series is showing', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks when only current time series is showing', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -54,22 +54,24 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(2); + expect(div.selectAll('a').size()).toBe(3); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks when compare is selected', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks when compare is selected', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -106,23 +108,25 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(3); - expect(div.selectAll('a').size()).toBe(4); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(3); + expect(div.selectAll('a').size()).toBe(4); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500&startDT=2019-11-14T23:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb¶meterCd=00060'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500&startDT=2019-11-14T23:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb¶meterCd=00060'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks when median is selected', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks when median is selected', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -156,23 +160,25 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(3); - expect(div.selectAll('a').size()).toBe(4); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(3); + expect(div.selectAll('a').size()).toBe(4); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?format=rdb&sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?format=rdb&sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks when both median and compare are selected', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks when both median and compare are selected', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -209,24 +215,26 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(4); - expect(div.selectAll('a').size()).toBe(5); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(4); + expect(div.selectAll('a').size()).toBe(5); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500&startDT=2019-11-14T23:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb¶meterCd=00060'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?format=rdb&sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[4].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00060'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500&startDT=2019-11-14T23:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb¶meterCd=00060'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?format=rdb&sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060'); + expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[4].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks if P30D is selected', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks if P30D is selected', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -263,24 +271,26 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(4); - expect(div.selectAll('a').size()).toBe(5); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(4); + expect(div.selectAll('a').size()).toBe(5); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500&startDT=2019-11-14T23:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb¶meterCd=00060'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500¶meterCd=00060&startDT=2019-10-22T22:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?format=rdb&sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[4].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500&startDT=2019-11-14T23:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb¶meterCd=00060'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500¶meterCd=00060&startDT=2019-10-22T22:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?format=rdb&sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060'); + expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[4].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks when custom days are selected', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks when custom days are selected', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -314,22 +324,24 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise (resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(2); + expect(div.selectAll('a').size()).toBe(3); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500¶meterCd=00060&startDT=2019-10-22T22:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500¶meterCd=00060&startDT=2019-10-22T22:18Z&endDT=2019-11-21T23:18Z&siteStatus=all&format=rdb'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks when custom calendar dates are selected', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks when custom calendar dates are selected', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -363,22 +375,24 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(2); + expect(div.selectAll('a').size()).toBe(3); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500¶meterCd=00060&startDT=2020-11-01T04:00Z&endDT=2020-11-04T04:59Z&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=01646500¶meterCd=00060&startDT=2020-11-01T04:00Z&endDT=2020-11-04T04:59Z&siteStatus=all&format=rdb'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks when a parameter other than 00060 is used', (done) => { + it('creates an unordered list and the correct number of list items and hyperlinks when a parameter other than 00060 is used', () => { const TEST_STATE = { 'ivTimeSeriesData': { 'queryInfo': { @@ -412,18 +426,20 @@ describe('monitoring-location/components/hydrograph/download-links', () => { let store = configureStore(TEST_STATE); const siteNumber = '05370000'; div.call(renderDownloadLinks, store, siteNumber); - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.selectAll('ul').size()).toBe(1); + expect(div.selectAll('li').size()).toBe(2); + expect(div.selectAll('a').size()).toBe(3); + const anchorSelection = div.selectAll('a'); + const anchorElements = anchorSelection.nodes(); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00010'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000&period=P7D&siteStatus=all&format=rdb¶meterCd=00010'); + expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); + expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - done(); + resolve(); + }); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js index 978fb8ead..afbec8e9d 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js @@ -174,13 +174,15 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { expect(checkbox.property('checked')).toBe(true); }); - it('Should render the compare toggle unchecked', (done) => { + it('Should render the compare toggle unchecked', () => { store.dispatch(Actions.setIVTimeSeriesVisibility('compare', false)); - window.requestAnimationFrame(() => { - const checkbox = select('#last-year-checkbox'); - expect(checkbox.size()).toBe(1); - expect(checkbox.property('checked')).toBe(false); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + const checkbox = select('#last-year-checkbox'); + expect(checkbox.size()).toBe(1); + expect(checkbox.property('checked')).toBe(false); + resolve(); + }); }); }); @@ -188,11 +190,13 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { expect(select('#last-year-checkbox').property('disabled')).toBeFalsy(); }); - it('should be disabled if there are no last year data', (done) => { + it('should be disabled if there are no last year data', () => { store.dispatch(Actions.setCurrentIVVariable('45807190')); - window.requestAnimationFrame(() => { - expect(select('#last-year-checkbox').property('disabled')).toBeTruthy(); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(select('#last-year-checkbox').property('disabled')).toBeTruthy(); + resolve(); + }); }); }); @@ -203,13 +207,15 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { expect(checkbox.property('checked')).toBe(true); }); - it('Should render the median toggle unchecked', (done) => { + it('Should render the median toggle unchecked', () => { store.dispatch(Actions.setIVTimeSeriesVisibility('median', false)); - window.requestAnimationFrame(() => { - const checkbox = select('#median-checkbox'); - expect(checkbox.size()).toBe(1); - expect(checkbox.property('checked')).toBe(false); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + const checkbox = select('#median-checkbox'); + expect(checkbox.size()).toBe(1); + expect(checkbox.property('checked')).toBe(false); + resolve(); + }); }); }); @@ -217,11 +223,13 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { expect(select('#median-checkbox').property('disabled')).toBeFalsy(); }); - it('should be disabled if there are no median statistics data', (done) => { + it('should be disabled if there are no median statistics data', () => { store.dispatch(Actions.setCurrentIVVariable('45807190')); - window.requestAnimationFrame(() => { - expect(select('#median-checkbox').property('disabled')).toBeTruthy(); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(select('#median-checkbox').property('disabled')).toBeTruthy(); + resolve(); + }); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js index 9e94f7501..8790b785f 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js @@ -303,33 +303,37 @@ describe('monitoring-location/components/hydrograph module', () => { }); }); - it('Expect to not retrieve additional time series if not indicated', (done) => { + it('Expect to not retrieve additional time series if not indicated', () => { attachToNode(store, graphNode, { siteno: '12345678', parameterCode: '00065' }); - window.requestAnimationFrame(() => { - expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); + resolve(); + }); }); }); - it('should retrieve extend time series if period set', (done) => { + it('should retrieve extend time series if period set', () => { attachToNode(store, graphNode, { siteno: '12345678', parameterCode: '00065', period: 'P30D' }); - window.requestAnimationFrame(() => { - expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).toHaveBeenCalledWith('12345678', 'P30D', '00065'); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).toHaveBeenCalledWith('12345678', 'P30D', '00065'); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); + resolve(); + }); }); }); - it('should not retrieve data for date range if time zone has not been fetched', (done) => { + it('should not retrieve data for date range if time zone has not been fetched', () => { attachToNode(store, graphNode, { siteno: '12345678', parameterCode: '00065', @@ -337,14 +341,16 @@ describe('monitoring-location/components/hydrograph module', () => { endDT: '2010-03-01' }); - window.requestAnimationFrame(() => { - expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); + resolve(); + }); }); }); - it('should retrieve data for date range if time zone has been fetched', (done) => { + it('should retrieve data for date range if time zone has been fetched', () => { jest.spyOn(timeZoneActions, 'retrieveIanaTimeZone').mockReturnValue(function() { return Promise.resolve({}); }); @@ -355,16 +361,18 @@ describe('monitoring-location/components/hydrograph module', () => { endDT: '2010-03-01' }); - window.requestAnimationFrame(() => { - expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not. toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not. toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); + resolve(); + }); }); }); }); }); - describe('Tests for initial data fetching when showOnlyGraph is true ', () => { + describe('Tests for initial data fetching when showOnlyGraph is true', () => { let store; beforeEach(() => { @@ -385,7 +393,7 @@ describe('monitoring-location/components/hydrograph module', () => { }); }); - it('should retrieve custom time period if period is specified', (done) => { + it('should retrieve custom time period if period is specified', () => { attachToNode(store, graphNode, { siteno: '12345678', parameterCode: '00065', @@ -393,17 +401,18 @@ describe('monitoring-location/components/hydrograph module', () => { showOnlyGraph: true }); - window.requestAnimationFrame(() => { - - expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).toHaveBeenCalledWith('12345678', '00065', 'P20D'); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).toHaveBeenCalledWith('12345678', '00065', 'P20D'); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); - done(); + resolve(); + }); }); }); - it('should not retrieve date range for date range parameters if time zone has not been fetched', (done) => { + it('should not retrieve date range for date range parameters if time zone has not been fetched', () => { attachToNode(store, graphNode, { siteno: '12345678', parameterCode: '00065', @@ -412,15 +421,17 @@ describe('monitoring-location/components/hydrograph module', () => { showOnlyGraph: true }); - window.requestAnimationFrame(() => { - expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); + resolve(); + }); }); }); - it('should retrieve date range for date range parameters if time zone has been fetched', (done) => { + it('should retrieve date range for date range parameters if time zone has been fetched', () => { jest.spyOn(timeZoneActions, 'retrieveIanaTimeZone').mockReturnValue(function() { return Promise.resolve({}); }); @@ -432,26 +443,30 @@ describe('monitoring-location/components/hydrograph module', () => { showOnlyGraph: true }); - window.requestAnimationFrame(() => { - expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); + resolve(); + }); }); }); - it('should retrieve time series if no custom period or date range', (done) => { + it('should retrieve time series if no custom period or date range', () => { attachToNode(store, graphNode, { siteno: '12345678', parameterCode: '00065', showOnlyGraph: true }); - window.requestAnimationFrame(() => { - expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).toHaveBeenCalledWith('12345678', ['00065']); - expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); - expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).toHaveBeenCalledWith('12345678', ['00065']); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); + resolve(); + }); }); }); }); @@ -459,7 +474,7 @@ describe('monitoring-location/components/hydrograph module', () => { describe('graphNode contains the expected elements when no IV time series has been retrieved and showOnlyGraph is false', () => { let store; config.NWIS_INVENTORY_ENDPOINT = 'https://fakenwis.usgs.gov/inventory'; - beforeEach((done) => { + beforeEach(() => { jest.spyOn(floodDataActions, 'retrieveWaterwatchData').mockReturnValue(function() { return Promise.resolve({}); }); @@ -481,8 +496,10 @@ describe('monitoring-location/components/hydrograph module', () => { } }); attachToNode(store, graphNode, {siteno: '12345678'}); - window.requestAnimationFrame(() => { - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + resolve(); + }); }); }); @@ -498,7 +515,7 @@ describe('monitoring-location/components/hydrograph module', () => { describe('graphNode contains the expected elements when showOnlyGraph is false', () => { /* eslint no-use-before-define: 0 */ let store; - beforeEach((done) => { + beforeEach(() => { jest.spyOn(floodDataActions, 'retrieveWaterwatchData').mockReturnValue(function() { return Promise.resolve({}); }); @@ -551,8 +568,10 @@ describe('monitoring-location/components/hydrograph module', () => { }); attachToNode(store, graphNode, {siteno: '12345678'}); - window.requestAnimationFrame(() => { - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + resolve(); + }); }); }); @@ -564,12 +583,14 @@ describe('monitoring-location/components/hydrograph module', () => { expect(select('#classic-page-link').attr('href')).not.toContain('https://fakenwis.usgs.gov/inventory'); }); - it('should render the correct number of svg nodes', (done) => { - window.requestAnimationFrame(() => { + it('should render the correct number of svg nodes', () => { + return new Promise(resolve => { window.requestAnimationFrame(() => { - // one main hydrograph, brush, slider, legend and two sparklines - expect(selectAll('svg').size()).toBe(6); - done(); + window.requestAnimationFrame(() => { + // one main hydrograph, brush, slider, legend and two sparklines + expect(selectAll('svg').size()).toBe(6); + resolve(); + }); }); }); }); @@ -628,12 +649,14 @@ describe('monitoring-location/components/hydrograph module', () => { expect(selectAll('table .usa-tooltip').size()).toBe(4); }); - it('should render the data table', (done) => { - window.requestAnimationFrame(() => { - const container = select('#iv-data-table-container'); - expect(container.selectAll('table').size()).toBe(1); - expect(container.select('.pagination').size()).toBe(1); - done(); + it('should render the data table', () => { + return new Promise(resolve => { + window.requestAnimationFrame(() => { + const container = select('#iv-data-table-container'); + expect(container.selectAll('table').size()).toBe(1); + expect(container.select('.pagination').size()).toBe(1); + resolve(); + }); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js index 941a2a559..9bc61646a 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js @@ -143,11 +143,13 @@ describe('monitoring-location/components/hydrograph/legend module', () => { expect(selectAll('.legend g line.median-step').size()).toBe(1); }); - it('Should have 4 legend marker after the median time series are removed', (done) => { + it('Should have 4 legend marker after the median time series are removed', () => { store.dispatch(Actions.setIVTimeSeriesVisibility('median', false)); - window.requestAnimationFrame(() => { - expect(selectAll('.legend g').size()).toBe(4); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(selectAll('.legend g').size()).toBe(4); + resolve(); + }); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js index da13835c4..38affacb8 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js @@ -67,14 +67,16 @@ describe('monitoring-location/components/hydrograph/method-picker', () => { div.remove(); }); - it('Creates a picker and sets the currentMethodID', (done) => { + it('Creates a picker and sets the currentMethodID', () => { let store = configureStore(TEST_STATE); div.call(drawMethodPicker, store); - window.requestAnimationFrame(() => { - expect(div.select('div').property('hidden')).toEqual(false); - expect(div.select('select').property('value')).toEqual('69930'); - expect(store.getState().ivTimeSeriesState.currentIVMethodID).toEqual(69930); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.select('div').property('hidden')).toEqual(false); + expect(div.select('select').property('value')).toEqual('69930'); + expect(store.getState().ivTimeSeriesState.currentIVMethodID).toEqual(69930); + resolve(); + }); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.test.js index 77452fc6d..b71662210 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.test.js @@ -207,7 +207,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { const result = getAllPoints(TEST_DATA); it('Return three time series', () => { - expect(Object.keys(result).length).toBe(3); + expect(Object.keys(result)).toHaveLength(3); expect(result['69928:00060']).toBeDefined(); expect(result['69929:00010']).toBeDefined(); expect(result['69930:00045']).toBeDefined(); @@ -272,7 +272,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { it('Return the points array for the ts Key selector', () => { const result = getPointsByTsKey('current')(TEST_DATA); - expect(Object.keys(result).length).toBe(2); + expect(Object.keys(result)).toHaveLength(2); expect(result['69928:00060']).toBeDefined(); expect(result['69930:00045']).toBeDefined(); }); @@ -299,7 +299,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { it('Return the current variable for the tsKey', () => { const result = getCurrentVariablePoints('current')(TEST_DATA); - expect(result.length).toBe(1); + expect(result).toHaveLength(1); expect(result[0]).toEqual(TEST_DATA.ivTimeSeriesData.timeSeries['69928:00060'].points); }); @@ -323,7 +323,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { it('Returns the expected data', () => { const result = getCurrentPointData(TEST_DATA); - expect(result.length).toBe(3); + expect(result).toHaveLength(3); expect(result[0]).toEqual({ parameterName: 'Streamflow', dateTime: '2018-03-06T09:45-06:00', @@ -806,7 +806,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { it('Should return two mappings for current time series', () => { const result = getLineSegmentsByParmCd('current')(TEST_DATA); - expect(Object.keys(result).length).toBe(2); + expect(Object.keys(result)).toHaveLength(2); expect(result['00060']).toBeDefined(); expect(result['00045']).toBeDefined(); }); @@ -816,7 +816,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { it('Should return a single time series for current', () => { const result = getCurrentVariableLineSegments('current')(TEST_DATA); - expect(Object.keys(result).length).toBe(1); + expect(Object.keys(result)).toHaveLength(1); expect(result['69928:00060']).toBeDefined(); }); @@ -856,7 +856,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { }; it('Return two arrays', () => { - expect(getVisiblePoints(testData).length).toBe(2); + expect(getVisiblePoints(testData)).toHaveLength(2); }); it('Expects one array if only median is not visible', () => { @@ -872,7 +872,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { } }; - expect(getVisiblePoints(newTestData).length).toBe(1); + expect(getVisiblePoints(newTestData)).toHaveLength(1); }); it('Expects an empty array if no visible series has the current variable', () => { @@ -884,7 +884,7 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { } }; - expect(getVisiblePoints(newTestData).length).toBe(0); + expect(getVisiblePoints(newTestData)).toHaveLength(0); }); }); @@ -982,8 +982,8 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { it('Return the expected data points', () => { let result = getCurrentVariableMedianStatPoints(TEST_STATE); - expect(result.length).toBe(1); - expect(result[0].length).toBe(9); + expect(result).toHaveLength(1); + expect(result[0]).toHaveLength(9); expect(result[0][0]).toEqual({ value: 42, date: DateTime.fromObject({ diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js index a5fab7b7d..142d5444d 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js @@ -119,13 +119,13 @@ describe('monitoring-location/components/hydrograph/selectors/legend-data', () = it('Should return markers for the selected variable', () => { const result = getLegendMarkerRows(TEST_DATA); - expect(result.length).toBe(2); - expect(result[0].length).toBe(4); + expect(result).toHaveLength(2); + expect(result[0]).toHaveLength(4); expect(result[0][0].type).toEqual(textOnlyMarker); expect(result[0][1].type).toEqual(lineMarker); expect(result[0][2].type).toEqual(rectangleMarker); expect(result[0][3].type).toEqual(rectangleMarker); - expect(result[1].length).toBe(2); + expect(result[1]).toHaveLength(2); expect(result[1][0].type).toEqual(textOnlyMarker); expect(result[1][1].type).toEqual(lineMarker); }); @@ -140,8 +140,8 @@ describe('monitoring-location/components/hydrograph/selectors/legend-data', () = }; const result = getLegendMarkerRows(newData); - expect(result.length).toBe(5); - expect(result[0].length).toBe(3); + expect(result).toHaveLength(5); + expect(result[0]).toHaveLength(3); expect(result[0][0].type).toEqual(textOnlyMarker); expect(result[0][1].type).toEqual(lineMarker); expect(result[0][2].type).toEqual(lineMarker); @@ -162,8 +162,8 @@ describe('monitoring-location/components/hydrograph/selectors/legend-data', () = const result = getLegendMarkerRows(newData); - expect(result.length).toBe(1); - expect(result[0].length).toBe(4); + expect(result).toHaveLength(1); + expect(result[0]).toHaveLength(4); expect(result[0][0].type).toEqual(textOnlyMarker); expect(result[0][1].type).toEqual(lineMarker); expect(result[0][2].type).toEqual(rectangleMarker); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js index f6d73ac7f..ffa7d811e 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js @@ -272,11 +272,13 @@ describe('monitoring-location/components/hydrograph/time-series-graph', () => { expect(selectAll('#ts-compare-group .line-segment').size()).toBe(1); }); - it('Should remove the lines when removing the compare time series', (done) => { + it('Should remove the lines when removing the compare time series', () => { store.dispatch(Actions.setIVTimeSeriesVisibility('compare', false)); - window.requestAnimationFrame(() => { - expect(selectAll('#ts-compare-group .line-segment').size()).toBe(0); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(selectAll('#ts-compare-group .line-segment').size()).toBe(0); + resolve(); + }); }); }); }); @@ -291,11 +293,13 @@ describe('monitoring-location/components/hydrograph/time-series-graph', () => { expect(selectAll('#median-points .median-data-series').size()).toBe(1); }); - it('Should remove the lines when removing the median statistics data', (done) => { + it('Should remove the lines when removing the median statistics data', () => { store.dispatch(Actions.setIVTimeSeriesVisibility('median', false)); - window.requestAnimationFrame(() => { - expect(selectAll('#median-points .median-data-series').size()).toBe(0); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(selectAll('#median-points .median-data-series').size()).toBe(0); + resolve(); + }); }); }); }); @@ -316,10 +320,12 @@ describe('monitoring-location/components/hydrograph/time-series-graph', () => { }); - it('Should remove the lines when removing the waterwatch flood levels data', (done) => { - window.requestAnimationFrame(() => { - expect(selectAll('#flood-level-points').size()).toBe(0); - done(); + it('Should remove the lines when removing the waterwatch flood levels data', () => { + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(selectAll('#flood-level-points').size()).toBe(0); + resolve(); + }); }); }); }); @@ -353,7 +359,7 @@ describe('monitoring-location/components/hydrograph/time-series-graph', () => { expect(div.selectAll('.focus-line').size()).toBe(0); }); - it('Should not render the tooltip if showTooltip is false', () => { + it('Should not render the tooltip if showTooltip is true', () => { div.call(drawTimeSeriesGraph, store, '12345678', false, true); expect(div.selectAll('.tooltip-text-group').size()).toBe(1); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.test.js index 20fc91242..585d87a69 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.test.js @@ -231,7 +231,7 @@ describe('monitoring-location/components/hydrograph/tooltip module', () => { expect(value).toBe('14 deg C (57.2 deg F)'); }); - it('Text contents are updated when the store is provided with new focus times', (done) => { + it('Text contents are updated when the store is provided with new focus times', () => { let store = configureStore(Object.assign({}, testState, { ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { ivGraphCursorOffset: 1 @@ -244,17 +244,19 @@ describe('monitoring-location/components/hydrograph/tooltip module', () => { expect(value).toBe('12 ft3/s'); store.dispatch(Actions.setIVGraphCursorOffset(3 * 60 * 60 * 1000)); - window.requestAnimationFrame(() => { - value = div.select('.current-tooltip-text').text().split(' - ')[0]; - expect(value).toBe('15 ft3/s'); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + value = div.select('.current-tooltip-text').text().split(' - ')[0]; + expect(value).toBe('15 ft3/s'); - value = div.select('.compare-tooltip-text').text().split(' - ')[0]; - expect(value).toBe('15 ft3/s'); - done(); + value = div.select('.compare-tooltip-text').text().split(' - ')[0]; + expect(value).toBe('15 ft3/s'); + resolve(); + }); }); }); - it('Shows the qualifier text if focus is near masked data points', (done) => { + it('Shows the qualifier text if focus is near masked data points', () => { let store = configureStore(Object.assign({}, testState, { ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { ivGraphCursorOffset: 1 @@ -264,13 +266,15 @@ describe('monitoring-location/components/hydrograph/tooltip module', () => { div.call(drawTooltipText, store); store.dispatch(Actions.setIVGraphCursorOffset(299 * 60 * 1000)); // 2018-01-03T16:59:00.000Z - window.requestAnimationFrame(() => { - expect(div.select('.current-tooltip-text').text()).toContain('Flood'); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(div.select('.current-tooltip-text').text()).toContain('Flood'); + resolve(); + }); }); }); - it('Creates the correct text for values of zero', (done) => { + it('Creates the correct text for values of zero', () => { const zeroData = [12, 13, 14, 15, 16].map(hour => { return { dateTime: new Date(`2018-01-03T${hour}:00:00.000Z`).getTime(), @@ -292,11 +296,13 @@ describe('monitoring-location/components/hydrograph/tooltip module', () => { })); div.call(drawTooltipText, store); store.dispatch(Actions.setIVGraphCursorOffset(119 * 60 * 1000)); - window.requestAnimationFrame(() => { - let value = div.select('.current-tooltip-text').text().split(' - ')[0]; + return new Promise(resolve => { + window.requestAnimationFrame(() => { + let value = div.select('.current-tooltip-text').text().split(' - ')[0]; - expect(value).toBe('0 ft3/s'); - done(); + expect(value).toBe('0 ft3/s'); + resolve(); + }); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/map/flood-slider.test.js b/assets/src/scripts/monitoring-location/components/map/flood-slider.test.js index e1e67c870..83f1db038 100644 --- a/assets/src/scripts/monitoring-location/components/map/flood-slider.test.js +++ b/assets/src/scripts/monitoring-location/components/map/flood-slider.test.js @@ -80,16 +80,17 @@ describe('monitoring-location/components/map/flood-slider', () => { .call(floodSlider, store); }); - it('Sets the gageHeight when the slider value changes and updates the label', (done) => { + it('Sets the gageHeight when the slider value changes and updates the label', () => { const slider = select(sliderNode).select('input[type="range"]'); slider.attr('value', 2) .dispatch('input'); - window.requestAnimationFrame(() => { - expect(store.getState().floodState.gageHeight).toBe(11); - expect(select(sliderNode).select('label').html()).toContain('11'); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(store.getState().floodState.gageHeight).toBe(11); + expect(select(sliderNode).select('label').html()).toContain('11'); + resolve(); + }); }); - }); }); }); diff --git a/assets/src/scripts/monitoring-location/selectors/daily-value-time-series-selector.test.js b/assets/src/scripts/monitoring-location/selectors/daily-value-time-series-selector.test.js index e3a859a4b..73f5da1f0 100644 --- a/assets/src/scripts/monitoring-location/selectors/daily-value-time-series-selector.test.js +++ b/assets/src/scripts/monitoring-location/selectors/daily-value-time-series-selector.test.js @@ -259,7 +259,7 @@ describe('monitoring-location/selectors/daily-value-time-series-selector', () => const meanResult = result.mean; const maxResult = result.max; - expect(minResult.length).toBe(9); + expect(minResult).toHaveLength(9); expect(minResult[0]).toEqual({ value: '5.0', dateTime: 1514851200000, @@ -285,9 +285,9 @@ describe('monitoring-location/selectors/daily-value-time-series-selector', () => grades: ['50'] }); - expect(meanResult.length).toBe(0); + expect(meanResult).toHaveLength(0); - expect(maxResult.length).toBe(9); + expect(maxResult).toHaveLength(9); expect(maxResult[0]).toEqual({ value: '5.2', dateTime: 1514851200000, diff --git a/assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js b/assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js index 9006aeec2..ce1d04518 100644 --- a/assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js +++ b/assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js @@ -460,7 +460,7 @@ describe('monitoring-location/selectors/time-series-selector', () => { } } }; - it('Returns empty string if state has no siteCodes ', () => { + it('Returns empty string if state has no siteCodes', () => { expect(getAgencyCode('12345678')({ ivTimeSeriesData: {} })).toBe(''); @@ -1068,7 +1068,7 @@ describe('monitoring-location/selectors/time-series-selector', () => { } }; const result = getAllMethodsForCurrentVariable(newTestData); - expect(result.length).toEqual(2); + expect(result).toHaveLength(2); expect(result).toContainEqual({ methodDescription: '4.1 ft from riverbed (middle)', methodID: 69930 diff --git a/assets/src/scripts/monitoring-location/store/daily-value-time-series.test.js b/assets/src/scripts/monitoring-location/store/daily-value-time-series.test.js index 5f6ca90b3..6a2d769fe 100644 --- a/assets/src/scripts/monitoring-location/store/daily-value-time-series.test.js +++ b/assets/src/scripts/monitoring-location/store/daily-value-time-series.test.js @@ -56,13 +56,13 @@ describe('monitoring-location/store/daily-value-time-series module', () => { }); describe('Actions.retrieveAvailableDVTimeSeries', () => { - it('Expects a successful fetch request to update the store', (done) => { + it('Expects a successful fetch request to update the store', () => { const promise = store.dispatch(Actions.retrieveAvailableDVTimeSeries('USGS-12345678')); expect(fakeServer.requests[0].url).toContain('USGS-12345678'); fakeServer.requests[0].respond(200, {}, MOCK_AVAILABLE_TIME_SERIES); - promise.then(() => { + return promise.then(() => { const state = store.getState(); expect(state.dailyValueTimeSeriesData.availableDVTimeSeries).toBeDefined(); expect(state.dailyValueTimeSeriesData.availableDVTimeSeries).toEqual([ @@ -74,37 +74,32 @@ describe('monitoring-location/store/daily-value-time-series module', () => { 'id': 'AGENCY-FEATURE-TIMESERIES' } ]); - done(); }); }); - it('Expects a successful fetch request with no time series sets the store to show empty array', (done) => { + it('Expects a successful fetch request with no time series sets the store to show empty array', () => { const promise = store.dispatch(Actions.retrieveAvailableDVTimeSeries('USGS-12345678')); fakeServer.requests[0].respond(200, {}, MOCK_EMPTY_AVAILABLE_TIME_SERIES); - promise.then(() => { + return promise.then(() => { expect(store.getState().dailyValueTimeSeriesData.availableDVTimeSeries).toEqual([]); - - done(); }); }); - it('Expects a bad fetch request to not update the store', (done) => { + it('Expects a bad fetch request to not update the store', () => { const promise = store.dispatch(Actions.retrieveAvailableDVTimeSeries('USGS-12345678')); fakeServer.requests[0].respond(500, {}, 'Bad Data'); - promise.then(() => { + return promise.then(() => { const state = store.getState(); expect(state.dailyValueTimeSeriesData.availableDVTimeSeries).toEqual([]); - - done(); }); }); }); describe('Actions.retrieveDVTimeSeries', () => { - it('Expects a successful fetch request to update the store', (done) => { + it('Expects a successful fetch request to update the store', () => { const promise = store.dispatch(Actions.retrieveDVTimeSeries('USGS-12345678', 'ffff345')); const url = fakeServer.requests[0].url; expect(url).toContain('USGS-12345678'); @@ -112,13 +107,11 @@ describe('monitoring-location/store/daily-value-time-series module', () => { fakeServer.requests[0].respond(200, {}, MOCK_DV_TIME_SERIES); - promise.then(() => { + return promise.then(() => { const state = store.getState(); expect(state.dailyValueTimeSeriesData.dvTimeSeries).toBeDefined(); expect(state.dailyValueTimeSeriesData.dvTimeSeries.ffff345).toBeDefined(); expect(state.dailyValueTimeSeriesData.dvTimeSeries.ffff345.id).toEqual('USGS-12345678-ffff345'); - - done(); }); }); @@ -126,24 +119,22 @@ describe('monitoring-location/store/daily-value-time-series module', () => { store.dispatch(Actions.addDVTimeSeries('ffff345', {id: 'ffff345'})); store.dispatch(Actions.retrieveDVTimeSeries('USGS-12345678', 'ffff345')); - expect(fakeServer.requests.length).toBe(0); + expect(fakeServer.requests).toHaveLength(0); }); - it('Expects a bad fetch request to not add a time series the store', (done) => { + it('Expects a bad fetch request to not add a time series the store', () => { const initPromise = store.dispatch(Actions.retrieveDVTimeSeries('USGS-12345678', 'ffff345')); fakeServer.requests[0].respond(200, {}, MOCK_DV_TIME_SERIES); - initPromise.then(() => { + return initPromise.then(() => { const promise = store.dispatch(Actions.retrieveDVTimeSeries('USGS-12345678', 'aaaa345')); fakeServer.requests[1].respond(500, {}, 'Bad Data'); - promise.then(() => { + return promise.then(() => { const state = store.getState(); expect(state.dailyValueTimeSeriesData.dvTimeSeries.ffff345).toBeDefined(); expect(state.dailyValueTimeSeriesData.dvTimeSeries.aaaa345).toBeDefined(); expect(state.dailyValueTimeSeriesData.dvTimeSeries.aaaa345).toEqual({}); - - done(); }); }); }); diff --git a/assets/src/scripts/monitoring-location/store/flood-inundation.test.js b/assets/src/scripts/monitoring-location/store/flood-inundation.test.js index 9daaaa9b5..11174288b 100644 --- a/assets/src/scripts/monitoring-location/store/flood-inundation.test.js +++ b/assets/src/scripts/monitoring-location/store/flood-inundation.test.js @@ -71,7 +71,7 @@ describe('monitoring-location/store/flood-inundation module', () => { it('Expects call to determine FIM Public Status to occur', () => { store.dispatch(Actions.retrieveFloodData('12345678')); - expect(fakeServer.requests.length).toBe(3); + expect(fakeServer.requests).toHaveLength(3); const req1 = fakeServer.requests[0]; const req2 = fakeServer.requests[1]; const req3 = fakeServer.requests[2]; @@ -85,33 +85,31 @@ describe('monitoring-location/store/flood-inundation module', () => { expect(req3.url).toContain('returnExtentOnly=true'); }); - it('Expects a public site with successful ajax calls to populate the store', (done) => { + it('Expects a public site with successful ajax calls to populate the store', () => { let promise = store.dispatch(Actions.retrieveFloodData('1234567')); fakeServer.requests[0].respond(200, {}, PUBLIC_SITE); fakeServer.requests[1].respond(200, {}, MOCK_STAGES); fakeServer.requests[2].respond(200, {}, MOCK_EXTENT); - promise.then(() => { + return promise.then(() => { const floodData = store.getState().floodData; expect(floodData.stages).toEqual([28, 29, 30]); expect(floodData.extent).toEqual(JSON.parse(MOCK_EXTENT).extent); - done(); }); }); - it('Expects a not public site with successful ajax calls to populate the store', (done) => { + it('Expects a not public site with successful ajax calls to populate the store', () => { let promise = store.dispatch(Actions.retrieveFloodData('1234567')); fakeServer.requests[0].respond(200, {}, NOT_PUBLIC_SITE); fakeServer.requests[1].respond(200, {}, MOCK_STAGES); fakeServer.requests[2].respond(200, {}, MOCK_EXTENT); - promise.then(() => { + return promise.then(() => { const floodData = store.getState().floodData; expect(floodData.stages).toEqual([]); expect(floodData.extent).toEqual({}); - done(); }); }); }); @@ -120,16 +118,16 @@ describe('monitoring-location/store/flood-inundation module', () => { it('Expects that fetching urls have the siteno', () => { store.dispatch(Actions.retrieveWaterwatchData('12345678')); - expect(fakeServer.requests.length).toBe(1); + expect(fakeServer.requests).toHaveLength(1); expect(fakeServer.requests[0].url).toContain('12345678'); }); - it('Expects the store to be updated on successful fetches', (done) => { + it('Expects the store to be updated on successful fetches', () => { const promise = store.dispatch(Actions.retrieveWaterwatchData('12345678')); fakeServer.requests[0].respond(200, {}, MOCK_WATERWATCH_FLOOD_LEVELS); - promise.then(() => { + return promise.then(() => { const waterwatchData = store.getState().floodData; expect(waterwatchData.floodLevels.action_stage) .toEqual(JSON.parse(MOCK_WATERWATCH_FLOOD_LEVELS).sites[0].action_stage); @@ -139,21 +137,19 @@ describe('monitoring-location/store/flood-inundation module', () => { .toEqual(JSON.parse(MOCK_WATERWATCH_FLOOD_LEVELS).sites[0].moderate_flood_stage); expect(waterwatchData.floodLevels.major_flood_stage) .toEqual(JSON.parse(MOCK_WATERWATCH_FLOOD_LEVELS).sites[0].major_flood_stage); - done(); }); }); - it('Expects the store to not contain empty features if calls are unsuccessful', (done) => { + it('Expects the store to not contain empty features if calls are unsuccessful', () => { const promise = store.dispatch(Actions.retrieveWaterwatchData('12345678')); fakeServer.requests[0].respond(500, {}, 'Internal server error'); - promise.then(() => { + return promise.then(() => { const waterwatchData = store.getState().floodData; expect(waterwatchData.floodLevels).toEqual(null); - done(); }); }); }); diff --git a/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-data.spec.js b/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-data.test.js similarity index 83% rename from assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-data.spec.js rename to assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-data.test.js index a6dc4660d..6b372fb0d 100644 --- a/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-data.spec.js +++ b/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-data.test.js @@ -1,5 +1,7 @@ +import mockConsole from 'jest-mock-console'; import {applyMiddleware, combineReducers, createStore} from 'redux'; import {default as thunk} from 'redux-thunk'; +import sinon from 'sinon'; import {MOCK_IV_DATA} from 'ui/mock-service-data'; @@ -9,8 +11,11 @@ import {Actions as ivTimeSeriesStateActions, ivTimeSeriesStateReducer} from './i describe('monitoring-location/store/instantaneous-value-time-series-data module', () => { let store; + let fakeServer; + let restoreConsole; describe('ivTimeSeriesDataReducer module', () => { beforeEach(() => { + restoreConsole = mockConsole(); store = createStore( combineReducers({ floodState: floodStateReducer, @@ -39,11 +44,12 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' }, applyMiddleware(thunk) ); - jasmine.Ajax.install(); + fakeServer = sinon.createFakeServer(); }); afterEach(() => { - jasmine.Ajax.uninstall(); + restoreConsole(); + fakeServer.restore(); }); describe('Actions.addIVTimeSeriesCollection', () => { @@ -196,7 +202,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' it('Service url should contain the siteno and period=P7D', () => { store.dispatch(Actions.retrieveIVTimeSeries('12345678')); - const url = jasmine.Ajax.requests.mostRecent().url; + const url = fakeServer.requests[0].url; expect(url).toContain('sites=12345678'); expect(url).toContain('period=P7D'); }); @@ -207,13 +213,11 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' expect(store.getState().ivTimeSeriesState.loadingIVTSKeys).toContain('current:P7D'); }); - it('Expect that a successful fetch updates the data and sets the state appropriately', (done) => { + it('Expect that a successful fetch updates the data and sets the state appropriately', () => { const promise = store.dispatch(Actions.retrieveIVTimeSeries('12345678')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - responseText: MOCK_IV_DATA - }); - promise.then(() => { + fakeServer.requests[0].respond(200, {}, MOCK_IV_DATA); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.retrieveCompareIVTimeSeries).toHaveBeenCalled(); expect(Actions.addIVTimeSeriesCollection).toHaveBeenCalled(); @@ -221,21 +225,17 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' expect(tsState.loadingIVTSKeys).not.toContain('current:P7D'); expect(tsState.showIVTimeSeries.current).toBe(true); expect(tsState.currentIVVariableID).toBe('45807197'); - done(); }); }); - it('Expect that a failed fetch resets the time series and removes the loading key', (done) => { + it('Expect that a failed fetch resets the time series and removes the loading key', () => { const promise = store.dispatch(Actions.retrieveIVTimeSeries('12345678')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 500, - responseText: 'Internal server error' - }); - promise.then(() => { + fakeServer.requests[0].respond(500, {}, 'Internal server error'); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.resetIVTimeSeries).toHaveBeenCalled(); expect(tsState.loadingIVTSKeys).not.toContain('current:P7D'); - done(); }); }); }); @@ -251,7 +251,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' it('Service url should contain the siteno, startDT, and endDT', () => { store.dispatch(Actions.retrieveCompareIVTimeSeries('12345678', 'P7D', startDT, endDT)); - const url = jasmine.Ajax.requests.mostRecent().url; + const url = fakeServer.requests[0].url; expect(url).toContain('sites=12345678'); expect(url).toContain('startDT='); expect(url).toContain('endDT='); @@ -263,31 +263,25 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' expect(store.getState().ivTimeSeriesState.loadingIVTSKeys).toContain('compare:P7D'); }); - it('Expect that a successful fetch updates the data and sets the state appropriately', (done) => { + it('Expect that a successful fetch updates the data and sets the state appropriately', () => { const promise = store.dispatch(Actions.retrieveCompareIVTimeSeries('12345678', 'P7D', startDT, endDT)); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - responseText: MOCK_IV_DATA - }); - promise.then(() => { + fakeServer.requests[0].respond(200, {}, MOCK_IV_DATA); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.addIVTimeSeriesCollection).toHaveBeenCalled(); expect(tsState.loadingIVTSKeys).not.toContain('compare:P7D'); - done(); }); }); - it('Expect that a failed fetch resets the time series and removes the loading key', (done) => { + it('Expect that a failed fetch resets the time series and removes the loading key', () => { const promise = store.dispatch(Actions.retrieveCompareIVTimeSeries('12345678', 'P7D', startDT, endDT)); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 500, - responseText: 'Internal server error' - }); - promise.then(() => { + fakeServer.requests[0].respond(500, {}, 'Internal server error'); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.resetIVTimeSeries).toHaveBeenCalled(); expect(tsState.loadingIVTSKeys).not.toContain('compare:P7D'); - done(); }); }); }); @@ -301,7 +295,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' it('Service url should contain the siteno, startDT, and endDT', () => { store.dispatch(Actions.retrieveCustomTimePeriodIVTimeSeries('12345678', '00060', 'P14D')); - const url = jasmine.Ajax.requests.mostRecent().url; + const url = fakeServer.requests[0].url; expect(url).toContain('sites=12345678'); expect(url).toContain('parameterCd=00060'); expect(url).toContain('period=P14D'); @@ -315,32 +309,26 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' expect(tsState.userInputsForTimeRange.mainTimeRangeSelectionButton).toBe('custom'); }); - it('Expect that a successful fetch updates the data and sets the state appropriately', (done) => { + it('Expect that a successful fetch updates the data and sets the state appropriately', () => { const promise = store.dispatch(Actions.retrieveCustomTimePeriodIVTimeSeries('12345678', '00060', 'P14D')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - responseText: MOCK_IV_DATA - }); - promise.then(() => { + fakeServer.requests[0].respond(200, {}, MOCK_IV_DATA); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.addIVTimeSeriesCollection).toHaveBeenCalled(); expect(tsState.currentIVVariableID).toBe('45807197'); expect(tsState.loadingIVTSKeys).not.toContain('current:custom:00060'); - done(); }); }); - it('Expect that a failed fetch resets the time series and removes the loading key', (done) => { + it('Expect that a failed fetch resets the time series and removes the loading key', () => { const promise = store.dispatch(Actions.retrieveCustomTimePeriodIVTimeSeries('12345678', '00060', 'P14D')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 500, - responseText: 'Internal server error' - }); - promise.then(() => { + fakeServer.requests[0].respond(500, {}, 'Internal server error'); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.resetIVTimeSeries).toHaveBeenCalled(); expect(tsState.loadingIVTSKeys).not.toContain('current:custom:00060'); - done(); }); }); }); @@ -358,7 +346,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' it('Service url should contain the siteno, startDT, and endDT and current parameter code', () => { store.dispatch(Actions.retrieveCustomIVTimeSeries('12345678', startDT, endDT)); - const url = jasmine.Ajax.requests.mostRecent().url; + const url = fakeServer.requests[0].url; expect(url).toContain('sites=12345678'); expect(url).toContain('parameterCd=00060'); expect(url).toContain('startDT='); @@ -377,31 +365,25 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' expect(tsState.showIVTimeSeries.median).toBe(false); }); - it('Expect that a successful fetch updates the data and sets the state appropriately', (done) => { + it('Expect that a successful fetch updates the data and sets the state appropriately', () => { const promise = store.dispatch(Actions.retrieveCustomIVTimeSeries('12345678', startDT, endDT)); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - responseText: MOCK_IV_DATA - }); - promise.then(() => { + fakeServer.requests[fakeServer.requests.length - 1].respond(200, {}, MOCK_IV_DATA); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.addIVTimeSeriesCollection).toHaveBeenCalled(); expect(tsState.loadingIVTSKeys).not.toContain('current:custom:00060'); - done(); }); }); - it('Expect that a failed fetch resets the time series and removes the loading key', (done) => { + it('Expect that a failed fetch resets the time series and removes the loading key', () => { const promise = store.dispatch(Actions.retrieveCustomIVTimeSeries('12345678', '00060', 'P14D')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 500, - responseText: 'Internal server error' - }); - promise.then(() => { + fakeServer.requests[fakeServer.requests.length - 1].respond(500, {}, 'Internal server error'); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.addIVTimeSeriesCollection).toHaveBeenCalledWith({}); expect(tsState.loadingIVTSKeys).not.toContain('current:custom:00060'); - done(); }); }); }); @@ -414,62 +396,51 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' jest.spyOn(Actions, 'retrieveCompareIVTimeSeries'); store.dispatch(ivTimeSeriesStateActions.setCurrentIVVariable('45807197')); initialPromise = store.dispatch(Actions.retrieveIVTimeSeries('12345678')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - responseText: MOCK_IV_DATA - }); + fakeServer.requests[fakeServer.requests.length - 1].respond(200, {}, MOCK_IV_DATA); }); - it('Service url should contain the siteno, current parameter code, and period', (done) => { - initialPromise.then(() => { + it('Service url should contain the siteno, current parameter code, and period', () => { + return initialPromise.then(() => { store.dispatch(Actions.retrieveExtendedIVTimeSeries('12345678', 'P30D')); - const url = jasmine.Ajax.requests.mostRecent().url; + const url = fakeServer.requests[fakeServer.requests.length - 1].url; expect(url).toContain('sites=12345678'); expect(url).toContain('startDT='); expect(url).toContain('endDT='); - done(); }); }); - it('Loading key should be set for this time series before fetch is complete ', (done) => { - initialPromise.then(() => { + it('Loading key should be set for this time series before fetch is complete', () => { + return initialPromise.then(() => { store.dispatch(Actions.retrieveExtendedIVTimeSeries('12345678', 'P30D')); expect(store.getState().ivTimeSeriesState.loadingIVTSKeys).toContain('current:P30D:00060'); - done(); }); }); - it('Expect that a successful fetch updates the data and sets the state appropriately', (done) => { - initialPromise.then(() => { + it('Expect that a successful fetch updates the data and sets the state appropriately', () => { + return initialPromise.then(() => { const promise = store.dispatch(Actions.retrieveExtendedIVTimeSeries('12345678', 'P30D:00060')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - responseText: MOCK_IV_DATA - }); - promise.then(() => { + fakeServer.requests[fakeServer.requests.length - 1].respond(200, {}, MOCK_IV_DATA); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.addIVTimeSeriesCollection).toHaveBeenCalled(); expect(Actions.retrieveCompareIVTimeSeries).toHaveBeenCalled(); expect(tsState.loadingIVTSKeys).not.toContain('current:P30D'); - done(); }); }); }); - it('Expect that a failed fetch resets the time series and removes the loading key', (done) => { - initialPromise.then(() => { + it('Expect that a failed fetch resets the time series and removes the loading key', () => { + return initialPromise.then(() => { const promise = store.dispatch(Actions.retrieveExtendedIVTimeSeries('12345678', 'P30D')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 500, - responseText: 'Internal server error' - }); - promise.then(() => { + fakeServer.requests[fakeServer.requests.length - 1].respond(500, {}, 'Internal server error'); + + return promise.then(() => { const tsState = store.getState().ivTimeSeriesState; expect(Actions.addIVTimeSeriesCollection).toHaveBeenCalledWith({}); expect(tsState.loadingIVTSKeys).not.toContain('current:P30D:00060'); - done(); }); }); }); @@ -492,17 +463,14 @@ describe('monitoring-location/store/instantaneous-value-time-series-data module' expect(Actions.retrieveCustomIVTimeSeries).toHaveBeenCalled(); }); - it('Expect to retrieve extended time series if date range kind is not custom', (done) => { + it('Expect to retrieve extended time series if date range kind is not custom', () => { store.dispatch(ivTimeSeriesStateActions.setCurrentIVVariable('45807197')); let initialPromise = store.dispatch(Actions.retrieveIVTimeSeries('12345678')); - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - responseText: MOCK_IV_DATA - }); - initialPromise.then(() => { + fakeServer.requests[0].respond(200, {}, MOCK_IV_DATA); + + return initialPromise.then(() => { store.dispatch(Actions.updateIVCurrentVariableAndRetrieveTimeSeries('12345678', '45807197')); expect(Actions.retrieveExtendedIVTimeSeries).toHaveBeenCalled(); - done(); }); }); }); diff --git a/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-state.spec.js b/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-state.test.js similarity index 95% rename from assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-state.spec.js rename to assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-state.test.js index 06463ab24..d78ffd53c 100644 --- a/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-state.spec.js +++ b/assets/src/scripts/monitoring-location/store/instantaneous-value-time-series-state.test.js @@ -38,7 +38,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-state', () = describe('setCurrentIVMethodId', () => { it('sets the current IV method id', () => { store.dispatch(Actions.setCurrentIVMethodID('1345')); - expect(store.getState().ivTimeSeriesState.currentIVMethodID); + expect(store.getState().ivTimeSeriesState.currentIVMethodID).toBe('1345'); }); }); @@ -125,10 +125,11 @@ describe('monitoring-location/store/instantaneous-value-time-series-state', () = afterEach(() => { jest.useRealTimers(); + jest.clearAllMocks(); }); - it('Does not reset the cursor offset when current offset is not null or greater than the max offset ', () => { - mockGetState.and.returnValues({ + it('Does not reset the cursor offset when current offset is not null or greater than the max offset', () => { + mockGetState.mockReturnValue({ ivTimeSeriesState: { ivGraphCursorOffset: 0 } @@ -139,7 +140,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-state', () = }); it('Call the action to start time series play', () => { - mockGetState.and.returnValues({ + mockGetState.mockReturnValue({ ivTimeSeriesState: { ivGraphCursorOffset: 0 } @@ -150,7 +151,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-state', () = }); it('Expects the cursor to be updated after 10 milliseconds', () => { - mockGetState.and.returnValues({ + mockGetState.mockReturnValue({ ivTimeSeriesState: { ivGraphCursorOffset: 0 } @@ -162,12 +163,11 @@ describe('monitoring-location/store/instantaneous-value-time-series-state', () = Actions.startTimeSeriesPlay(2700000)(mockDispatch, mockGetState); jest.advanceTimersByTime(11); - expect(Actions.setIVGraphCursorOffset.mock.calls.length).toBe(1); - expect(Actions.setIVGraphCursorOffset.mock.calls[0][0]).toBe(900000); + expect(Actions.setIVGraphCursorOffset.mock.calls[2][0]).toBe(900000); }); it('Expects the cursor to be reset if the cursor offset is greater than the maxCursorOffset', () => { - mockGetState.and.returnValues({ + mockGetState.mockReturnValue({ ivTimeSeriesState: { ivGraphCursorOffset: 2700000 } @@ -179,7 +179,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-state', () = }); it('Expects the play to be stopped if the cursorOffset exceeds the maxCursorOffset', () => { - mockGetState.and.returnValues({ + mockGetState.mockReturnValue({ ivTimeSeriesState: { ivGraphCursorOffset: 2100000 } @@ -211,7 +211,7 @@ describe('monitoring-location/store/instantaneous-value-time-series-state', () = }); it('Expects that ivTimeSeriesPlayStop is called', () => { - mockGetState.and.returnValues({ + mockGetState.mockReturnValue({ ivTimeSeriesState: { audiblePlayId: 1 } diff --git a/assets/src/scripts/monitoring-location/store/network.test.js b/assets/src/scripts/monitoring-location/store/network.test.js index c01527452..3fa2bb841 100644 --- a/assets/src/scripts/monitoring-location/store/network.test.js +++ b/assets/src/scripts/monitoring-location/store/network.test.js @@ -76,34 +76,32 @@ describe('monitoring-location/store/network module', () => { it('Expects that fetching urls have the siteno', () => { store.dispatch(Actions.retrieveNetworkListData('12345678')); - expect(fakeServer.requests.length).toBe(1); + expect(fakeServer.requests).toHaveLength(1); expect(fakeServer.requests[0].url).toContain('USGS-12345678'); }); - it('Expects the store to be updated on successful fetches', (done) => { + it('Expects the store to be updated on successful fetches', () => { const promise = store.dispatch(Actions.retrieveNetworkListData('12345678')); fakeServer.requests[0].respond(200, {}, MOCK_OBSERVATION_ITEM); - promise.then(() => { + return promise.then(() => { const networkData = store.getState().networkData; expect(networkData.networkList).toEqual( JSON.parse(MOCK_OBSERVATION_ITEM).links.filter(function(link) { - return link['rel'] == 'collection'; + return link['rel'] === 'collection'; })); - done(); }); }); - it('Expects the store to contain empty array if calls are unsuccessful', (done) => { + it('Expects the store to contain empty array if calls are unsuccessful', () => { const promise = store.dispatch(Actions.retrieveNetworkListData('12345678')); fakeServer.requests[0].respond(500, {}, 'Internal server error'); - promise.then(() => { + return promise.then(() => { const networkData = store.getState().networkData; expect(networkData.networkList).toEqual([]); - done(); }); }); }); diff --git a/assets/src/scripts/monitoring-location/store/nldi-data.test.js b/assets/src/scripts/monitoring-location/store/nldi-data.test.js index 29a11fa9a..a40b3281c 100644 --- a/assets/src/scripts/monitoring-location/store/nldi-data.test.js +++ b/assets/src/scripts/monitoring-location/store/nldi-data.test.js @@ -95,41 +95,39 @@ describe('monitoring-location/store/nldi-data module', () => { it('Expects that fetching urls have the siteno', () => { store.dispatch(Actions.retrieveNldiData('12345678')); - expect(fakeServer.requests.length).toBe(3); + expect(fakeServer.requests).toHaveLength(3); expect(fakeServer.requests[0].url).toContain('USGS-12345678'); expect(fakeServer.requests[1].url).toContain('USGS-12345678'); expect(fakeServer.requests[2].url).toContain('USGS-12345678'); }); - it('Expects the store to be updated on successful fetches', (done) => { + it('Expects the store to be updated on successful fetches', () => { const promise = store.dispatch(Actions.retrieveNldiData('12345678')); fakeServer.requests[0].respond(200, {}, MOCK_NLDI_UPSTREAM_FLOW_FEATURE); fakeServer.requests[1].respond(200, {}, MOCK_NLDI_DOWNSTREAM_FLOW_FEATURE); fakeServer.requests[2].respond(200, {}, MOCK_NLDI_UPSTREAM_BASIN_FEATURE); - promise.then(() => { + return promise.then(() => { const nldiData = store.getState().nldiData; expect(nldiData.upstreamFlows).toEqual(JSON.parse(MOCK_NLDI_UPSTREAM_FLOW_FEATURE).features); expect(nldiData.downstreamFlows).toEqual(JSON.parse(MOCK_NLDI_DOWNSTREAM_FLOW_FEATURE).features); expect(nldiData.upstreamBasin).toEqual(JSON.parse(MOCK_NLDI_UPSTREAM_BASIN_FEATURE).features); - done(); }); }); - it('Expects the store to not contain empty features if calls are unsuccessful', (done) => { + it('Expects the store to not contain empty features if calls are unsuccessful', () => { const promise = store.dispatch(Actions.retrieveNldiData('12345678')); fakeServer.requests[0].respond(500, {}, 'Internal server error'); fakeServer.requests[1].respond(500, {}, 'Internal server error'); fakeServer.requests[2].respond(500, {}, 'Internal server error'); - promise.then(() => { + return promise.then(() => { const nldiData = store.getState().nldiData; expect(nldiData.upstreamFlows).toEqual([]); expect(nldiData.downstreamFlows).toEqual([]); expect(nldiData.upstreamBasin).toEqual([]); - done(); }); }); }); diff --git a/assets/src/scripts/monitoring-location/store/statistics-data.test.js b/assets/src/scripts/monitoring-location/store/statistics-data.test.js index 2b27a27d6..aa0446105 100644 --- a/assets/src/scripts/monitoring-location/store/statistics-data.test.js +++ b/assets/src/scripts/monitoring-location/store/statistics-data.test.js @@ -50,23 +50,21 @@ describe('monitoring-location/store/statistics-data module', () => { expect(fakeServer.requests[0].url).toContain('sites=12345678'); }); - it('Expect that a succesful fetch updates the store', (done) => { + it('Expect that a succesful fetch updates the store', () => { const promise = store.dispatch(Actions.retrieveMedianStatistics('12345678')); fakeServer.requests[0].respond(200, {}, MOCK_STATISTICS_RDB); - promise.then(() => { + return promise.then(() => { expect(store.getState().statisticsData.median['00060']).toBeDefined(); - done(); }); }); - it('Expect that a failed fetch leaves the store with an empty object', (done) => { + it('Expect that a failed fetch leaves the store with an empty object', () => { const promise = store.dispatch(Actions.retrieveMedianStatistics('12345678')); fakeServer.requests[0].respond(500, {}, 'Internal Server error'); - promise.then(() => { + return promise.then(() => { expect(store.getState().statisticsData.median).toEqual({}); - done(); }); }); }); diff --git a/assets/src/scripts/monitoring-location/store/time-zone.test.js b/assets/src/scripts/monitoring-location/store/time-zone.test.js index ba8348528..036d50fe5 100644 --- a/assets/src/scripts/monitoring-location/store/time-zone.test.js +++ b/assets/src/scripts/monitoring-location/store/time-zone.test.js @@ -44,21 +44,19 @@ describe('monitoring-location/store/time-zone module', () => { expect(fakeServer.requests[0].url).toContain('45.3,-100.2'); }); - it('Successful fetch assigns time zone', (done) => { + it('Successful fetch assigns time zone', () => { const promise = store.dispatch(Actions.retrieveIanaTimeZone('45.3', '-100.2')); fakeServer.requests[0].respond(200, {}, '{"properties" : {"timeZone" : "America/Chicago"}}'); - promise.then(() => { + return promise.then(() => { expect(store.getState().ianaTimeZone).toBe('America/Chicago'); - done(); }); }); - it('Failed fetch assigns time zone to be null', (done) => { + it('Failed fetch assigns time zone to be null', () => { const promise = store.dispatch(Actions.retrieveIanaTimeZone('45.3', '-100.2')); fakeServer.requests[0].respond(500, {}, '{"properties" : {}}'); - promise.then(() => { + return promise.then(() => { expect(store.getState().ianaTimeZone).toBeNull(); - done(); }); }); }); diff --git a/assets/src/scripts/monitoring-location/url-params.test.js b/assets/src/scripts/monitoring-location/url-params.test.js index a9d50823d..c9ffd2a8f 100644 --- a/assets/src/scripts/monitoring-location/url-params.test.js +++ b/assets/src/scripts/monitoring-location/url-params.test.js @@ -105,7 +105,7 @@ describe('monitoring-location/url-params module', () => { expect(window.location.hash).not.toContain('timeSeriesId'); }); - it('adds period if current date range is P30D or P1Y', (done) => { + it('adds period if current date range is P30D or P1Y', () => { let store = configureStore({ ...TEST_STATE, ivTimeSeriesState: { @@ -123,13 +123,15 @@ describe('monitoring-location/url-params module', () => { expect(window.location.hash).not.toContain('timeSeriesId'); store.dispatch(Actions.setCurrentIVDateRange('P1Y')); - window.requestAnimationFrame(() => { - expect(window.location.hash).toContain('period=P1Y'); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(window.location.hash).toContain('period=P1Y'); + resolve(); + }); }); }); - it('adds period if current date range not P7D and is in the form of P{some number}{Day or Year code}', (done) => { + it('adds period if current date range not P7D and is in the form of P{some number}{Day or Year code}', () => { let store = configureStore({ ...TEST_STATE, ivTimeSeriesState: { @@ -147,13 +149,15 @@ describe('monitoring-location/url-params module', () => { expect(window.location.hash).not.toContain('timeSeriesId'); store.dispatch(Actions.setCurrentIVDateRange('P1Y')); - window.requestAnimationFrame(() => { - expect(window.location.hash).toContain('period=P1Y'); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(window.location.hash).toContain('period=P1Y'); + resolve(); + }); }); }); - it('does not add period if current date range is P7D', (done) => { + it('does not add period if current date range is P7D', () => { let store = configureStore({ ...TEST_STATE, ivTimeSeriesState: { @@ -171,9 +175,11 @@ describe('monitoring-location/url-params module', () => { expect(window.location.hash).not.toContain('timeSeriesId'); store.dispatch(Actions.setCurrentIVDateRange('P1Y')); - window.requestAnimationFrame(() => { - expect(window.location.hash).toContain('period=P1Y'); - done(); + return new Promise(resolve => { + window.requestAnimationFrame(() => { + expect(window.location.hash).toContain('period=P1Y'); + resolve(); + }); }); }); diff --git a/assets/src/scripts/network/store/index.test.js b/assets/src/scripts/network/store/index.test.js index 1f9d2f235..77699a21c 100644 --- a/assets/src/scripts/network/store/index.test.js +++ b/assets/src/scripts/network/store/index.test.js @@ -86,27 +86,25 @@ describe('network/store', () => { fakeServer.restore(); }); - it('fetches the data and updates the redux store', (done) => { + it('fetches the data and updates the redux store', () => { jest.spyOn(Actions, 'setNetworkMonitoringLocations').mockImplementation(() => {}); let p = Actions.retrieveNetworkMonitoringLocations(NETWORK_CD)(mockDispatch, mockGetState); fakeServer.requests[0].respond(200, {'Content-Type': 'application/json'}, MOCK_NETWORK_FEATURE); - p.then(() => { - expect(mockDispatch.mock.calls.length).toBe(1); - expect(Actions.setNetworkMonitoringLocations.mock.calls.length).toBe(1); - done(); + return p.then(() => { + expect(mockDispatch.mock.calls).toHaveLength(1); + expect(Actions.setNetworkMonitoringLocations.mock.calls).toHaveLength(1); }); }); - it('a failed fetch sets the save monitoring locations to the empty array', (done) => { + it('a failed fetch sets the save monitoring locations to the empty array', () => { jest.spyOn(Actions, 'setNetworkMonitoringLocations').mockImplementation(() => {}); let p = Actions.retrieveNetworkMonitoringLocations(NETWORK_CD)(mockDispatch, mockGetState); fakeServer.requests[0].respond(500); - p.then(() => { - expect(mockDispatch.mock.calls.length).toBe(1); - expect(Actions.setNetworkMonitoringLocations.mock.calls.length).toBe(1); + return p.then(() => { + expect(mockDispatch.mock.calls).toHaveLength(1); + expect(Actions.setNetworkMonitoringLocations.mock.calls).toHaveLength(1); expect(Actions.setNetworkMonitoringLocations).toHaveBeenCalledWith([]); - done(); }); }); }); diff --git a/assets/src/scripts/schema.test.js b/assets/src/scripts/schema.test.js index b829664d0..506fee03c 100644 --- a/assets/src/scripts/schema.test.js +++ b/assets/src/scripts/schema.test.js @@ -203,7 +203,7 @@ describe('Normalizr schema', () => { }); -export const MOCK_DATA = ` +const MOCK_DATA = ` {"name" : "ns1:timeSeriesResponseType", "declaredType" : "org.cuahsi.waterml.TimeSeriesResponseType", "scope" : "javax.xml.bind.JAXBElement$GlobalScope", diff --git a/assets/src/scripts/utils.test.js b/assets/src/scripts/utils.test.js index 7652cc9b8..1650cefff 100644 --- a/assets/src/scripts/utils.test.js +++ b/assets/src/scripts/utils.test.js @@ -28,7 +28,7 @@ describe('Utils module', () => { let result = getHtmlFromString('kg * m²/s³'); expect(result).toContain('²'); expect(result).toContain('³'); - expect(result.length).toBe(2); + expect(result).toHaveLength(2); }); }); @@ -61,7 +61,7 @@ describe('Utils module', () => { }); // Can't run this is jsdom because getComputedTextLength needs real DOM. - xdescribe('wrap() fits long text', () => { + describe.skip('wrap() fits long text', () => { const lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; let elem; let maxWordWidth; @@ -115,7 +115,7 @@ describe('Utils module', () => { }); // Can't run this because it requires a real DOM - xdescribe('mediaQuery', () => { + describe.skip('mediaQuery', () => { it('returns a boolean', () => { expect(typeof mediaQuery(-100)).toEqual('boolean'); expect(typeof mediaQuery(0)).toEqual('boolean'); @@ -171,19 +171,19 @@ describe('Utils module', () => { /* eslint no-use-before-define: 0 */ it('parseRDB successfully parses RDB content', () => { let result = parseRDB(MOCK_RDB); - expect(result.length).toEqual(13); + expect(result).toHaveLength(13); expect(Object.keys(result[0])).toEqual(['agency_cd', 'site_no', 'parameter_cd', 'ts_id', 'loc_web_ds', 'month_nu', 'day_nu', 'begin_yr', 'end_yr', 'count_nu', 'p50_va']); }); it('parseRDB handles no data', () => { let result = parseRDB(MOCK_RDB_NO_DATA); - expect(result.length).toEqual(0); + expect(result).toHaveLength(0); }); it('parseRDB handles no headers', () => { let result = parseRDB('#Some Stuff'); - expect(result.length).toEqual(0); + expect(result).toHaveLength(0); }); }); @@ -249,11 +249,11 @@ describe('Utils module', () => { }); it('handles the case where variables are empty', () => { - expect(sortedParameters({}).length).toEqual(0); + expect(sortedParameters({})).toHaveLength(0); }); it('handles the case where variables are undefined', () => { - expect(sortedParameters(undefined).length).toEqual(0); + expect(sortedParameters(undefined)).toHaveLength(0); }); }); diff --git a/assets/src/scripts/web-services/flood-data.test.js b/assets/src/scripts/web-services/flood-data.test.js index ae233fd1d..07b6ae7ff 100644 --- a/assets/src/scripts/web-services/flood-data.test.js +++ b/assets/src/scripts/web-services/flood-data.test.js @@ -21,7 +21,7 @@ describe('flood_data module', () => { describe('with valid response', () => { let promise; - it('expected response is true', (done) => { + it('expected response is true', () => { promise = fetchFIMPublicStatus(siteno); fakeServer.requests[0].respond( 200, @@ -36,13 +36,12 @@ describe('flood_data module', () => { }` ); - promise.then((resp) => { + return promise.then((resp) => { expect(resp).toBeTruthy(); - done(); }); }); - it('expected response is False', (done) => { + it('expected response is False', () => { promise = fetchFIMPublicStatus(siteno); fakeServer.requests[0].respond( 200, @@ -59,20 +58,19 @@ describe('flood_data module', () => { }` ); - promise.then((resp) => { + return promise.then((resp) => { expect(resp).toBeFalsy(); - done(); }); }); }); describe('with error response', () => { - it('On failed response return false', (done) => { - fetchFIMPublicStatus(siteno).then((resp) => { + it('On failed response return false', () => { + const fetchPromise = fetchFIMPublicStatus(siteno); + fakeServer.requests[0].respond(500); + return fetchPromise.then((resp) => { expect(resp).toBeFalsy(); - done(); }); - fakeServer.requests[0].respond(500); }); }); }); @@ -96,8 +94,8 @@ describe('flood_data module', () => { }); it('expected response is json object with the stages', () => { - promise.then((resp) => { - expect(resp.length).toBe(3); + return promise.then((resp) => { + expect(resp).toHaveLength(3); expect(resp[0].attributes.STAGE).toBe(30); expect(resp[1].attributes.STAGE).toBe(29); expect(resp[2].attributes.STAGE).toBe(28); @@ -107,10 +105,11 @@ describe('flood_data module', () => { describe('with error response', () => { it('On failed response return an empty feature list', () => { - fetchFloodFeatures(siteno).then((resp) => { - expect(resp.length).toBe(0); - }); + const fetchPromise = fetchFloodFeatures(siteno); fakeServer.requests[0].respond(500); + return fetchPromise.then((resp) => { + expect(resp).toHaveLength(0); + }); }); }); }); @@ -134,7 +133,7 @@ describe('flood_data module', () => { }); it('expected response is json object with the extent', () => { - promise.then((resp) => { + return promise.then((resp) => { expect(resp.extent).toBeDefined(); expect(resp.extent.xmin).toBe(-84.353211731250525); expect(resp.extent.xmax).toBe(-84.223456338038901); @@ -152,7 +151,7 @@ describe('flood_data module', () => { }); it('On failed response return an empty feature list', () => { - promise.then((resp) => { + return promise.then((resp) => { expect(resp).toEqual({}); }); }); @@ -180,7 +179,7 @@ describe('flood_data module', () => { }); it('expected response is json object with the flood levels', () => { - floodLevelPromise.then((resp) => { + return floodLevelPromise.then((resp) => { expect(resp).not.toEqual(null); expect(resp.site_no).toBe('07144100'); }); @@ -189,10 +188,11 @@ describe('flood_data module', () => { describe('with error response', () => { it('On failed response return an empty flood levels list', () => { - fetchWaterwatchFloodLevels(siteno).then((resp) => { + const fetchPromise = fetchWaterwatchFloodLevels(siteno); + fakeServer.requests[0].respond(500, {}, 'Error'); + return fetchPromise.then((resp) => { expect(resp).toBeNull(); }); - fakeServer.requests[0].respond(500, {}, 'Error'); }); }); }); diff --git a/assets/src/scripts/web-services/models.test.js b/assets/src/scripts/web-services/models.test.js index bb98181bf..ef612f53c 100644 --- a/assets/src/scripts/web-services/models.test.js +++ b/assets/src/scripts/web-services/models.test.js @@ -125,30 +125,28 @@ describe('Models module', () => { expect(fakeServer.requests[0].url).toContain('45.3,-100.2'); }); - it('Expect that a successful fetch returns the response', (done) => { + it('Expect that a successful fetch returns the response', () => { const MOCK_WEATHER_SERVICE_DATA = '{"properties" : {"timeZone" : "America/Chicago"}}'; const promise = queryWeatherService('45.3', '100.2'); fakeServer.requests[0].respond(200, {}, MOCK_WEATHER_SERVICE_DATA); - promise.then((response) => { + return promise.then((response) => { expect(response).toEqual({ properties: { timeZone: 'America/Chicago' } }); - done(); }); }); - it('Expect that a failed fetch returns a JSON object with empty properties', (done) => { + it('Expect that a failed fetch returns a JSON object with empty properties', () => { const promise = queryWeatherService('45.3', '100.2'); fakeServer.requests[0].respond(500, {}, 'Internal server error'); - promise.then((response) => { + return promise.then((response) => { expect(response).toEqual({ properties: {} }); - done(); }); }); }); diff --git a/assets/src/scripts/web-services/nldi-data.test.js b/assets/src/scripts/web-services/nldi-data.test.js index 11547e81e..dd44c94eb 100644 --- a/assets/src/scripts/web-services/nldi-data.test.js +++ b/assets/src/scripts/web-services/nldi-data.test.js @@ -1,3 +1,4 @@ +import mockConsole from 'jest-mock-console'; import sinon from 'sinon'; import {MOCK_NLDI_UPSTREAM_FLOW_FEATURE, MOCK_NLDI_DOWNSTREAM_FLOW_FEATURE, @@ -7,12 +8,15 @@ import {fetchNldiUpstreamFlow, fetchNldiDownstreamFlow, fetchNldiUpstreamBasin} describe('nldi-data module', () => { let fakeServer; + let restoreConsole; beforeEach(() => { fakeServer = sinon.createFakeServer(); + restoreConsole = mockConsole(); }); afterEach(() => { + restoreConsole(); fakeServer.restore(); }); @@ -34,23 +38,22 @@ describe('nldi-data module', () => { ); }); - it('expected response is json object with the upstream flow', (done) => { - upstreamFlowPromise.then((resp) => { - expect(resp.length).toBe(2); + it('expected response is json object with the upstream flow', () => { + return upstreamFlowPromise.then((resp) => { + expect(resp).toHaveLength(2); expect(resp[0].properties.nhdplus_comid).toBe('10286212'); expect(resp[1].properties.nhdplus_comid).toBe('10286442'); - done(); }); }); }); describe('with error response', () => { - it('On failed response return an empty feature list', (done) => { - fetchNldiUpstreamFlow(siteno).then((resp) => { - expect(resp.length).toBe(0); - done(); - }); + it('On failed response return an empty feature list', () => { + const fetchPromise = fetchNldiUpstreamFlow(siteno); fakeServer.requests[0].respond(500); + return fetchPromise.then((resp) => { + expect(resp).toHaveLength(0); + }); }); }); }); @@ -73,24 +76,22 @@ describe('nldi-data module', () => { ); }); - it('expected response is json object with the downstream flow', (done) => { - downstreamFlowPromise.then((resp) => { - expect(resp.length).toBe(2); + it('expected response is json object with the downstream flow', () => { + return downstreamFlowPromise.then((resp) => { + expect(resp).toHaveLength(2); expect(resp[0].properties.nhdplus_comid).toBe('10286213'); expect(resp[1].properties.nhdplus_comid).toBe('10286443'); - - done(); }); }); }); describe('with error response', () => { - it('On failed response return an empty feature list', (done) => { - fetchNldiDownstreamFlow(siteno).then((resp) => { - expect(resp.length).toBe(0); - done(); - }); + it('On failed response return an empty feature list', () => { + const fetchPromise = fetchNldiDownstreamFlow(siteno); fakeServer.requests[0].respond(500); + return fetchPromise.then((resp) => { + expect(resp).toHaveLength(0); + }); }); }); }); @@ -113,21 +114,20 @@ describe('nldi-data module', () => { ); }); - it('expected response is json object with the upstream basin', (done) => { - upstreamBasinPromise.then((resp) => { - expect(resp.length).toBe(1); - done(); + it('expected response is json object with the upstream basin', () => { + return upstreamBasinPromise.then((resp) => { + expect(resp).toHaveLength(1); }); }); }); describe('with error response', () => { - it('On failed response return an empty feature list', (done) => { - fetchNldiUpstreamBasin(siteno).then((resp) => { - expect(resp.length).toBe(0); - done(); - }); + it('On failed response return an empty feature list', () => { + const fetchPromise = fetchNldiUpstreamBasin(siteno); fakeServer.requests[0].respond(500); + return fetchPromise.then((resp) => { + expect(resp).toHaveLength(0); + }); }); }); }); diff --git a/assets/src/scripts/web-services/observations.test.js b/assets/src/scripts/web-services/observations.test.js index 616e65efb..a77d7def0 100644 --- a/assets/src/scripts/web-services/observations.test.js +++ b/assets/src/scripts/web-services/observations.test.js @@ -37,7 +37,7 @@ describe('web-services/observations module', () => { }); it('Expect url to contain query parameters', () => { - networkPromise = fetchNetworkMonitoringLocations(networkCd, {active: true, agencyCode: 'USGS'}); + fetchNetworkMonitoringLocations(networkCd, {active: true, agencyCode: 'USGS'}); const url = fakeServer.requests[1].url; const queryString = url.split('?')[1]; @@ -45,17 +45,19 @@ describe('web-services/observations module', () => { expect(queryString).toContain('active=true'); expect(queryString).toContain('agencyCode=USGS'); expect(queryString).toContain('f=json'); - expect(queryString.split('&').length).toBe(3); + expect(queryString.split('&')).toHaveLength(3); }); it('expected response is json object with the network sites', () => { - networkPromise = fetchNetworkMonitoringLocations(networkCd ); - fakeServer.respondWith( - `${config.OBSERVATIONS_ENDPOINT}/${networkCd}/items`, - [200, {'Content-Type': 'application/json'}, MOCK_NETWORK_FEATURE] + networkPromise = fetchNetworkMonitoringLocations(networkCd); + fakeServer.requests[fakeServer.requests.length - 1].respond( + 200, + {'Content-Type': 'application/json'}, + MOCK_NETWORK_FEATURE ); - networkPromise.then((resp) => { - expect(resp.length).toBe(1); + + return networkPromise.then((resp) => { + expect(resp).toHaveLength(1); expect(resp).toEqual(JSON.parse(MOCK_NETWORK_FEATURE).features); }); }); @@ -67,30 +69,30 @@ describe('web-services/observations module', () => { expect(fakeServer.requests[0].url).toContain('USGS-1234567890'); }); - it('Expects json response with a valid response', (done) => { - fetchAvailableDVTimeSeries('USGS-1234567890') - .then((resp) => { - expect(resp).toBeInstanceOf(Object); - expect(resp.timeSeries).toBeDefined; - expect(resp.timeSeries.length).toBe(1); - - done(); - }); + it('Expects json response with a valid response', () => { + const fetchPromise = fetchAvailableDVTimeSeries('USGS-1234567890'); fakeServer.requests[0].respond( 200, {'Content-Type': 'application/json'}, VALID_AVAILABLE_STATS_RESPONSE ); + return fetchPromise + .then((resp) => { + expect(resp).toBeInstanceOf(Object); + expect(resp.timeSeries).toBeDefined(); + expect(resp.timeSeries).toHaveLength(1); + }); + }); - it('Expect empty object with an bad response', (done) => { - fetchAvailableDVTimeSeries('USGS-1234567890') + it('Expect empty object with an bad response', () => { + const fetchPromise = fetchAvailableDVTimeSeries('USGS-1234567890'); + fakeServer.requests[0].respond(500); + return fetchPromise .then((resp) => { expect(resp).toBeInstanceOf(Object); expect(resp).toEqual({}); - done(); }); - fakeServer.requests[0].respond(500); }); }); @@ -102,30 +104,29 @@ describe('web-services/observations module', () => { expect(url).toContain('12345670abcdef'); }); - it('Expect json response with a valid response', (done) => { - fetchDVTimeSeries('USGS-1234567890', '12345670abcdef') - .then((resp) => { - expect(resp).toBeInstanceOf(Object); - expect(resp.properties).toBeDefined; - expect(resp.properties.timeStep).toEqual(['2013-10-02', '2013-10-03', '2013-10-04']); - - done(); - }); + it('Expect json response with a valid response', () => { + const fetchPromise = fetchDVTimeSeries('USGS-1234567890', '12345670abcdef'); fakeServer.requests[0].respond( 200, {'Content-Type': 'application/json'}, VALID_STATS_RESPONSE ); + return fetchPromise.then((resp) => { + expect(resp).toBeInstanceOf(Object); + expect(resp.properties).toBeDefined(); + expect(resp.properties.timeStep).toEqual(['2013-10-02', '2013-10-03', '2013-10-04']); + }); + }); - it('Expect empty object with an bad response', (done) => { - fetchDVTimeSeries('1234567890', '12345670abcdef') + it('Expect empty object with an bad response', () => { + const fetchPromise = fetchDVTimeSeries('1234567890', '12345670abcdef'); + fakeServer.requests[0].respond(500); + return fetchPromise .then((resp) => { expect(resp).toBeInstanceOf(Object); expect(resp).toEqual({}); - done(); }); - fakeServer.requests[0].respond(500); }); }); @@ -136,30 +137,30 @@ describe('web-services/observations module', () => { expect(url).toContain('USGS-1234567890'); }); - it('Expect json response with a valid response', (done) => { - fetchMonitoringLocationMetaData('USGS-1234567890') - .then((resp) => { - expect(resp).toBeInstanceOf(Object); - expect(resp.properties).toBeDefined; - expect(resp.links.length).toEqual(6); - - done(); - }); + it('Expect json response with a valid response', () => { + const fetchPromise = fetchMonitoringLocationMetaData('USGS-1234567890'); fakeServer.requests[0].respond( 200, {'Content-Type': 'application/json'}, MOCK_OBSERVATION_ITEM ); + return fetchPromise + .then((resp) => { + expect(resp).toBeInstanceOf(Object); + expect(resp.properties).toBeDefined(); + expect(resp.links).toHaveLength(6); + }); + }); - it('Expect empty object with an bad response', (done) => { - fetchMonitoringLocationMetaData('1234567890') + it('Expect empty object with an bad response', () => { + const fetchPromise = fetchMonitoringLocationMetaData('1234567890'); + fakeServer.requests[0].respond(500); + return fetchPromise .then((resp) => { expect(resp).toBeInstanceOf(Object); expect(resp).toEqual({}); - done(); }); - fakeServer.requests[0].respond(500); }); }); }); diff --git a/assets/src/scripts/web-services/statistics-data.test.js b/assets/src/scripts/web-services/statistics-data.test.js index 2a7d33dd5..0290d6a63 100644 --- a/assets/src/scripts/web-services/statistics-data.test.js +++ b/assets/src/scripts/web-services/statistics-data.test.js @@ -53,8 +53,8 @@ describe('statistics-data', () => { expect(request.url).toContain('sites=05370000'); }); - it('Parses the data as expected', (done) => { - promise.then((resp) => { + it('Parses the data as expected', () => { + return promise.then((resp) => { expect(resp).toEqual({ '00060': { '153885': [{ @@ -216,7 +216,6 @@ describe('statistics-data', () => { }] } }); - done(); }); }); }); -- GitLab