aboutsummaryrefslogtreecommitdiff
path: root/test/background/operators/impls/CloseTabOperator.test.ts
blob: f72e118346d2be7e7258795d3d212f892b622b18 (plain) (blame)
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
import CloseTabOperator from "../../../../src/background/operators/impls/CloseTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";

describe("CloseTabOperator", () => {
  describe("#run", () => {
    it("close a current tab", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/1", { active: false });
      await tabPresenter.create("https://example.com/2", { active: true });
      await tabPresenter.create("https://example.com/3", { active: false });
      const sut = new CloseTabOperator(tabPresenter);

      await sut.run();

      const tabs = await tabPresenter.getAll();
      expect(tabs.map((t) => t.url)).toEqual([
        "https://example.com/1",
        "https://example.com/3",
      ]);
    });

    it("close a current tab forcely", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/1", {
        pinned: true,
        active: false,
      });
      await tabPresenter.create("https://example.com/2", {
        pinned: true,
        active: true,
      });
      await tabPresenter.create("https://example.com/3", {
        pinned: true,
        active: false,
      });
      const sut = new CloseTabOperator(tabPresenter, true);

      await sut.run();

      const tabs = await tabPresenter.getAll();
      expect(tabs.map((t) => t.url)).toEqual([
        "https://example.com/1",
        "https://example.com/3",
      ]);
    });

    it("close a current tab and select left of the closed tab", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/1", { active: false });
      await tabPresenter.create("https://example.com/2", { active: true });
      await tabPresenter.create("https://example.com/3", { active: false });
      const sut = new CloseTabOperator(tabPresenter, false, true);

      await sut.run();

      const tab = await tabPresenter.getCurrent();
      expect(tab.url).toEqual("https://example.com/1");
    });
  });
});