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

describe("NavigateParentOperator", () => {
  describe("#run", () => {
    it("opens a parent directory of the file in the URL", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/fruits/yellow/banana", {
        active: true,
      });
      const sut = new NavigateParentOperator(tabPresenter);

      await sut.run();

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

    it("opens a parent directory of the directoryin the URL", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/fruits/yellow/");
      const sut = new NavigateParentOperator(tabPresenter);

      await sut.run();

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

    it("removes a hash in the URL", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/fruits/yellow/#top");
      const sut = new NavigateParentOperator(tabPresenter);

      await sut.run();

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

    it("removes query parameters in the URL", async () => {
      const tabPresenter = new MockTabPresenter();
      await tabPresenter.create("https://example.com/search?q=apple");
      const sut = new NavigateParentOperator(tabPresenter);

      await sut.run();

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