aboutsummaryrefslogtreecommitdiff
path: root/test/content
diff options
context:
space:
mode:
Diffstat (limited to 'test/content')
-rw-r--r--test/content/actions/setting.test.ts43
-rw-r--r--test/content/reducers/setting.test.ts31
-rw-r--r--test/content/repositories/SettingRepository.test.ts30
-rw-r--r--test/content/usecases/SettingUseCaase.test.ts71
4 files changed, 101 insertions, 74 deletions
diff --git a/test/content/actions/setting.test.ts b/test/content/actions/setting.test.ts
deleted file mode 100644
index c831433..0000000
--- a/test/content/actions/setting.test.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import * as actions from 'content/actions';
-import * as settingActions from 'content/actions/setting';
-
-describe("setting actions", () => {
- describe("set", () => {
- it('create SETTING_SET action', () => {
- let action = settingActions.set({
- keymaps: {
- 'dd': 'remove current tab',
- 'z<C-A>': 'increment',
- },
- search: {
- default: "google",
- engines: {
- google: 'https://google.com/search?q={}',
- }
- },
- properties: {
- hintchars: 'abcd1234',
- },
- blacklist: [],
- });
- expect(action.type).to.equal(actions.SETTING_SET);
- expect(action.settings.properties.hintchars).to.equal('abcd1234');
- });
-
- it('overrides cancel keys', () => {
- let action = settingActions.set({
- keymaps: {
- "k": { "type": "scroll.vertically", "count": -1 },
- "j": { "type": "scroll.vertically", "count": 1 },
- }
- });
- let keymaps = action.settings.keymaps;
- expect(action.settings.keymaps).to.deep.equals({
- "k": { type: "scroll.vertically", count: -1 },
- "j": { type: "scroll.vertically", count: 1 },
- '<Esc>': { type: 'cancel' },
- '<C-[>': { type: 'cancel' },
- });
- });
- });
-});
diff --git a/test/content/reducers/setting.test.ts b/test/content/reducers/setting.test.ts
deleted file mode 100644
index 9b332aa..0000000
--- a/test/content/reducers/setting.test.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import * as actions from 'content/actions';
-import settingReducer from 'content/reducers/setting';
-
-describe("content setting reducer", () => {
- it('return the initial state', () => {
- let state = settingReducer(undefined, {});
- expect(state.keymaps).to.be.empty;
- });
-
- it('return next state for SETTING_SET', () => {
- let newSettings = { red: 'apple', yellow: 'banana' };
- let action = {
- type: actions.SETTING_SET,
- settings: {
- keymaps: {
- "zz": { type: "zoom.neutral" },
- "<S-Esc>": { "type": "addon.toggle.enabled" }
- },
- "blacklist": []
- }
- }
- let state = settingReducer(undefined, action);
- expect(state.keymaps).to.have.deep.all.members([
- { key: [{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false },
- { key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }],
- op: { type: 'zoom.neutral' }},
- { key: [{ key: 'Esc', shiftKey: true, ctrlKey: false, altKey: false, metaKey: false }],
- op: { type: 'addon.toggle.enabled' }},
- ]);
- });
-});
diff --git a/test/content/repositories/SettingRepository.test.ts b/test/content/repositories/SettingRepository.test.ts
new file mode 100644
index 0000000..fea70b7
--- /dev/null
+++ b/test/content/repositories/SettingRepository.test.ts
@@ -0,0 +1,30 @@
+import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
+import { expect } from 'chai';
+
+describe('SettingRepositoryImpl', () => {
+ it('updates and gets current value', () => {
+ let sut = new SettingRepositoryImpl();
+
+ let settings = {
+ keymaps: {},
+ search: {
+ default: 'google',
+ engines: {
+ google: 'https://google.com/?q={}',
+ }
+ },
+ properties: {
+ hintchars: 'abcd1234',
+ smoothscroll: false,
+ complete: 'sbh',
+ },
+ blacklist: [],
+ }
+
+ sut.set(settings);
+
+ let actual = sut.get();
+ expect(actual.properties.hintchars).to.equal('abcd1234');
+ });
+});
+
diff --git a/test/content/usecases/SettingUseCaase.test.ts b/test/content/usecases/SettingUseCaase.test.ts
new file mode 100644
index 0000000..02cef78
--- /dev/null
+++ b/test/content/usecases/SettingUseCaase.test.ts
@@ -0,0 +1,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';
+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(() => {
+ let 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() => {
+ let settings = await sut.reload();
+ expect(settings.properties.hintchars).to.equal('abcd1234');
+
+ let saved = repository.get();
+ expect(saved.properties.hintchars).to.equal('abcd1234');
+ });
+ });
+});