aboutsummaryrefslogtreecommitdiff
path: root/test/content/usecases/SettingUseCaase.test.ts
blob: cf14e6e7a7d96ae74d22ebdce7866df95628dc22 (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
import SettingRepository from '../../../src/content/repositories/SettingRepository';
import SettingClient from '../../../src/content/client/SettingClient';
import SettingUseCase from '../../../src/content/usecases/SettingUseCase';
import Settings, { DefaultSetting } from '../../../src/shared/settings/Settings';
import { expect } from 'chai';

class MockSettingRepository implements SettingRepository {
  private current: Settings;

  constructor() {
    this.current = DefaultSetting;
  }

  set(settings: Settings): void {
    this.current= settings;
  }

  get(): Settings {
    return this.current;
  }
}

class MockSettingClient implements SettingClient {
  private data: Settings;

  constructor(data: Settings) {
    this.data = data;
  }

  load(): Promise<Settings> {
    return Promise.resolve(this.data);
  }
}

describe('AddonEnabledUseCase', () => {
  let repository: MockSettingRepository;
  let client: MockSettingClient;
  let sut: SettingUseCase;

  beforeEach(() => {
    const testSettings = {
      keymaps: {},
      search: {
        default: 'google',
        engines: {
          google: 'https://google.com/?q={}',
        }
      },
      properties: {
        hintchars: 'abcd1234',
        smoothscroll: false,
        complete: 'sbh',
      },
      blacklist: [],
    };

    repository = new MockSettingRepository();
    client = new MockSettingClient(testSettings);
    sut = new SettingUseCase(repository, client);
  });

  describe('#reload', () => {
    it('loads settings and store to repository', async() => {
      const settings = await sut.reload();
      expect(settings.properties.hintchars).to.equal('abcd1234');

      const saved = repository.get();
      expect(saved.properties.hintchars).to.equal('abcd1234');
    });
  });
});