DEV: introduces prettier for es6 files

This commit is contained in:
Joffrey JAFFEUX
2018-06-15 17:03:24 +02:00
committed by GitHub
parent c7ee70941e
commit 03a7d532cf
1162 changed files with 60667 additions and 29659 deletions

View File

@ -1,15 +1,12 @@
import DiscourseURL from "discourse/lib/url";
import ClickTrack from "discourse/lib/click-track";
var windowOpen,
win,
redirectTo;
var windowOpen, win, redirectTo;
QUnit.module("lib:click-track-profile-page", {
beforeEach() {
// Prevent any of these tests from navigating away
win = {focus: function() { } };
win = { focus: function() {} };
redirectTo = sandbox.stub(DiscourseURL, "redirectTo");
windowOpen = sandbox.stub(window, "open").returns(win);
sandbox.stub(win, "focus");
@ -38,7 +35,8 @@ QUnit.module("lib:click-track-profile-page", {
<a id="same-site" href="http://discuss.domain.com">forum</a>
<a class="attachment" href="http://discuss.domain.com/uploads/default/1234/1532357280.txt">log.txt</a>
<a class="hashtag" href="http://discuss.domain.com">#hashtag</a>
</p>`);
</p>`
);
}
});
@ -50,14 +48,14 @@ var generateClickEventOn = function(selector) {
};
QUnit.test("does not track clicks on lightboxes", assert => {
var clickEvent = generateClickEventOn('.lightbox');
var clickEvent = generateClickEventOn(".lightbox");
sandbox.stub(clickEvent, "preventDefault");
assert.ok(track(clickEvent));
assert.ok(!clickEvent.preventDefault.calledOnce);
});
QUnit.test("it calls preventDefault when clicking on an a", assert => {
var clickEvent = generateClickEventOn('a');
var clickEvent = generateClickEventOn("a");
sandbox.stub(clickEvent, "preventDefault");
track(clickEvent);
assert.ok(clickEvent.preventDefault.calledOnce);
@ -65,37 +63,37 @@ QUnit.test("it calls preventDefault when clicking on an a", assert => {
});
QUnit.test("does not track clicks when forcibly disabled", assert => {
assert.ok(track(generateClickEventOn('.no-track-link')));
assert.ok(track(generateClickEventOn(".no-track-link")));
});
QUnit.test("does not track clicks on back buttons", assert => {
assert.ok(track(generateClickEventOn('.back')));
assert.ok(track(generateClickEventOn(".back")));
});
QUnit.test("does not track clicks on category badges", assert => {
assert.ok(track(generateClickEventOn('.hashtag')));
assert.ok(track(generateClickEventOn(".hashtag")));
});
QUnit.test("removes the href and put it as a data attribute", assert => {
track(generateClickEventOn('a'));
track(generateClickEventOn("a"));
var $link = fixture('a').first();
assert.ok($link.hasClass('no-href'));
assert.equal($link.data('href'), 'http://www.google.com');
assert.blank($link.attr('href'));
assert.ok($link.data('auto-route'));
var $link = fixture("a").first();
assert.ok($link.hasClass("no-href"));
assert.equal($link.data("href"), "http://www.google.com");
assert.blank($link.attr("href"));
assert.ok($link.data("auto-route"));
assert.ok(DiscourseURL.redirectTo.calledOnce);
});
asyncTestDiscourse("restores the href after a while", function(assert) {
assert.expect(1);
track(generateClickEventOn('a'));
track(generateClickEventOn("a"));
const done = assert.async();
setTimeout(function() {
done();
assert.equal(fixture('a').attr('href'), "http://www.google.com");
assert.equal(fixture("a").attr("href"), "http://www.google.com");
}, 75);
});
@ -106,24 +104,39 @@ var trackRightClick = function(target) {
};
QUnit.test("right clicks change the href", assert => {
assert.ok(trackRightClick('a'));
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
assert.ok(trackRightClick("a"));
assert.equal(
fixture("a")
.first()
.prop("href"),
"http://www.google.com/"
);
});
QUnit.test("right clicks are tracked", assert => {
Discourse.SiteSettings.track_external_right_clicks = true;
trackRightClick('a');
assert.equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
trackRightClick("a");
assert.equal(
fixture(".first a")
.first()
.attr("href"),
"/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
);
});
QUnit.test("right clicks are tracked for second excerpt", assert => {
Discourse.SiteSettings.track_external_right_clicks = true;
trackRightClick('.second a');
assert.equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331");
trackRightClick(".second a");
assert.equal(
fixture(".second a")
.first()
.attr("href"),
"/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"
);
});
QUnit.test("preventDefault is not called for right clicks", assert => {
var clickEvent = generateClickEventOn('a');
var clickEvent = generateClickEventOn("a");
clickEvent.which = 3;
sandbox.stub(clickEvent, "preventDefault");
assert.ok(track(clickEvent));
@ -132,7 +145,7 @@ QUnit.test("preventDefault is not called for right clicks", assert => {
var testOpenInANewTab = function(description, clickEventModifier) {
test(description, function(assert) {
var clickEvent = generateClickEventOn('a');
var clickEvent = generateClickEventOn("a");
clickEventModifier(clickEvent);
sandbox.stub(clickEvent, "preventDefault");
assert.ok(track(clickEvent));
@ -140,19 +153,27 @@ var testOpenInANewTab = function(description, clickEventModifier) {
});
};
testOpenInANewTab("it opens in a new tab when pressing shift", function(clickEvent) {
testOpenInANewTab("it opens in a new tab when pressing shift", function(
clickEvent
) {
clickEvent.shiftKey = true;
});
testOpenInANewTab("it opens in a new tab when pressing meta", function(clickEvent) {
testOpenInANewTab("it opens in a new tab when pressing meta", function(
clickEvent
) {
clickEvent.metaKey = true;
});
testOpenInANewTab("it opens in a new tab when pressing ctrl", function(clickEvent) {
testOpenInANewTab("it opens in a new tab when pressing ctrl", function(
clickEvent
) {
clickEvent.ctrlKey = true;
});
testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent) {
testOpenInANewTab("it opens in a new tab on middle click", function(
clickEvent
) {
clickEvent.button = 2;
});
@ -160,7 +181,7 @@ QUnit.test("tracks via AJAX if we're on the same site", assert => {
sandbox.stub(DiscourseURL, "routeTo");
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
assert.ok(!track(generateClickEventOn('#same-site')));
assert.ok(!track(generateClickEventOn("#same-site")));
assert.ok(DiscourseURL.routeTo.calledOnce);
});
@ -168,32 +189,62 @@ QUnit.test("does not track via AJAX for attachments", assert => {
sandbox.stub(DiscourseURL, "routeTo");
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
assert.ok(!track(generateClickEventOn('.attachment')));
assert.ok(!track(generateClickEventOn(".attachment")));
assert.ok(DiscourseURL.redirectTo.calledOnce);
});
QUnit.test("tracks custom urls when opening in another window", assert => {
var clickEvent = generateClickEventOn('a');
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
var clickEvent = generateClickEventOn("a");
sandbox
.stub(Discourse.User, "currentProp")
.withArgs("external_links_in_new_tab")
.returns(true);
assert.ok(!track(clickEvent));
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
assert.ok(
windowOpen.calledWith(
"/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337",
"_blank"
)
);
});
QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => {
var clickEvent = generateClickEventOn('.second a');
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
assert.ok(!track(clickEvent));
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank'));
});
QUnit.test(
"tracks custom urls on second excerpt when opening in another window",
assert => {
var clickEvent = generateClickEventOn(".second a");
sandbox
.stub(Discourse.User, "currentProp")
.withArgs("external_links_in_new_tab")
.returns(true);
assert.ok(!track(clickEvent));
assert.ok(
windowOpen.calledWith(
"/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331",
"_blank"
)
);
}
);
QUnit.test("tracks custom urls when opening in another window", assert => {
var clickEvent = generateClickEventOn('a');
var clickEvent = generateClickEventOn("a");
assert.ok(!track(clickEvent));
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
assert.ok(
redirectTo.calledWith(
"/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
)
);
});
QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => {
var clickEvent = generateClickEventOn('.second a');
assert.ok(!track(clickEvent));
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331'));
});
QUnit.test(
"tracks custom urls on second excerpt when opening in another window",
assert => {
var clickEvent = generateClickEventOn(".second a");
assert.ok(!track(clickEvent));
assert.ok(
redirectTo.calledWith(
"/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"
)
);
}
);