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

100 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
2019-10-12 21:52:04 +05:30
spyOn(boardsStore, 'addList').and.stub();
spyOn(boardsStore, 'removeList').and.stub();
spyOn(boardsStore, 'generateDefaultLists').and.callFake(
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();
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(() => {
2019-10-12 21:52:04 +05:30
expect(boardsStore.addList).toHaveBeenCalledTimes(2);
expect(boardsStore.addList).toHaveBeenCalledWith(
jasmine.objectContaining({ title: 'To Do' }),
);
expect(boardsStore.addList).toHaveBeenCalledWith(
jasmine.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
setTimeout(() => {
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();
});
});
});