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( `
google.com forum log.txt #hashtag google.com forum log.txt #hashtag ` ); } }); 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"))); });