fixed todos spec

This commit is contained in:
Phil Hughes 2017-09-12 15:38:42 +01:00
parent 08362d80b8
commit 855c258fdb
No known key found for this signature in database
GPG Key ID: 32245528C52E0F9F
2 changed files with 14 additions and 27 deletions

View File

@ -138,22 +138,17 @@ export default class Todos {
goToTodoUrl(e) {
const todoLink = this.dataset.url;
if (!todoLink) {
if (!todoLink || e.target.tagName === 'A' || e.target.tagName === 'IMG') {
return;
}
e.stopPropagation();
e.preventDefault();
if (isMetaClick(e)) {
const windowTarget = '_blank';
const selected = e.target;
e.stopPropagation();
e.preventDefault();
if (selected.tagName === 'IMG') {
const avatarUrl = selected.parentElement.getAttribute('href');
window.open(avatarUrl, windowTarget);
} else {
window.open(todoLink, windowTarget);
}
window.open(todoLink, windowTarget);
} else {
gl.utils.visitUrl(todoLink);
}

View File

@ -26,38 +26,30 @@ describe('Todos', () => {
describe('meta click', () => {
let visitUrlSpy;
let windowOpenSpy;
let metakeyEvent;
beforeEach(() => {
metakeyEvent = $.Event('click', { keyCode: 91, ctrlKey: true });
visitUrlSpy = spyOn(gl.utils, 'visitUrl').and.callFake(() => {});
windowOpenSpy = spyOn(window, 'open').and.callFake(() => {});
});
it('opens the todo url in another tab', (done) => {
it('opens the todo url in another tab', () => {
const todoLink = todoItem.dataset.url;
spyOn(window, 'open').and.callFake((url, target) => {
expect(todoLink).toEqual(url);
expect(target).toEqual('_blank');
done();
});
$('.todos-list .todo').trigger(metakeyEvent);
expect(visitUrlSpy).not.toHaveBeenCalled();
expect(windowOpenSpy).toHaveBeenCalledWith(todoLink, '_blank');
});
it('opens the avatar\'s url in another tab when the avatar is clicked', (done) => {
const avatarImage = todoItem.querySelector('img');
const avatarUrl = avatarImage.parentElement.getAttribute('href');
it('run native funcionality when avatar is clicked', () => {
$('.todos-list a').on('click', e => e.preventDefault());
$('.todos-list img').trigger(metakeyEvent);
spyOn(window, 'open').and.callFake((url, target) => {
expect(avatarUrl).toEqual(url);
expect(target).toEqual('_blank');
done();
});
avatarImage.click();
expect(visitUrlSpy).not.toHaveBeenCalled();
expect(windowOpenSpy).not.toHaveBeenCalled();
});
});
});