Skip to content

A platform for community discussion. Free, open, simple.

DEV: Make click-track exclusion tests assert tracking

Régis Hanol661d93fc8014
diff --git a/frontend/discourse/tests/unit/lib/click-track-test.js b/frontend/discourse/tests/unit/lib/click-track-test.js
index 1febedc7d2a..c75caaa5ca6 100644
--- a/frontend/discourse/tests/unit/lib/click-track-test.js
+++ b/frontend/discourse/tests/unit/lib/click-track-test.js
@@ -49,7 +49,8 @@ module("Unit | Utility | click-track", function (hooks) {
fixture().innerHTML = `<div id="topic" data-topic-id="1337">
<article data-post-id="42" data-user-id="3141">
<a href="http://www.google.com">google.com</a>
- <a class="lightbox back" href="http://www.google.fr">google.fr</a>
+ <a class="lightbox" href="http://www.google.fr">google.fr</a>
+ <a class="back" href="http://www.google.fr">google.fr</a>
<a id="with-badge" data-user-id="314" href="http://www.google.de">google.de<span class="badge">1</span></a>
<a id="with-badge-but-not-mine" href="http://www.google.es">google.es<span class="badge">1</span></a>
<div class="onebox-result">
@@ -227,16 +228,26 @@ module("Unit | Utility | click-track", function (hooks) {
assert.true(track(generateClickEventOn("#svg-link-blank")));
});
- test("does not track clicks on lightboxes", async function (assert) {
- assert.false(track(generateClickEventOn(".lightbox")));
- });
+ test("does not track clicks on excluded links", async function (assert) {
+ pretender.post("/clicks/track", () => {
+ assert.step("tracked");
+ return [200, {}, ""];
+ });
- test("does not track clicks when forcibly disabled", async function (assert) {
- assert.false(track(generateClickEventOn(".no-track-link")));
- });
+ for (const selector of [
+ ".lightbox",
+ ".no-track-link",
+ ".back",
+ ".hashtag",
+ ".hashtag-cooked",
+ ".quote a:last-child",
+ ]) {
+ await track(generateClickEventOn(selector), null, {
+ returnPromise: true,
+ });
+ }
- test("does not track clicks on back buttons", async function (assert) {
- assert.false(track(generateClickEventOn(".back")));
+ assert.verifySteps([]);
});
test("does not track right clicks inside quotes", async function (assert) {
@@ -245,17 +256,6 @@ module("Unit | Utility | click-track", function (hooks) {
assert.true(track(event));
});
- test("does not track clicks links in quotes", async function (assert) {
- User.currentProp("user_option.external_links_in_new_tab", true);
- assert.false(track(generateClickEventOn(".quote a:last-child")));
- assert.true(window.open.calledWith("https://google.com/", "_blank"));
- });
-
- test("does not track clicks on hashtags for categories and tags", async function (assert) {
- assert.false(track(generateClickEventOn(".hashtag")));
- assert.false(track(generateClickEventOn(".hashtag-cooked")));
- });
-
test("returns true for tracking mentions and group mentions so the card can appear", async function (assert) {
assert.true(track(generateClickEventOn(".mention")));
assert.true(track(generateClickEventOn(".mention-group")));
@@ -342,6 +342,6 @@ module("Unit | Utility | click-track", function (hooks) {
);
testOpenInANewTab("it opens in a new tab on middle click", (clickEvent) => {
- sinon.stub(clickEvent, "button").get(() => 2);
+ sinon.stub(clickEvent, "button").get(() => 1);
});
});