mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 17:33:38 +08:00
Upgrade QUnit to latest version
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
@ -6,8 +5,8 @@ var windowOpen,
|
||||
win,
|
||||
redirectTo;
|
||||
|
||||
module("lib:click-track-profile-page", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:click-track-profile-page", {
|
||||
beforeEach() {
|
||||
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
@ -50,56 +49,57 @@ var generateClickEventOn = function(selector) {
|
||||
return $.Event("click", { currentTarget: fixture(selector)[0] });
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
QUnit.test("does not track clicks on lightboxes", assert => {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
test("it calls preventDefault when clicking on an a", function() {
|
||||
QUnit.test("it calls preventDefault when clicking on an a", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks when forcibly disabled", function() {
|
||||
ok(track(generateClickEventOn('.no-track-link')));
|
||||
QUnit.test("does not track clicks when forcibly disabled", assert => {
|
||||
assert.ok(track(generateClickEventOn('.no-track-link')));
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
QUnit.test("does not track clicks on back buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
QUnit.test("does not track clicks on quote buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("does not track clicks on category badges", () => {
|
||||
ok(track(generateClickEventOn('.hashtag')));
|
||||
QUnit.test("does not track clicks on category badges", assert => {
|
||||
assert.ok(track(generateClickEventOn('.hashtag')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
QUnit.test("removes the href and put it as a data attribute", assert => {
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
var $link = fixture('a').first();
|
||||
ok($link.hasClass('no-href'));
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
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() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("restores the href after a while", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
const done = assert.async();
|
||||
setTimeout(function() {
|
||||
start();
|
||||
equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
done();
|
||||
assert.equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
}, 75);
|
||||
});
|
||||
|
||||
@ -109,38 +109,38 @@ var trackRightClick = function(target) {
|
||||
return track(clickEvent);
|
||||
};
|
||||
|
||||
test("right clicks change the href", function() {
|
||||
ok(trackRightClick('a'));
|
||||
equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
QUnit.test("right clicks change the href", assert => {
|
||||
assert.ok(trackRightClick('a'));
|
||||
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
});
|
||||
|
||||
test("right clicks are tracked", function() {
|
||||
QUnit.test("right clicks are tracked", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('a');
|
||||
equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
assert.equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
});
|
||||
|
||||
test("right clicks are tracked for second excerpt", function() {
|
||||
QUnit.test("right clicks are tracked for second excerpt", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('.second a');
|
||||
equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331");
|
||||
assert.equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331");
|
||||
});
|
||||
|
||||
test("preventDefault is not called for right clicks", function() {
|
||||
QUnit.test("preventDefault is not called for right clicks", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||
test(description, function() {
|
||||
test(description, function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEventModifier(clickEvent);
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
};
|
||||
|
||||
@ -160,44 +160,44 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
||||
clickEvent.button = 2;
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
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");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('#same-site')));
|
||||
assert.ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
QUnit.test("does not track via AJAX for attachments", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('.attachment')));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
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);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls on second excerpt when opening in another window", function() {
|
||||
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);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
});
|
||||
|
||||
test("tracks custom urls on second excerpt when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('.second a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331'));
|
||||
});
|
||||
|
Reference in New Issue
Block a user