Interactive interface for browsing global, full-resolution satellite imagery
tests for different time zone
Mike McGann37d68e4168be
diff --git a/.travis.yml b/.travis.ymlindex ca3517a35..3cd10d3fc 100644--- a/.travis.yml+++ b/.travis.yml@@ -12,4 +12,4 @@ cache:- .pythoninstall: npm install-script: npm test+script: npm run cidiff --git a/doc/testing.md b/doc/testing.mdindex 1fb1701e0..cf60ce942 100644--- a/doc/testing.md+++ b/doc/testing.md@@ -9,10 +9,11 @@ Use `npm run lint:css` or `npm run lint:js` to check CSS or JS files separately.## Unit TestsUnit tests are run using the BusterJS test runner. To run unit tests, run-`npm test`. Make sure to run `npm run build` or `npm run build:tests` first to-build a testable version of Worldview.+`npm test`. Make sure to run `npm run getcapabilities` and+`npm run build:config` first to build the configuration.-*Note for Windows users:* `npm test` may fail unless you [install PhantomJS manually](http://phantomjs.org/download.html).+To test against a different time zone, run `npm run test:unit:tz`. This+currently doesn't work in Windows.## End-to-end TestsEnd to end tests are integrated into our CI and are required to pass before a submission is accepted. New features should be accompanied by End to End tests to cover any new functionality you add.diff --git a/package.json b/package.jsonindex f60fbe6a3..6afd59104 100644--- a/package.json+++ b/package.json@@ -32,6 +32,7 @@"build:dev": "cross-env NODE_ENV=development webpack","build:config": "bash -c 'tasks/buildOptions.sh' && node ./tasks/config.js","build:prod": "cross-env NODE_ENV=production webpack",+ "ci": "npm run test:unit && npm run test:unit:tz && npm run test:lint","clean": "node ./tasks/clean.js","dist": "npm run clean && npm run getcapabilities && npm run build:config && npm run build:prod && node ./tasks/dist.js","dist:dev": "npm run clean && npm run getcapabilities && npm run build:config && npm run build:dev && node ./tasks/dist.js",@@ -61,6 +62,7 @@"test": "npm run test:unit && npm run test:lint","test:lint": "npx eslint .","test:unit": "npx jest",+ "test:unit:tz": "TZ=Australia/Sydney npx jest","updateconfig": "run-s getcapabilities build:config","watch": "cross-env NODE_ENV=development webpack-dev-server","upload": "node tasks/upload.js"diff --git a/web/js/date/date.js b/web/js/date/date.jsindex 188227334..fd0a43a5a 100644--- a/web/js/date/date.js+++ b/web/js/date/date.js@@ -28,7 +28,6 @@ export function parse(state, errors) {util.now = function() {return new Date(state.now.getTime());};- util.warn('Overriding now: ' + state.now.toISOString());} catch (error) {delete state.now;errors.push({diff --git a/web/js/util/util.js b/web/js/util/util.jsindex 547f0a01e..d38612575 100644--- a/web/js/util/util.js+++ b/web/js/util/util.js@@ -390,7 +390,7 @@ export default (function (self) {self.dateAdd = function (date, interval, amount) {var month, maxDay, year;- var newDate = new Date(date.getTime());+ var newDate = new Date(date);switch (interval) {case 'minute':newDate.setUTCMinutes(newDate.getUTCMinutes() + amount);@@ -447,7 +447,7 @@ export default (function (self) {self.daysInYear = function (date) {var jStart, jDate;jStart = self.parseDateUTC(date.getUTCFullYear() + '-01-01');- jDate = '00' + (Math.ceil((date.getTime() - jStart) / 86400000));+ jDate = '00' + (Math.ceil((date.getTime() - jStart) / 86400000) + 1);return (jDate).substr((jDate.length) - 3);};diff --git a/web/js/util/util.test.js b/web/js/util/util.test.jsindex 9f7575847..9e93a63df 100644--- a/web/js/util/util.test.js+++ b/web/js/util/util.test.js@@ -117,15 +117,15 @@ test('clearTimeUTC', () => {describe('dateAdd', () => {let tests = [- { part: 'day', fn: 'getDate', answer: 5 },- { part: 'month', fn: 'getMonth', answer: 5 },- { part: 'year', fn: 'getFullYear', answer: 2015 },+ { part: 'day', fn: 'getUTCDate', answer: 5 },+ { part: 'month', fn: 'getUTCMonth', answer: 5 },+ { part: 'year', fn: 'getUTCFullYear', answer: 2015 },{ part: 'foo' }];tests.forEach((t) => {test(t.part, () => {- let d = new Date(2011, 1, 1);+ let d = new Date(Date.UTC(2011, 1, 1));if (t.answer) {let result = util.dateAdd(d, t.part, 4);expect(result[t.fn]()).toBe(t.answer);@@ -138,16 +138,31 @@ describe('dateAdd', () => {describe('daysInMonth', () => {test('feb, non-leap', () => {- var d = new Date(2015, 1, 15);+ var d = new Date(Date.UTC(2015, 1, 15));expect(util.daysInMonth(d)).toBe(28);});test('feb, leap', () => {- var d = new Date(2016, 1, 15);+ var d = new Date(Date.UTC(2016, 1, 15));expect(util.daysInMonth(d)).toBe(29);});});+describe('daysInYear', () => {+ let tests = [+ { date: Date.UTC(2015, 5, 26), doy: '177', name: '2015 jun 26 => 177' },+ { date: Date.UTC(2015, 0, 1), doy: '001', name: 'first of year' },+ { date: Date.UTC(2015, 11, 31), doy: '365', name: 'last day of year' },+ { date: Date.UTC(2016, 11, 31), doy: '366', name: 'last day of leap year' }+ ];+ tests.forEach((t) => {+ test(t.name, () => {+ let d = new Date(t.date);+ expect(util.daysInYear(d)).toBe(t.doy);+ });+ });+});+describe('clamp', () => {let tests = [{ v: 15, min: 10, max: 20, answer: 15, name: 'middle' },