2016-05-02 23:43:58 +08:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
|
|
|
import ClickTrack from "discourse/lib/click-track";
|
2019-06-06 19:10:41 +08:00
|
|
|
import { fixture, logIn } from "helpers/qunit-helpers";
|
2016-05-02 23:43:58 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("lib:click-track-profile-page", {
|
|
|
|
beforeEach() {
|
2019-04-23 17:41:36 +08:00
|
|
|
logIn();
|
|
|
|
|
|
|
|
let win = { focus: function() {} };
|
|
|
|
sandbox.stub(window, "open").returns(win);
|
2016-05-02 23:43:58 +08:00
|
|
|
sandbox.stub(win, "focus");
|
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
sandbox.stub(DiscourseURL, "routeTo");
|
|
|
|
sandbox.stub(DiscourseURL, "redirectTo");
|
|
|
|
|
|
|
|
sessionStorage.clear();
|
|
|
|
|
2016-05-02 23:43:58 +08:00
|
|
|
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>
|
2017-10-07 03:14:08 +08:00
|
|
|
<a class="lightbox back" href="http://www.google.com">google.com</a>
|
2016-05-02 23:43:58 +08:00
|
|
|
<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>
|
2017-10-07 03:14:08 +08:00
|
|
|
<a class="lightbox back" href="http://www.google.com">google.com</a>
|
2016-05-02 23:43:58 +08:00
|
|
|
<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>
|
2018-06-15 23:03:24 +08:00
|
|
|
</p>`
|
|
|
|
);
|
2016-05-02 23:43:58 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var track = ClickTrack.trackClick;
|
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
function generateClickEventOn(selector) {
|
|
|
|
return $.Event("click", { currentTarget: fixture(selector).first() });
|
|
|
|
}
|
2016-05-02 23:43:58 +08:00
|
|
|
|
2019-07-02 16:08:28 +08:00
|
|
|
QUnit.skip("tracks internal URLs", async assert => {
|
2019-04-23 17:41:36 +08:00
|
|
|
assert.expect(2);
|
|
|
|
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
2016-05-02 23:43:58 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
const done = assert.async();
|
2019-04-23 17:41:36 +08:00
|
|
|
/* global server */
|
2019-05-07 18:53:45 +08:00
|
|
|
server.post("/clicks/track", request => {
|
|
|
|
assert.equal(request.requestBody, "url=http%3A%2F%2Fdiscuss.domain.com");
|
2017-06-15 01:57:58 +08:00
|
|
|
done();
|
2016-05-02 23:43:58 +08:00
|
|
|
});
|
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
assert.notOk(track(generateClickEventOn("#same-site")));
|
2016-05-02 23:43:58 +08:00
|
|
|
});
|
|
|
|
|
2019-07-02 16:08:28 +08:00
|
|
|
QUnit.skip("tracks external URLs", async assert => {
|
2019-04-23 17:41:36 +08:00
|
|
|
assert.expect(2);
|
2016-05-02 23:43:58 +08:00
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
const done = assert.async();
|
|
|
|
/* global server */
|
2019-05-07 18:53:45 +08:00
|
|
|
server.post("/clicks/track", request => {
|
|
|
|
assert.equal(
|
|
|
|
request.requestBody,
|
|
|
|
"url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
|
2019-04-23 17:41:36 +08:00
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-02 23:43:58 +08:00
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
assert.notOk(track(generateClickEventOn("a")));
|
2016-05-02 23:43:58 +08:00
|
|
|
});
|
|
|
|
|
2019-07-02 16:08:28 +08:00
|
|
|
QUnit.skip("tracks external URLs in other posts", async assert => {
|
2019-04-23 17:41:36 +08:00
|
|
|
assert.expect(2);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
const done = assert.async();
|
|
|
|
/* global server */
|
2019-05-07 18:53:45 +08:00
|
|
|
server.post("/clicks/track", request => {
|
|
|
|
assert.equal(
|
|
|
|
request.requestBody,
|
|
|
|
"url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2019-04-23 17:41:36 +08:00
|
|
|
done();
|
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
assert.notOk(track(generateClickEventOn(".second a")));
|
|
|
|
});
|