aboutsummaryrefslogtreecommitdiff
path: root/test/background/operators/impls/ReloadTabOperator.test.ts
blob: 0cedf3e5e0d44ef703fd77d73186aa81db691467 (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
import ReloadTabOperator from "../../../../src/background/operators/impls/ReloadTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";

describe("ReloadTabOperator", () => {
  describe("#run", () => {
    it("reloads the current tab with cache", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/", { active: true });
      await tabPresenter.create("https://example.com/", { active: false });
      const reloadSpy = jest
        .spyOn(tabPresenter, "reload")
        .mockReturnValue(Promise.resolve());

      const sut = new ReloadTabOperator(tabPresenter, true);
      await sut.run();

      expect(reloadSpy).toBeCalledWith(0, true);
    });

    it("reloads the current tab without cache", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/", { active: true });
      await tabPresenter.create("https://example.com/", { active: false });
      const reloadSpy = jest
        .spyOn(tabPresenter, "reload")
        .mockReturnValue(Promise.resolve());

      const sut = new ReloadTabOperator(tabPresenter, false);
      await sut.run();

      expect(reloadSpy).toBeCalledWith(0, false);
    });
  });
});