Fix regression where cmd-click stopped working for todos and merge request tabs

This commit is contained in:
Clement Ho 2017-02-09 16:19:12 -06:00
parent 059f47b6ba
commit 25fec0f882
5 changed files with 112 additions and 18 deletions

View file

@ -102,9 +102,10 @@ require('./flash');
}
clickTab(e) {
if (e.target && gl.utils.isMetaClick(e)) {
const targetLink = e.target.getAttribute('href');
if (e.currentTarget && gl.utils.isMetaClick(e)) {
const targetLink = e.currentTarget.getAttribute('href');
e.stopImmediatePropagation();
e.preventDefault();
window.open(targetLink, '_blank');
}
}

View file

@ -147,24 +147,21 @@
goToTodoUrl(e) {
const todoLink = this.dataset.url;
let targetLink = e.target.getAttribute('href');
if (e.target.tagName === 'IMG') { // See if clicked target was Avatar
targetLink = e.target.parentElement.getAttribute('href'); // Parent of Avatar is link
}
if (!todoLink) {
return;
}
if (gl.utils.isMetaClick(e)) {
const windowTarget = '_blank';
const selected = e.target;
e.preventDefault();
// Meta-Click on username leads to different URL than todoLink.
// Turbolinks can resolve that URL, but window.open requires URL manually.
if (targetLink !== todoLink) {
return window.open(targetLink, '_blank');
if (selected.tagName === 'IMG') {
const avatarUrl = selected.parentElement.getAttribute('href');
return window.open(avatarUrl, windowTarget);
} else {
return window.open(todoLink, '_blank');
return window.open(todoLink, windowTarget);
}
} else {
return gl.utils.visitUrl(todoLink);

View file

@ -0,0 +1,5 @@
---
title: Fix regression where cmd-click stopped working for todos and merge request
tabs
merge_request:
author:

View file

@ -62,19 +62,47 @@ require('vendor/jquery.scrollTo');
});
});
describe('#opensInNewTab', function () {
var commitsLink;
var tabUrl;
var windowTarget = '_blank';
beforeEach(function () {
commitsLink = '.commits-tab li a';
tabUrl = $(commitsLink).attr('href');
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
tabUrl = $('.commits-tab a').attr('href');
spyOn($.fn, 'attr').and.returnValue(tabUrl);
});
describe('meta click', () => {
beforeEach(function () {
spyOn(gl.utils, 'isMetaClick').and.returnValue(true);
});
it('opens page when commits link is clicked', function () {
spyOn(window, 'open').and.callFake(function (url, name) {
expect(url).toEqual(tabUrl);
expect(name).toEqual(windowTarget);
});
this.class.bindEvents();
document.querySelector('.merge-request-tabs .commits-tab a').click();
});
it('opens page when commits badge is clicked', function () {
spyOn(window, 'open').and.callFake(function (url, name) {
expect(url).toEqual(tabUrl);
expect(name).toEqual(windowTarget);
});
this.class.bindEvents();
document.querySelector('.merge-request-tabs .commits-tab a .badge').click();
});
});
it('opens page tab in a new browser tab with Ctrl+Click - Windows/Linux', function () {
spyOn(window, 'open').and.callFake(function (url, name) {
expect(url).toEqual(tabUrl);
expect(name).toEqual('_blank');
expect(name).toEqual(windowTarget);
});
this.class.clickTab({
@ -87,7 +115,7 @@ require('vendor/jquery.scrollTo');
it('opens page tab in a new browser tab with Cmd+Click - Mac', function () {
spyOn(window, 'open').and.callFake(function (url, name) {
expect(url).toEqual(tabUrl);
expect(name).toEqual('_blank');
expect(name).toEqual(windowTarget);
});
this.class.clickTab({
@ -100,7 +128,7 @@ require('vendor/jquery.scrollTo');
it('opens page tab in a new browser tab with Middle-click - Mac/PC', function () {
spyOn(window, 'open').and.callFake(function (url, name) {
expect(url).toEqual(tabUrl);
expect(name).toEqual('_blank');
expect(name).toEqual(windowTarget);
});
this.class.clickTab({

View file

@ -0,0 +1,63 @@
require('~/todos');
require('~/lib/utils/common_utils');
describe('Todos', () => {
preloadFixtures('todos/todos.html.raw');
let todoItem;
beforeEach(() => {
loadFixtures('todos/todos.html.raw');
todoItem = document.querySelector('.todos-list .todo');
return new gl.Todos();
});
describe('goToTodoUrl', () => {
it('opens the todo url', (done) => {
const todoLink = todoItem.dataset.url;
spyOn(gl.utils, 'visitUrl').and.callFake((url) => {
expect(url).toEqual(todoLink);
done();
});
todoItem.click();
});
describe('meta click', () => {
let visitUrlSpy;
beforeEach(() => {
spyOn(gl.utils, 'isMetaClick').and.returnValue(true);
visitUrlSpy = spyOn(gl.utils, 'visitUrl').and.callFake(() => {});
});
it('opens the todo url in another tab', (done) => {
const todoLink = todoItem.dataset.url;
spyOn(window, 'open').and.callFake((url, target) => {
expect(todoLink).toEqual(url);
expect(target).toEqual('_blank');
done();
});
todoItem.click();
expect(visitUrlSpy).not.toHaveBeenCalled();
});
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');
spyOn(window, 'open').and.callFake((url, target) => {
expect(avatarUrl).toEqual(url);
expect(target).toEqual('_blank');
done();
});
avatarImage.click();
expect(visitUrlSpy).not.toHaveBeenCalled();
});
});
});
});