diff options
Diffstat (limited to 'spec/frontend/boards/board_blank_state_spec.js')
-rw-r--r-- | spec/frontend/boards/board_blank_state_spec.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/frontend/boards/board_blank_state_spec.js b/spec/frontend/boards/board_blank_state_spec.js new file mode 100644 index 00000000000..3ffdda52f58 --- /dev/null +++ b/spec/frontend/boards/board_blank_state_spec.js @@ -0,0 +1,95 @@ +import Vue from 'vue'; +import boardsStore from '~/boards/stores/boards_store'; +import BoardBlankState from '~/boards/components/board_blank_state.vue'; + +describe('Boards blank state', () => { + let vm; + let fail = false; + + beforeEach(done => { + const Comp = Vue.extend(BoardBlankState); + + boardsStore.create(); + + jest.spyOn(boardsStore, 'addList').mockImplementation(); + jest.spyOn(boardsStore, 'removeList').mockImplementation(); + jest.spyOn(boardsStore, 'generateDefaultLists').mockImplementation( + () => + 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 }, + }, + ], + }); + } + }), + ); + + vm = new Comp(); + + setImmediate(() => { + vm.$mount(); + done(); + }); + }); + + it('renders pre-defined labels', () => { + expect(vm.$el.querySelectorAll('.board-blank-state-list li').length).toBe(2); + + expect(vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim()).toEqual( + 'To Do', + ); + + expect(vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim()).toEqual( + 'Doing', + ); + }); + + it('clears blank state', done => { + vm.$el.querySelector('.btn-default').click(); + + setImmediate(() => { + expect(boardsStore.welcomeIsHidden()).toBeTruthy(); + + done(); + }); + }); + + it('creates pre-defined labels', done => { + vm.$el.querySelector('.btn-success').click(); + + setImmediate(() => { + expect(boardsStore.addList).toHaveBeenCalledTimes(2); + expect(boardsStore.addList).toHaveBeenCalledWith(expect.objectContaining({ title: 'To Do' })); + + expect(boardsStore.addList).toHaveBeenCalledWith(expect.objectContaining({ title: 'Doing' })); + + done(); + }); + }); + + it('resets the store if request fails', done => { + fail = true; + + vm.$el.querySelector('.btn-success').click(); + + setImmediate(() => { + expect(boardsStore.welcomeIsHidden()).toBeFalsy(); + expect(boardsStore.removeList).toHaveBeenCalledWith(undefined, 'label'); + + done(); + }); + }); +}); |