2017-12-07 07:30:53 -05:00
|
|
|
import * as urlUtils from '~/lib/utils/url_utility';
|
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';
|
2017-02-09 17:19:12 -05:00
|
|
|
|
|
|
|
describe('Todos', () => {
|
|
|
|
preloadFixtures('todos/todos.html.raw');
|
|
|
|
let todoItem;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('todos/todos.html.raw');
|
|
|
|
todoItem = document.querySelector('.todos-list .todo');
|
|
|
|
|
2017-07-06 13:57:01 -04:00
|
|
|
return new Todos();
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('goToTodoUrl', () => {
|
|
|
|
it('opens the todo url', (done) => {
|
|
|
|
const todoLink = todoItem.dataset.url;
|
|
|
|
|
2017-12-07 07:30:53 -05:00
|
|
|
spyOn(urlUtils, '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 });
|
2017-12-07 07:30:53 -05:00
|
|
|
visitUrlSpy = spyOn(urlUtils, '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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|