2017-03-16 10:11:02 -04:00
|
|
|
import Vue from 'vue';
|
2018-10-10 13:08:43 -04:00
|
|
|
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-12-15 03:31:14 -05:00
|
|
|
import { mockBoardService } from './mock_data';
|
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
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
boardsStore.create();
|
2017-09-06 02:49:19 -04:00
|
|
|
gl.boardService = mockBoardService();
|
2017-03-16 10:11:02 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
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-03-16 10:11:02 -04:00
|
|
|
|
|
|
|
vm = new Comp();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
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();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-10-10 13:08:43 -04:00
|
|
|
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 => {
|
2018-09-18 05:58:22 -04:00
|
|
|
vm.$el.querySelector('.btn-success').click();
|
2017-03-16 10:11:02 -04:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-10-10 13:08:43 -04:00
|
|
|
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-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;
|
|
|
|
|
2018-09-18 05:58:22 -04:00
|
|
|
vm.$el.querySelector('.btn-success').click();
|
2017-03-16 10:11:02 -04:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-10-10 13:08:43 -04:00
|
|
|
expect(boardsStore.welcomeIsHidden()).toBeFalsy();
|
|
|
|
expect(boardsStore.state.lists.length).toBe(1);
|
2017-03-16 10:11:02 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|