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

91 lines
2.1 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-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;
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-09-06 02:49:19 -04:00
gl.boardService = mockBoardService();
2017-03-16 10:11:02 -04:00
spyOn(gl.boardService, 'generateDefaultLists').and.callFake(() => new Promise((resolve, reject) => {
if (fail) {
reject();
} else {
resolve({
2017-12-15 03:31:14 -05:00
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', () => {
expect(
2017-03-16 11:15:51 -04:00
vm.$el.querySelectorAll('.board-blank-state-list li').length,
2017-03-16 10:11:02 -04:00
).toBe(2);
expect(
2017-03-16 11:15:51 -04:00
vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim(),
2017-03-16 10:11:02 -04:00
).toEqual('To Do');
expect(
2017-03-16 11:15:51 -04:00
vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim(),
2017-03-16 10:11:02 -04:00
).toEqual('Doing');
});
it('clears blank state', (done) => {
vm.$el.querySelector('.btn-default').click();
setTimeout(() => {
expect(boardsStore.welcomeIsHidden()).toBeTruthy();
2017-03-16 10:11:02 -04:00
done();
});
});
it('creates pre-defined labels', (done) => {
vm.$el.querySelector('.btn-success').click();
2017-03-16 10:11:02 -04:00
setTimeout(() => {
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();
});
});
it('resets the store if request fails', (done) => {
fail = true;
vm.$el.querySelector('.btn-success').click();
2017-03-16 10:11:02 -04:00
setTimeout(() => {
expect(boardsStore.welcomeIsHidden()).toBeFalsy();
expect(boardsStore.state.lists.length).toBe(1);
2017-03-16 10:11:02 -04:00
done();
});
});
});