summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/unit/lib/SystemTickFeed.test.js
blob: 3b9ee14f817e6a0bc195105768a9716268aea84b (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
import { SYSTEM_TICK_INTERVAL, SystemTickFeed } from "lib/SystemTickFeed.jsm";
import { actionTypes as at } from "common/Actions.sys.mjs";

describe("System Tick Feed", () => {
  let instance;
  let clock;

  beforeEach(() => {
    clock = sinon.useFakeTimers();

    instance = new SystemTickFeed();
    instance.store = {
      getState() {
        return {};
      },
      dispatch() {},
    };
  });
  afterEach(() => {
    clock.restore();
  });
  it("should create a SystemTickFeed", () => {
    assert.instanceOf(instance, SystemTickFeed);
  });
  it("should fire SYSTEM_TICK events at configured interval", () => {
    let expectation = sinon
      .mock(instance.store)
      .expects("dispatch")
      .twice()
      .withExactArgs({ type: at.SYSTEM_TICK });

    instance.onAction({ type: at.INIT });
    clock.tick(SYSTEM_TICK_INTERVAL * 2);
    expectation.verify();
  });
  it("should not fire SYSTEM_TICK events after UNINIT", () => {
    let expectation = sinon
      .mock(instance.store)
      .expects("dispatch")
      .never();

    instance.onAction({ type: at.UNINIT });
    clock.tick(SYSTEM_TICK_INTERVAL * 2);
    expectation.verify();
  });
});