2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2019-09-18 14:06:14 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2018-01-08 16:55:28 -05:00
|
|
|
import Todos from '~/pages/dashboard/todos/index/todos';
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/lib/utils/common_utils';
|
2019-09-18 14:06:14 -04:00
|
|
|
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;
|
2017-02-09 17:19:12 -05:00
|
|
|
|
|
|
|
describe('Todos', () => {
|
2019-03-26 12:03:28 -04:00
|
|
|
preloadFixtures('todos/todos.html');
|
2017-02-09 17:19:12 -05:00
|
|
|
let todoItem;
|
2019-09-18 14:06:14 -04:00
|
|
|
let mock;
|
2017-02-09 17:19:12 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('todos/todos.html');
|
2017-02-09 17:19:12 -05:00
|
|
|
todoItem = document.querySelector('.todos-list .todo');
|
2019-09-18 14:06:14 -04:00
|
|
|
mock = new MockAdapter(axios);
|
2017-02-09 17:19:12 -05:00
|
|
|
|
2017-07-06 13:57:01 -04:00
|
|
|
return new Todos();
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
|
2019-09-18 14:06:14 -04:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2017-02-09 17:19:12 -05:00
|
|
|
describe('goToTodoUrl', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
it('opens the todo url', done => {
|
2017-02-09 17:19:12 -05:00
|
|
|
const todoLink = todoItem.dataset.url;
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
spyOnDependency(Todos, 'visitUrl').and.callFake(url => {
|
2017-02-09 17:19:12 -05:00
|
|
|
expect(url).toEqual(todoLink);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
todoItem.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('meta click', () => {
|
|
|
|
let visitUrlSpy;
|
2017-09-12 10:38:42 -04:00
|
|
|
let windowOpenSpy;
|
2017-09-06 12:14:34 -04:00
|
|
|
let metakeyEvent;
|
2017-02-09 17:19:12 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-09-06 12:14:34 -04:00
|
|
|
metakeyEvent = $.Event('click', { keyCode: 91, ctrlKey: true });
|
2018-04-13 23:49:11 -04:00
|
|
|
visitUrlSpy = spyOnDependency(Todos, 'visitUrl').and.callFake(() => {});
|
2017-09-12 10:38:42 -04:00
|
|
|
windowOpenSpy = spyOn(window, 'open').and.callFake(() => {});
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
|
2017-09-12 10:38:42 -04:00
|
|
|
it('opens the todo url in another tab', () => {
|
2017-02-09 17:19:12 -05:00
|
|
|
const todoLink = todoItem.dataset.url;
|
|
|
|
|
2017-09-06 12:14:34 -04:00
|
|
|
$('.todos-list .todo').trigger(metakeyEvent);
|
2017-09-12 10:38:42 -04:00
|
|
|
|
2017-02-09 17:19:12 -05:00
|
|
|
expect(visitUrlSpy).not.toHaveBeenCalled();
|
2017-09-12 10:38:42 -04:00
|
|
|
expect(windowOpenSpy).toHaveBeenCalledWith(todoLink, '_blank');
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
|
2017-09-12 10:38:42 -04:00
|
|
|
it('run native funcionality when avatar is clicked', () => {
|
|
|
|
$('.todos-list a').on('click', e => e.preventDefault());
|
|
|
|
$('.todos-list img').trigger(metakeyEvent);
|
2017-02-09 17:19:12 -05:00
|
|
|
|
|
|
|
expect(visitUrlSpy).not.toHaveBeenCalled();
|
2017-09-12 10:38:42 -04:00
|
|
|
expect(windowOpenSpy).not.toHaveBeenCalled();
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
});
|
2019-09-18 14:06:14 -04:00
|
|
|
|
|
|
|
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),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
});
|