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';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { mockBoardService } from './mock_data';
|
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();
|
2018-03-17 18:26:18 +05:30
|
|
|
gl.boardService = mockBoardService();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
spyOn(gl.boardService, 'generateDefaultLists').and.callFake(
|
|
|
|
() =>
|
|
|
|
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();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
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();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
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
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.state.lists.length).toBe(2);
|
|
|
|
expect(boardsStore.state.lists[0].title).toEqual('To Do');
|
|
|
|
expect(boardsStore.state.lists[1].title).toEqual('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
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(boardsStore.welcomeIsHidden()).toBeFalsy();
|
|
|
|
expect(boardsStore.state.lists.length).toBe(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|