mirror of
https://github.com/discourse/discourse.git
synced 2025-01-06 12:15:56 +08:00
176aa0ac7d
* DEV: Remove server global test variable * Delete yarn-error.log * prettier and some eslint fixes * add global server variable back for plugins * rename imported server to pretender * prettier * support plugin server. usage * Export pretender as named * Prettier * change default pretender export * fix bad import * Use pretender() and original default export * export new Pretender as default * fix accidental change * WIP testing * add pretend handlers in correct location * move more stuff into the correct pretender * Consolidated more pretenders * comment out another bad test * fix user acceptance tests * commented out bad test * fixed another composer server stub * fix more tests * fixed tag test pretender * Fix admin email test * removed another draft handler * add back test * fix and uncomment another test * remove test that is not useful * remove commented out lines * reapply handlers between every test * no need to re-stub requests now :) * cleanup from review * more cleanup
96 lines
3.4 KiB
JavaScript
96 lines
3.4 KiB
JavaScript
import DiscourseURL from "discourse/lib/url";
|
|
import ClickTrack from "discourse/lib/click-track";
|
|
import { fixture, logIn } from "helpers/qunit-helpers";
|
|
import pretender from "helpers/create-pretender";
|
|
|
|
QUnit.module("lib:click-track-profile-page", {
|
|
beforeEach() {
|
|
logIn();
|
|
|
|
let win = { focus: function() {} };
|
|
sandbox.stub(window, "open").returns(win);
|
|
sandbox.stub(win, "focus");
|
|
|
|
sandbox.stub(DiscourseURL, "routeTo");
|
|
sandbox.stub(DiscourseURL, "redirectTo");
|
|
|
|
sessionStorage.clear();
|
|
|
|
fixture().html(
|
|
`<p class="excerpt first" data-post-id="42" data-topic-id="1337" data-user-id="3141">
|
|
<a href="http://www.google.com">google.com</a>
|
|
<a class="lightbox back" href="http://www.google.com">google.com</a>
|
|
<div class="onebox-result">
|
|
<a id="inside-onebox" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
|
<a id="inside-onebox-forced" class="track-link" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
|
</div>
|
|
<a class="no-track-link" href="http://www.google.com">google.com</a>
|
|
<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 class="excerpt second" data-post-id="24" data-topic-id="7331" data-user-id="1413">
|
|
<a href="http://www.google.com">google.com</a>
|
|
<a class="lightbox back" href="http://www.google.com">google.com</a>
|
|
<div class="onebox-result">
|
|
<a id="inside-onebox" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
|
<a id="inside-onebox-forced" class="track-link" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
|
</div>
|
|
<a class="no-track-link" href="http://www.google.com">google.com</a>
|
|
<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>`
|
|
);
|
|
}
|
|
});
|
|
|
|
var track = ClickTrack.trackClick;
|
|
|
|
function generateClickEventOn(selector) {
|
|
return $.Event("click", { currentTarget: fixture(selector).first() });
|
|
}
|
|
|
|
QUnit.skip("tracks internal URLs", async assert => {
|
|
assert.expect(2);
|
|
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
|
|
|
const done = assert.async();
|
|
pretender.post("/clicks/track", request => {
|
|
assert.equal(request.requestBody, "url=http%3A%2F%2Fdiscuss.domain.com");
|
|
done();
|
|
});
|
|
|
|
assert.notOk(track(generateClickEventOn("#same-site")));
|
|
});
|
|
|
|
QUnit.skip("tracks external URLs", async assert => {
|
|
assert.expect(2);
|
|
|
|
const done = assert.async();
|
|
pretender.post("/clicks/track", request => {
|
|
assert.equal(
|
|
request.requestBody,
|
|
"url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
|
|
);
|
|
done();
|
|
});
|
|
|
|
assert.notOk(track(generateClickEventOn("a")));
|
|
});
|
|
|
|
QUnit.skip("tracks external URLs in other posts", async assert => {
|
|
assert.expect(2);
|
|
|
|
const done = assert.async();
|
|
pretender.post("/clicks/track", request => {
|
|
assert.equal(
|
|
request.requestBody,
|
|
"url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"
|
|
);
|
|
done();
|
|
});
|
|
|
|
assert.notOk(track(generateClickEventOn(".second a")));
|
|
});
|