aboutsummaryrefslogtreecommitdiff
path: root/test/background/operators/impls/NavigateParentOperator.test.ts
blob: cc57f1791e6ada91772ce2083d83e267f673e476 (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
import { expect } from "chai";
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).to.be.equal("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).to.be.equal("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).to.be.equal("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).to.be.equal("https://example.com/search");
    });
  });
});