Added specs for handleNotifications in mr_widget_options_spec.js
This commit is contained in:
parent
71d03e7e18
commit
870005c432
|
@ -39,4 +39,10 @@ function notifyMe(message, body, icon, onclick) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { notifyMe as default, notifyPermissions, notificationGranted };
|
const notify = {
|
||||||
|
notificationGranted,
|
||||||
|
notifyPermissions,
|
||||||
|
notifyMe,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default notify;
|
||||||
|
|
|
@ -41,4 +41,4 @@ export { default as getStateKey } from './stores/get_state_key';
|
||||||
export { default as mrWidgetOptions } from './mr_widget_options';
|
export { default as mrWidgetOptions } from './mr_widget_options';
|
||||||
export { default as stateMaps } from './stores/state_maps';
|
export { default as stateMaps } from './stores/state_maps';
|
||||||
export { default as SquashBeforeMerge } from './components/states/mr_widget_squash_before_merge';
|
export { default as SquashBeforeMerge } from './components/states/mr_widget_squash_before_merge';
|
||||||
export { default as notifyMe } from '../lib/utils/notify';
|
export { default as notify } from '../lib/utils/notify';
|
||||||
|
|
|
@ -29,7 +29,7 @@ import {
|
||||||
eventHub,
|
eventHub,
|
||||||
stateMaps,
|
stateMaps,
|
||||||
SquashBeforeMerge,
|
SquashBeforeMerge,
|
||||||
notifyMe,
|
notify,
|
||||||
} from './dependencies';
|
} from './dependencies';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -146,7 +146,7 @@ export default {
|
||||||
const title = `Pipeline ${label}`;
|
const title = `Pipeline ${label}`;
|
||||||
const message = `Pipeline ${label} for "${data.title}"`;
|
const message = `Pipeline ${label} for "${data.title}"`;
|
||||||
|
|
||||||
notifyMe(title, message, this.mr.gitlabLogo);
|
notify.notifyMe(title, message, this.mr.gitlabLogo);
|
||||||
},
|
},
|
||||||
resumePolling() {
|
resumePolling() {
|
||||||
this.pollingInterval.resume();
|
this.pollingInterval.resume();
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Vue from 'vue';
|
||||||
import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service';
|
import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service';
|
||||||
import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options';
|
import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options';
|
||||||
import eventHub from '~/vue_merge_request_widget/event_hub';
|
import eventHub from '~/vue_merge_request_widget/event_hub';
|
||||||
|
import notify from '~/lib/utils/notify';
|
||||||
import mockData from './mock_data';
|
import mockData from './mock_data';
|
||||||
|
|
||||||
const createComponent = () => {
|
const createComponent = () => {
|
||||||
|
@ -107,6 +108,8 @@ describe('mrWidgetOptions', () => {
|
||||||
it('should tell service to check status', (done) => {
|
it('should tell service to check status', (done) => {
|
||||||
spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData));
|
spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData));
|
||||||
spyOn(vm.mr, 'setData');
|
spyOn(vm.mr, 'setData');
|
||||||
|
spyOn(vm, 'handleNotification');
|
||||||
|
|
||||||
let isCbExecuted = false;
|
let isCbExecuted = false;
|
||||||
const cb = () => {
|
const cb = () => {
|
||||||
isCbExecuted = true;
|
isCbExecuted = true;
|
||||||
|
@ -117,6 +120,7 @@ describe('mrWidgetOptions', () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(vm.service.checkStatus).toHaveBeenCalled();
|
expect(vm.service.checkStatus).toHaveBeenCalled();
|
||||||
expect(vm.mr.setData).toHaveBeenCalled();
|
expect(vm.mr.setData).toHaveBeenCalled();
|
||||||
|
expect(vm.handleNotification).toHaveBeenCalledWith(mockData);
|
||||||
expect(isCbExecuted).toBeTruthy();
|
expect(isCbExecuted).toBeTruthy();
|
||||||
done();
|
done();
|
||||||
}, 333);
|
}, 333);
|
||||||
|
@ -254,6 +258,39 @@ describe('mrWidgetOptions', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('handleNotification', () => {
|
||||||
|
const data = {
|
||||||
|
ci_status: 'running',
|
||||||
|
title: 'title',
|
||||||
|
pipeline: { details: { status: { label: 'running-label' } } },
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(notify, 'notifyMe');
|
||||||
|
|
||||||
|
vm.mr.ciStatus = 'failed';
|
||||||
|
vm.mr.gitlabLogo = 'logo.png';
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call notifyMe', () => {
|
||||||
|
vm.handleNotification(data);
|
||||||
|
|
||||||
|
expect(notify.notifyMe).toHaveBeenCalledWith(
|
||||||
|
'Pipeline running-label',
|
||||||
|
'Pipeline running-label for "title"',
|
||||||
|
'logo.png',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call notifyMe if the status has not changed', () => {
|
||||||
|
vm.mr.ciStatus = data.ci_status;
|
||||||
|
|
||||||
|
vm.handleNotification(data);
|
||||||
|
|
||||||
|
expect(notify.notifyMe).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('resumePolling', () => {
|
describe('resumePolling', () => {
|
||||||
it('should call stopTimer on pollingInterval', () => {
|
it('should call stopTimer on pollingInterval', () => {
|
||||||
spyOn(vm.pollingInterval, 'resume');
|
spyOn(vm.pollingInterval, 'resume');
|
||||||
|
|
Loading…
Reference in New Issue