diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-10-05 09:34:08 +0200 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2018-10-05 09:34:31 +0200 |
commit | c5dead78558e552801205bf6e0a9b78f1e88711d (patch) | |
tree | 50c154441209bbbc71aa69f4fe9f8b2e78dde496 | |
parent | e8f14ef8859c2b6f870090666331f538702c40b9 (diff) | |
download | gitlab-ce-c5dead78558e552801205bf6e0a9b78f1e88711d.tar.gz |
Make sure remaining time of scheduled jobs is positive in pipelines list
-rw-r--r-- | app/assets/javascripts/pipelines/components/pipelines_actions.vue | 9 | ||||
-rw-r--r-- | spec/javascripts/pipelines/pipelines_actions_spec.js | 25 |
2 files changed, 27 insertions, 7 deletions
diff --git a/app/assets/javascripts/pipelines/components/pipelines_actions.vue b/app/assets/javascripts/pipelines/components/pipelines_actions.vue index 743d241ee7a..16e69759091 100644 --- a/app/assets/javascripts/pipelines/components/pipelines_actions.vue +++ b/app/assets/javascripts/pipelines/components/pipelines_actions.vue @@ -26,7 +26,12 @@ export default { methods: { onClickAction(action) { if (action.scheduled_at) { - const confirmationMessage = sprintf(s__("DelayedJobs|Are you sure you want to run %{jobName} immediately? This job will run automatically after it's timer finishes."), { jobName: action.name }); + const confirmationMessage = sprintf( + s__( + "DelayedJobs|Are you sure you want to run %{jobName} immediately? This job will run automatically after it's timer finishes.", + ), + { jobName: action.name }, + ); // https://gitlab.com/gitlab-org/gitlab-ce/issues/52156 // eslint-disable-next-line no-alert if (!window.confirm(confirmationMessage)) { @@ -49,7 +54,7 @@ export default { remainingTime(action) { const remainingMilliseconds = new Date(action.scheduled_at).getTime() - Date.now(); - return formatTime(remainingMilliseconds); + return formatTime(Math.max(0, remainingMilliseconds)); }, }, }; diff --git a/spec/javascripts/pipelines/pipelines_actions_spec.js b/spec/javascripts/pipelines/pipelines_actions_spec.js index fe60a883f77..0566bc55693 100644 --- a/spec/javascripts/pipelines/pipelines_actions_spec.js +++ b/spec/javascripts/pipelines/pipelines_actions_spec.js @@ -47,11 +47,22 @@ describe('Pipelines Actions dropdown', () => { playable: true, scheduled_at: '2063-04-05T00:42:00Z', }; - const findDropdownItem = () => vm.$el.querySelector('.dropdown-menu li button'); + const expiredJobAction = { + name: 'expired action', + path: `${TEST_HOST}/expired/job/action`, + playable: true, + scheduled_at: '2018-10-05T08:23:00Z', + }; + const findDropdownItem = action => { + const buttons = vm.$el.querySelectorAll('.dropdown-menu li button'); + return Array.prototype.find.call(buttons, element => + element.innerText.trim().startsWith(action.name), + ); + }; beforeEach(() => { spyOn(Date, 'now').and.callFake(() => new Date('2063-04-04T00:42:00Z').getTime()); - vm = mountComponent(Component, { actions: [scheduledJobAction] }); + vm = mountComponent(Component, { actions: [scheduledJobAction, expiredJobAction] }); }); it('emits postAction event after confirming', () => { @@ -59,7 +70,7 @@ describe('Pipelines Actions dropdown', () => { eventHub.$on('postAction', emitSpy); spyOn(window, 'confirm').and.callFake(() => true); - findDropdownItem().click(); + findDropdownItem(scheduledJobAction).click(); expect(window.confirm).toHaveBeenCalled(); expect(emitSpy).toHaveBeenCalledWith(scheduledJobAction.path); @@ -70,14 +81,18 @@ describe('Pipelines Actions dropdown', () => { eventHub.$on('postAction', emitSpy); spyOn(window, 'confirm').and.callFake(() => false); - findDropdownItem().click(); + findDropdownItem(scheduledJobAction).click(); expect(window.confirm).toHaveBeenCalled(); expect(emitSpy).not.toHaveBeenCalled(); }); it('displays the remaining time in the dropdown', () => { - expect(findDropdownItem()).toContainText('24:00:00'); + expect(findDropdownItem(scheduledJobAction)).toContainText('24:00:00'); + }); + + it('displays 00:00:00 for expired jobs in the dropdown', () => { + expect(findDropdownItem(expiredJobAction)).toContainText('00:00:00'); }); }); }); |