gitlab-org--gitlab-foss/spec/frontend/boards/board_blank_state_spec.js

96 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-03-16 10:11:02 -04:00
import Vue from 'vue';
import boardsStore from '~/boards/stores/boards_store';
2018-03-09 10:01:14 -05:00
import BoardBlankState from '~/boards/components/board_blank_state.vue';
2017-03-16 10:11:02 -04:00
describe('Boards blank state', () => {
let vm;
let fail = false;
2018-10-17 03:13:26 -04:00
beforeEach(done => {
2018-03-09 10:01:14 -05:00
const Comp = Vue.extend(BoardBlankState);
2017-03-16 10:11:02 -04:00
boardsStore.create();
2017-03-16 10:11:02 -04:00
jest.spyOn(boardsStore, 'addList').mockImplementation();
jest.spyOn(boardsStore, 'removeList').mockImplementation();
jest.spyOn(boardsStore, 'generateDefaultLists').mockImplementation(
2018-10-17 03:13:26 -04:00
() =>
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-03-16 10:11:02 -04:00
vm = new Comp();
setImmediate(() => {
2017-03-16 10:11:02 -04:00
vm.$mount();
done();
});
});
it('renders pre-defined labels', () => {
2018-10-17 03:13:26 -04:00
expect(vm.$el.querySelectorAll('.board-blank-state-list li').length).toBe(2);
2017-03-16 10:11:02 -04:00
2018-10-17 03:13:26 -04:00
expect(vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim()).toEqual(
'To Do',
);
2017-03-16 10:11:02 -04:00
2018-10-17 03:13:26 -04:00
expect(vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim()).toEqual(
'Doing',
);
2017-03-16 10:11:02 -04:00
});
2018-10-17 03:13:26 -04:00
it('clears blank state', done => {
2017-03-16 10:11:02 -04:00
vm.$el.querySelector('.btn-default').click();
setImmediate(() => {
expect(boardsStore.welcomeIsHidden()).toBeTruthy();
2017-03-16 10:11:02 -04:00
done();
});
});
2018-10-17 03:13:26 -04:00
it('creates pre-defined labels', done => {
vm.$el.querySelector('.btn-success').click();
2017-03-16 10:11:02 -04:00
setImmediate(() => {
expect(boardsStore.addList).toHaveBeenCalledTimes(2);
expect(boardsStore.addList).toHaveBeenCalledWith(expect.objectContaining({ title: 'To Do' }));
expect(boardsStore.addList).toHaveBeenCalledWith(expect.objectContaining({ title: 'Doing' }));
2017-03-16 10:11:02 -04:00
done();
});
});
2018-10-17 03:13:26 -04:00
it('resets the store if request fails', done => {
2017-03-16 10:11:02 -04:00
fail = true;
vm.$el.querySelector('.btn-success').click();
2017-03-16 10:11:02 -04:00
setImmediate(() => {
expect(boardsStore.welcomeIsHidden()).toBeFalsy();
expect(boardsStore.removeList).toHaveBeenCalledWith(undefined, 'label');
2017-03-16 10:11:02 -04:00
done();
});
});
});