debian-mirror-gitlab/spec/frontend/boards/board_blank_state_spec.js

96 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2018-12-13 13:39:08 +05:30
import boardsStore from '~/boards/stores/boards_store';
2018-10-15 14:42:47 +05:30
import BoardBlankState from '~/boards/components/board_blank_state.vue';
2017-08-17 22:00:37 +05:30
describe('Boards blank state', () => {
let vm;
let fail = false;
2018-12-13 13:39:08 +05:30
beforeEach(done => {
2018-10-15 14:42:47 +05:30
const Comp = Vue.extend(BoardBlankState);
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
boardsStore.create();
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
jest.spyOn(boardsStore, 'addList').mockImplementation();
jest.spyOn(boardsStore, 'removeList').mockImplementation();
jest.spyOn(boardsStore, 'generateDefaultLists').mockImplementation(
2018-12-13 13:39:08 +05:30
() =>
new Promise((resolve, reject) => {
if (fail) {
reject();
} else {
resolve({
data: [
{
id: 1,
title: 'To Do',
label: { id: 1 },
},
{
id: 2,
title: 'Doing',
label: { id: 2 },
},
],
});
}
}),
);
2017-08-17 22:00:37 +05:30
vm = new Comp();
2020-04-22 19:07:51 +05:30
setImmediate(() => {
2017-08-17 22:00:37 +05:30
vm.$mount();
done();
});
});
it('renders pre-defined labels', () => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelectorAll('.board-blank-state-list li').length).toBe(2);
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim()).toEqual(
'To Do',
);
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim()).toEqual(
'Doing',
);
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
it('clears blank state', done => {
2017-08-17 22:00:37 +05:30
vm.$el.querySelector('.btn-default').click();
2020-04-22 19:07:51 +05:30
setImmediate(() => {
2018-12-13 13:39:08 +05:30
expect(boardsStore.welcomeIsHidden()).toBeTruthy();
2017-08-17 22:00:37 +05:30
done();
});
});
2018-12-13 13:39:08 +05:30
it('creates pre-defined labels', done => {
2018-12-05 23:21:45 +05:30
vm.$el.querySelector('.btn-success').click();
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
setImmediate(() => {
2019-10-12 21:52:04 +05:30
expect(boardsStore.addList).toHaveBeenCalledTimes(2);
2020-04-22 19:07:51 +05:30
expect(boardsStore.addList).toHaveBeenCalledWith(expect.objectContaining({ title: 'To Do' }));
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
expect(boardsStore.addList).toHaveBeenCalledWith(expect.objectContaining({ title: 'Doing' }));
2017-08-17 22:00:37 +05:30
done();
});
});
2018-12-13 13:39:08 +05:30
it('resets the store if request fails', done => {
2017-08-17 22:00:37 +05:30
fail = true;
2018-12-05 23:21:45 +05:30
vm.$el.querySelector('.btn-success').click();
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
setImmediate(() => {
2018-12-13 13:39:08 +05:30
expect(boardsStore.welcomeIsHidden()).toBeFalsy();
2019-10-12 21:52:04 +05:30
expect(boardsStore.removeList).toHaveBeenCalledWith(undefined, 'label');
2017-08-17 22:00:37 +05:30
done();
});
});
});