Merge pull request '2676-worker_time-control add timestamp url param' (#809) from 2676-worker_time-control into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #809
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2021-11-30 08:20:20 +00:00
commit 68a3a4d1e0
5 changed files with 35 additions and 3 deletions

View File

@ -27,7 +27,7 @@ export async function getBrowser() {
args, args,
defaultViewport: null, defaultViewport: null,
headless: headless, headless: headless,
slowMo: 5, // slow down by ms slowMo: 1, // slow down by ms
// ignoreDefaultArgs: ['--disable-extensions'], // ignoreDefaultArgs: ['--disable-extensions'],
// executablePath: '/usr/bin/google-chrome-stable', // executablePath: '/usr/bin/google-chrome-stable',
// executablePath: '/usr/bin/firefox-developer-edition', // executablePath: '/usr/bin/firefox-developer-edition',

View File

@ -83,7 +83,7 @@
"worker": "$ctrl.worker" "worker": "$ctrl.worker"
} }
}, { }, {
"url": "/time-control", "url": "/time-control?timestamp",
"state": "worker.card.timeControl", "state": "worker.card.timeControl",
"component": "vn-worker-time-control", "component": "vn-worker-time-control",
"description": "Time control", "description": "Time control",

View File

@ -91,6 +91,7 @@
</vn-label-value> </vn-label-value>
</div> </div>
<vn-calendar <vn-calendar
vn-id="calendar"
class="vn-pt-md" class="vn-pt-md"
ng-model="$ctrl.date" ng-model="$ctrl.date"
has-events="$ctrl.hasEvents($day)"> has-events="$ctrl.hasEvents($day)">

View File

@ -15,7 +15,15 @@ class Controller extends Section {
} }
$postLink() { $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() { get worker() {

View File

@ -129,5 +129,28 @@ describe('Component vnWorkerTimeControl', () => {
expect(controller.fetchHours).toHaveBeenCalledWith(); 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 timestamp = 1;
const date = new Date(timestamp);
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
controller.$.calendar = {};
controller.$params = {timestamp: timestamp};
controller.$postLink();
expect(controller.date.toDateString()).toEqual(date.toDateString());
});
});
}); });
}); });