diff options
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/header_spec.js | 8 | ||||
-rw-r--r-- | spec/javascripts/todos_spec.js | 51 |
2 files changed, 55 insertions, 4 deletions
diff --git a/spec/javascripts/header_spec.js b/spec/javascripts/header_spec.js index 0ddf589f368..c36d3be1b22 100644 --- a/spec/javascripts/header_spec.js +++ b/spec/javascripts/header_spec.js @@ -20,26 +20,26 @@ describe('Header', function() { }); it('should update todos-count after receiving the todo:toggle event', () => { - triggerToggle('5'); + triggerToggle(5); expect($(todosPendingCount).text()).toEqual('5'); }); it('should hide todos-count when it is 0', () => { - triggerToggle('0'); + triggerToggle(0); expect(isTodosCountHidden()).toEqual(true); }); it('should show todos-count when it is more than 0', () => { - triggerToggle('10'); + triggerToggle(10); expect(isTodosCountHidden()).toEqual(false); }); describe('when todos-count is 1000', () => { beforeEach(() => { - triggerToggle('1000'); + triggerToggle(1000); }); it('should show todos-count', () => { diff --git a/spec/javascripts/todos_spec.js b/spec/javascripts/todos_spec.js index 802f54f6a7e..dc3c547c632 100644 --- a/spec/javascripts/todos_spec.js +++ b/spec/javascripts/todos_spec.js @@ -1,18 +1,31 @@ import $ from 'jquery'; +import MockAdapter from 'axios-mock-adapter'; import Todos from '~/pages/dashboard/todos/index/todos'; import '~/lib/utils/common_utils'; +import '~/gl_dropdown'; +import axios from '~/lib/utils/axios_utils'; +import { addDelimiter } from '~/lib/utils/text_utility'; + +const TEST_COUNT_BIG = 2000; +const TEST_DONE_COUNT_BIG = 7300; describe('Todos', () => { preloadFixtures('todos/todos.html'); let todoItem; + let mock; beforeEach(() => { loadFixtures('todos/todos.html'); todoItem = document.querySelector('.todos-list .todo'); + mock = new MockAdapter(axios); return new Todos(); }); + afterEach(() => { + mock.restore(); + }); + describe('goToTodoUrl', () => { it('opens the todo url', done => { const todoLink = todoItem.dataset.url; @@ -53,5 +66,43 @@ describe('Todos', () => { expect(windowOpenSpy).not.toHaveBeenCalled(); }); }); + + describe('on done todo click', () => { + let onToggleSpy; + + beforeEach(done => { + const el = document.querySelector('.js-done-todo'); + const path = el.dataset.href; + + // Arrange + mock + .onDelete(path) + .replyOnce(200, { count: TEST_COUNT_BIG, done_count: TEST_DONE_COUNT_BIG }); + onToggleSpy = jasmine.createSpy('onToggle'); + $(document).on('todo:toggle', onToggleSpy); + + // Act + el.click(); + + // Wait for axios and HTML to udpate + setImmediate(done); + }); + + it('dispatches todo:toggle', () => { + expect(onToggleSpy).toHaveBeenCalledWith(jasmine.anything(), TEST_COUNT_BIG); + }); + + it('updates pending text', () => { + expect(document.querySelector('.todos-pending .badge').innerHTML).toEqual( + addDelimiter(TEST_COUNT_BIG), + ); + }); + + it('updates done text', () => { + expect(document.querySelector('.todos-done .badge').innerHTML).toEqual( + addDelimiter(TEST_DONE_COUNT_BIG), + ); + }); + }); }); }); |