Commit c5dead78 authored by Winnie Hellmann's avatar Winnie Hellmann

Make sure remaining time of scheduled jobs is positive in pipelines list

parent e8f14ef8
...@@ -26,7 +26,12 @@ export default { ...@@ -26,7 +26,12 @@ export default {
methods: { methods: {
onClickAction(action) { onClickAction(action) {
if (action.scheduled_at) { 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 // https://gitlab.com/gitlab-org/gitlab-ce/issues/52156
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
if (!window.confirm(confirmationMessage)) { if (!window.confirm(confirmationMessage)) {
...@@ -49,7 +54,7 @@ export default { ...@@ -49,7 +54,7 @@ export default {
remainingTime(action) { remainingTime(action) {
const remainingMilliseconds = new Date(action.scheduled_at).getTime() - Date.now(); const remainingMilliseconds = new Date(action.scheduled_at).getTime() - Date.now();
return formatTime(remainingMilliseconds); return formatTime(Math.max(0, remainingMilliseconds));
}, },
}, },
}; };
......
...@@ -47,11 +47,22 @@ describe('Pipelines Actions dropdown', () => { ...@@ -47,11 +47,22 @@ describe('Pipelines Actions dropdown', () => {
playable: true, playable: true,
scheduled_at: '2063-04-05T00:42:00Z', 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(() => { beforeEach(() => {
spyOn(Date, 'now').and.callFake(() => new Date('2063-04-04T00:42:00Z').getTime()); 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', () => { it('emits postAction event after confirming', () => {
...@@ -59,7 +70,7 @@ describe('Pipelines Actions dropdown', () => { ...@@ -59,7 +70,7 @@ describe('Pipelines Actions dropdown', () => {
eventHub.$on('postAction', emitSpy); eventHub.$on('postAction', emitSpy);
spyOn(window, 'confirm').and.callFake(() => true); spyOn(window, 'confirm').and.callFake(() => true);
findDropdownItem().click(); findDropdownItem(scheduledJobAction).click();
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
expect(emitSpy).toHaveBeenCalledWith(scheduledJobAction.path); expect(emitSpy).toHaveBeenCalledWith(scheduledJobAction.path);
...@@ -70,14 +81,18 @@ describe('Pipelines Actions dropdown', () => { ...@@ -70,14 +81,18 @@ describe('Pipelines Actions dropdown', () => {
eventHub.$on('postAction', emitSpy); eventHub.$on('postAction', emitSpy);
spyOn(window, 'confirm').and.callFake(() => false); spyOn(window, 'confirm').and.callFake(() => false);
findDropdownItem().click(); findDropdownItem(scheduledJobAction).click();
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
expect(emitSpy).not.toHaveBeenCalled(); expect(emitSpy).not.toHaveBeenCalled();
}); });
it('displays the remaining time in the dropdown', () => { 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');
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment