summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/unit/asrouter/asrouter-utils.test.js
blob: 1027b8ddabf5c6b91d8e5f0f39a9d8741084e8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { ASRouterUtils } from "content-src/asrouter/asrouter-utils";
import { GlobalOverrider } from "test/unit/utils";

describe("ASRouterUtils", () => {
  let globals = null;
  let overrider = null;
  let sandbox = null;
  beforeEach(() => {
    sandbox = sinon.createSandbox();
    globals = {
      ASRouterMessage: sandbox.stub().resolves({}),
    };
    overrider = new GlobalOverrider();
    overrider.set(globals);
  });
  afterEach(() => {
    sandbox.restore();
    overrider.restore();
  });
  describe("sendMessage", () => {
    it("default", () => {
      ASRouterUtils.sendMessage({ foo: "bar" });
      assert.calledOnce(globals.ASRouterMessage);
      assert.calledWith(globals.ASRouterMessage, { foo: "bar" });
    });
    it("throws if ASRouterMessage is not defined", () => {
      overrider.set("ASRouterMessage", undefined);
      assert.throws(() => ASRouterUtils.sendMessage({ foo: "bar" }));
    });
  });
  describe("blockById", () => {
    it("default", () => {
      ASRouterUtils.blockById(1, { foo: "bar" });
      assert.calledWith(
        globals.ASRouterMessage,
        sinon.match({ data: { foo: "bar", id: 1 } })
      );
    });
  });
  describe("modifyMessageJson", () => {
    it("default", () => {
      ASRouterUtils.modifyMessageJson({ foo: "bar" });
      assert.calledWith(
        globals.ASRouterMessage,
        sinon.match({ data: { content: { foo: "bar" } } })
      );
    });
  });
  describe("executeAction", () => {
    it("default", () => {
      ASRouterUtils.executeAction({ foo: "bar" });
      assert.calledWith(
        globals.ASRouterMessage,
        sinon.match({ data: { foo: "bar" } })
      );
    });
  });
  describe("unblockById", () => {
    it("default", () => {
      ASRouterUtils.unblockById(2);
      assert.calledWith(
        globals.ASRouterMessage,
        sinon.match({ data: { id: 2 } })
      );
    });
  });
  describe("blockBundle", () => {
    it("default", () => {
      ASRouterUtils.blockBundle(2);
      assert.calledWith(
        globals.ASRouterMessage,
        sinon.match({ data: { bundle: 2 } })
      );
    });
  });
  describe("unblockBundle", () => {
    it("default", () => {
      ASRouterUtils.unblockBundle(2);
      assert.calledWith(
        globals.ASRouterMessage,
        sinon.match({ data: { bundle: 2 } })
      );
    });
  });
  describe("overrideMessage", () => {
    it("default", () => {
      ASRouterUtils.overrideMessage(12);
      assert.calledWith(
        globals.ASRouterMessage,
        sinon.match({ data: { id: 12 } })
      );
    });
  });
  describe("sendTelemetry", () => {
    it("default", () => {
      ASRouterUtils.sendTelemetry({ foo: "bar" });
      assert.calledOnce(globals.ASRouterMessage);
    });
  });
});