tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

addUtmParams.test.js (1617B)


      1 import { addUtmParams, BASE_PARAMS } from "content-src/lib/addUtmParams.mjs";
      2 
      3 describe("addUtmParams", () => {
      4  const originalBaseParams = JSON.parse(JSON.stringify(BASE_PARAMS));
      5  afterEach(() => Object.assign(BASE_PARAMS, originalBaseParams));
      6  it("should convert a string URL", () => {
      7    const result = addUtmParams("https://foo.com", "foo");
      8    assert.equal(result.hostname, "foo.com");
      9  });
     10  it("should add all base params", () => {
     11    assert.match(
     12      addUtmParams(new URL("https://foo.com"), "foo").toString(),
     13      /utm_source=activity-stream&utm_campaign=firstrun&utm_medium=referral/
     14    );
     15  });
     16  it("should allow updating base params utm values", () => {
     17    BASE_PARAMS.utm_campaign = "firstrun-default";
     18    assert.match(
     19      addUtmParams(new URL("https://foo.com"), "foo", "default").toString(),
     20      /utm_source=activity-stream&utm_campaign=firstrun-default&utm_medium=referral/
     21    );
     22  });
     23  it("should add utm_term", () => {
     24    const params = addUtmParams(new URL("https://foo.com"), "foo").searchParams;
     25    assert.equal(params.get("utm_term"), "foo", "utm_term");
     26  });
     27  it("should not override the URL's existing utm param values", () => {
     28    const url = new URL(
     29      "https://foo.com/?utm_source=foo&utm_campaign=bar&utm_term=baz"
     30    );
     31    const params = addUtmParams(url, "foo").searchParams;
     32    assert.equal(params.get("utm_source"), "foo", "utm_source");
     33    assert.equal(params.get("utm_campaign"), "bar", "utm_campaign");
     34    assert.equal(params.get("utm_term"), "baz", "utm_term");
     35    assert.equal(params.get("utm_medium"), "referral", "utm_medium");
     36  });
     37 });