summaryrefslogtreecommitdiffstats
path: root/browser/components/syncedtabs/test/xpcshell/test_SyncedTabsDeckStore.js
blob: 69abb402457bd26d4e68045efac0435ff49a1f30 (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
"use strict";

let { SyncedTabsDeckStore } = Cu.import("resource:///modules/syncedtabs/SyncedTabsDeckStore.js", {});

add_task(function* testSelectUnkownPanel() {
  let deckStore = new SyncedTabsDeckStore();
  let spy = sinon.spy();

  deckStore.on("change", spy);
  deckStore.selectPanel("foo");

  Assert.ok(!spy.called);
});

add_task(function* testSetPanels() {
  let deckStore = new SyncedTabsDeckStore();
  let spy = sinon.spy();

  deckStore.on("change", spy);
  deckStore.setPanels(["panel1", "panel2"]);

  Assert.ok(spy.calledWith({
    panels: [
      { id: "panel1", selected: false },
      { id: "panel2", selected: false },
    ],
    isUpdatable: false
  }));
});

add_task(function* testSelectPanel() {
  let deckStore = new SyncedTabsDeckStore();
  let spy = sinon.spy();

  deckStore.setPanels(["panel1", "panel2"]);

  deckStore.on("change", spy);
  deckStore.selectPanel("panel2");

  Assert.ok(spy.calledWith({
    panels: [
      { id: "panel1", selected: false },
      { id: "panel2", selected: true },
    ],
    isUpdatable: true
  }));

  deckStore.selectPanel("panel2");
  Assert.ok(spy.calledOnce, "doesn't trigger unless panel changes");
});

add_task(function* testSetPanelsSameArray() {
  let deckStore = new SyncedTabsDeckStore();
  let spy = sinon.spy();
  deckStore.on("change", spy);

  let panels = ["panel1", "panel2"];

  deckStore.setPanels(panels);
  deckStore.setPanels(panels);

  Assert.ok(spy.calledOnce, "doesn't trigger unless set of panels changes");
});