From 65053f5f28da9d81ed63f67693240c2baa886891 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 26 Nov 2021 13:26:48 +0100 Subject: [PATCH 1/3] feat(worker_time-control): add timestamp url param --- modules/worker/front/routes.json | 2 +- modules/worker/front/time-control/index.html | 1 + modules/worker/front/time-control/index.js | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index 4bad33dd0..47334d841 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -83,7 +83,7 @@ "worker": "$ctrl.worker" } }, { - "url": "/time-control", + "url": "/time-control?timestamp", "state": "worker.card.timeControl", "component": "vn-worker-time-control", "description": "Time control", diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index 66d6f282e..170d88b21 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -91,6 +91,7 @@ diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 96913c505..1f6251391 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -15,7 +15,15 @@ class Controller extends Section { } $postLink() { - this.date = new Date(); + const timestamp = this.$params.timestamp; + let initialDate = new Date(); + + if (timestamp) { + initialDate = new Date(timestamp * 1000); + this.$.calendar.defaultDate = initialDate; + } + + this.date = initialDate; } get worker() { From 85e3b47408e70048290b816d7227624b98945f49 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 29 Nov 2021 15:22:16 +0100 Subject: [PATCH 2/3] test(worker_time-control): tested url parameter timestamp --- e2e/helpers/puppeteer.js | 2 +- .../worker/front/time-control/index.spec.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/e2e/helpers/puppeteer.js b/e2e/helpers/puppeteer.js index dace276be..abd76b434 100644 --- a/e2e/helpers/puppeteer.js +++ b/e2e/helpers/puppeteer.js @@ -27,7 +27,7 @@ export async function getBrowser() { args, defaultViewport: null, headless: headless, - slowMo: 5, // slow down by ms + slowMo: 1, // slow down by ms // ignoreDefaultArgs: ['--disable-extensions'], // executablePath: '/usr/bin/google-chrome-stable', // executablePath: '/usr/bin/firefox-developer-edition', diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index 920f13e7c..39a47c47f 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -129,5 +129,28 @@ describe('Component vnWorkerTimeControl', () => { expect(controller.fetchHours).toHaveBeenCalledWith(); }); }); + + describe('$postLink() ', () => { + it(`should set the controller date as today if no timestamp is defined`, () => { + controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())}; + controller.$params = {timestamp: undefined}; + controller.$postLink(); + + expect(controller.date).toEqual(jasmine.any(Date)); + }); + + it(`should set the controller date using the received timestamp`, () => { + const date = 'Wed, 31 Dec 1969 23:00:00 GMT'; + const timestamp = 1; + + controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())}; + controller.$.calendar = {}; + controller.$params = {timestamp: timestamp}; + + controller.$postLink(); + + expect(controller.date.toUTCString()).toEqual(date); + }); + }); }); }); From 594f258232435b841c11b956aaec32aa1d66a987 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 30 Nov 2021 07:16:43 +0100 Subject: [PATCH 3/3] modify js date format --- modules/worker/front/time-control/index.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index 39a47c47f..4f317a5e6 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -140,8 +140,8 @@ describe('Component vnWorkerTimeControl', () => { }); it(`should set the controller date using the received timestamp`, () => { - const date = 'Wed, 31 Dec 1969 23:00:00 GMT'; const timestamp = 1; + const date = new Date(timestamp); controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())}; controller.$.calendar = {}; @@ -149,7 +149,7 @@ describe('Component vnWorkerTimeControl', () => { controller.$postLink(); - expect(controller.date.toUTCString()).toEqual(date); + expect(controller.date.toDateString()).toEqual(date.toDateString()); }); }); });