aboutsummaryrefslogtreecommitdiff
path: root/test/background/usecases/NavigateUseCase.test.ts
blob: 48a1c5b433c32635b987df3a1649baff062fe25f (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import TabPresenter from '../../../src/background/presenters/TabPresenter';
import NavigateUseCase from '../../../src/background/usecases/NavigateUseCase';
import NavigateClient from '../../../src/background/clients/NavigateClient';
// import { expect } from 'chai';
import * as sinon from 'sinon';

describe('NavigateUseCase', () => {
  let sut: NavigateUseCase;
  let tabPresenter: TabPresenter;
  let navigateClient: NavigateClient;
  beforeEach(() => {
    tabPresenter = new TabPresenter();
    navigateClient = new NavigateClient();
    sut = new NavigateUseCase(tabPresenter, navigateClient);
  });

  describe('#openParent()', async () => {
    it('opens parent directory of file', async() => {
      const stub = sinon.stub(tabPresenter, 'getCurrent');
      stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/banana' }))

      const mock = sinon.mock(tabPresenter);
      mock.expects('open').withArgs('https://google.com/fruits/yellow/');

      await sut.openParent();

      mock.verify();
    });

    it('opens parent directory of directory', async() => {
      const stub = sinon.stub(tabPresenter, 'getCurrent');
      stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/' }))

      const mock = sinon.mock(tabPresenter);
      mock.expects('open').withArgs('https://google.com/fruits/');

      await sut.openParent();

      mock.verify();
    });

    it('removes hash', async() => {
      const stub = sinon.stub(tabPresenter, 'getCurrent');
      stub.returns(Promise.resolve({ url: 'https://google.com/#top' }))

      const mock = sinon.mock(tabPresenter);
      mock.expects('open').withArgs('https://google.com/');

      await sut.openParent();

      mock.verify();
    });

    it('removes search query', async() => {
      const stub = sinon.stub(tabPresenter, 'getCurrent');
      stub.returns(Promise.resolve({ url: 'https://google.com/search?q=apple' }))

      const mock = sinon.mock(tabPresenter);
      mock.expects('open').withArgs('https://google.com/search');

      await sut.openParent();

      mock.verify();
    });
  });

  describe('#openRoot()', () => {
    it('opens root direectory', async() => {
      const stub = sinon.stub(tabPresenter, 'getCurrent');
      stub.returns(Promise.resolve({
        url: 'https://google.com/seach?q=apple',
      }))

      const mock = sinon.mock(tabPresenter);
      mock.expects('open').withArgs('https://google.com');

      await sut.openRoot();

      mock.verify();
    });
  });
});