From 37410b874f89de4907ba038244318129835e8157 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 4 Mar 2018 17:57:56 +0900 Subject: [PATCH 1/3] add hide action for console --- src/console/actions/console.js | 8 +++++++- src/console/actions/index.js | 1 + src/console/index.js | 2 ++ src/console/reducers/index.js | 4 ++++ test/console/actions/console.test.js | 6 ++++++ test/console/reducers/console.test.js | 6 ++++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/console/actions/console.js b/src/console/actions/console.js index 2cf8e8d..f80045f 100644 --- a/src/console/actions/console.js +++ b/src/console/actions/console.js @@ -1,5 +1,11 @@ import actions from 'console/actions'; +const hide = () => { + return { + type: actions.CONSOLE_HIDE, + }; +}; + const showCommand = (text) => { return { type: actions.CONSOLE_SHOW_COMMAND, @@ -61,6 +67,6 @@ const completionPrev = () => { }; export { - showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, + hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, setCompletions, completionNext, completionPrev }; diff --git a/src/console/actions/index.js b/src/console/actions/index.js index a85e329..b394179 100644 --- a/src/console/actions/index.js +++ b/src/console/actions/index.js @@ -1,5 +1,6 @@ export default { // console commands + CONSOLE_HIDE: 'console.hide', CONSOLE_SHOW_COMMAND: 'console.show.command', CONSOLE_SHOW_ERROR: 'console.show.error', CONSOLE_SHOW_INFO: 'console.show.info', diff --git a/src/console/index.js b/src/console/index.js index 86edd9a..156456c 100644 --- a/src/console/index.js +++ b/src/console/index.js @@ -24,6 +24,8 @@ const onMessage = (message) => { return store.dispatch(consoleActions.showError(message.text)); case messages.CONSOLE_SHOW_INFO: return store.dispatch(consoleActions.showInfo(message.text)); + case messages.CONSOLE_HIDE: + return store.dispatch(consoleActions.hide()); } }; diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js index 60c0007..2aec55c 100644 --- a/src/console/reducers/index.js +++ b/src/console/reducers/index.js @@ -53,6 +53,10 @@ const nextConsoleText = (completions, group, item, defaults) => { export default function reducer(state = defaultState, action = {}) { switch (action.type) { + case actions.CONSOLE_HIDE: + return Object.assign({}, state, { + mode: '', + }); case actions.CONSOLE_SHOW_COMMAND: return Object.assign({}, state, { mode: 'command', diff --git a/test/console/actions/console.test.js b/test/console/actions/console.test.js index 9af13d4..1774431 100644 --- a/test/console/actions/console.test.js +++ b/test/console/actions/console.test.js @@ -3,6 +3,12 @@ import actions from 'console/actions'; import * as consoleActions from 'console/actions/console'; describe("console actions", () => { + describe('hide', () => { + it('create CONSOLE_HIDE action', () => { + let action = consoleActions.hide(); + expect(action.type).to.equal(actions.CONSOLE_HIDE); + }); + }); describe("showCommand", () => { it('create CONSOLE_SHOW_COMMAND action', () => { let action = consoleActions.showCommand('hello'); diff --git a/test/console/reducers/console.test.js b/test/console/reducers/console.test.js index 438d513..d196011 100644 --- a/test/console/reducers/console.test.js +++ b/test/console/reducers/console.test.js @@ -13,6 +13,12 @@ describe("console reducer", () => { expect(state).to.have.property('itemSelection', -1); }); + it('return next state for CONSOLE_HIDE', () => { + let action = { type: actions.CONSOLE_HIDE }; + let state = reducer({ mode: 'error' }, action); + expect(state).to.have.property('mode', ''); + }) + it('return next state for CONSOLE_SHOW_COMMAND', () => { let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; let state = reducer({}, action); From 90b83d7b7b99598834466c97e9c74c82cbd25cf3 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 4 Mar 2018 18:32:24 +0900 Subject: [PATCH 2/3] hide console on and --- src/background/actions/operation.js | 4 ++++ src/content/actions/setting.js | 9 ++++++++- src/shared/messages.js | 1 + src/shared/operations.js | 3 +++ test/background/reducers/setting.test.js | 1 - test/content/actions/setting.test.js | 2 ++ 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/background/actions/operation.js b/src/background/actions/operation.js index 1188ea2..56eb168 100644 --- a/src/background/actions/operation.js +++ b/src/background/actions/operation.js @@ -73,6 +73,10 @@ const exec = (operation, tab) => { return browser.tabs.sendMessage(tab.id, { type: messages.CONSOLE_SHOW_FIND }); + case operations.CANCEL: + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_HIDE, + }); default: return Promise.resolve(); } diff --git a/src/content/actions/setting.js b/src/content/actions/setting.js index 0238c71..4c1e385 100644 --- a/src/content/actions/setting.js +++ b/src/content/actions/setting.js @@ -1,10 +1,17 @@ import actions from 'content/actions'; import * as keyUtils from 'shared/utils/keys'; +import operations from 'shared/operations'; + +const reservedKeymaps = { + '': { type: operations.CANCEL }, + '': { type: operations.CANCEL }, +}; const set = (value) => { let entries = []; if (value.keymaps) { - entries = Object.entries(value.keymaps).map((entry) => { + let keymaps = Object.assign({}, value.keymaps, reservedKeymaps); + entries = Object.entries(keymaps).map((entry) => { return [ keyUtils.fromMapKeys(entry[0]), entry[1], diff --git a/src/shared/messages.js b/src/shared/messages.js index de00a3f..b7a1a7e 100644 --- a/src/shared/messages.js +++ b/src/shared/messages.js @@ -32,6 +32,7 @@ export default { CONSOLE_SHOW_ERROR: 'console.show.error', CONSOLE_SHOW_INFO: 'console.show.info', CONSOLE_SHOW_FIND: 'console.show.find', + CONSOLE_HIDE: 'console.hide', FOLLOW_START: 'follow.start', FOLLOW_REQUEST_COUNT_TARGETS: 'follow.request.count.targets', diff --git a/src/shared/operations.js b/src/shared/operations.js index 008e9eb..a2f980f 100644 --- a/src/shared/operations.js +++ b/src/shared/operations.js @@ -1,4 +1,7 @@ export default { + // Hide console, or cancel some user actions + CANCEL: 'cancel', + // Addons ADDON_ENABLE: 'addon.enable', ADDON_DISABLE: 'addon.disable', diff --git a/test/background/reducers/setting.test.js b/test/background/reducers/setting.test.js index 2ef98cb..8df5abe 100644 --- a/test/background/reducers/setting.test.js +++ b/test/background/reducers/setting.test.js @@ -30,7 +30,6 @@ describe("setting reducer", () => { }; state = settingReducer(state, action); - console.log(state); expect(state.value.properties).to.have.property('smoothscroll', true); expect(state.value.properties).to.have.property('encoding', 'utf-8'); }); diff --git a/test/content/actions/setting.test.js b/test/content/actions/setting.test.js index 1248edf..3112b2d 100644 --- a/test/content/actions/setting.test.js +++ b/test/content/actions/setting.test.js @@ -23,6 +23,8 @@ describe("setting actions", () => { let map = new Map(keymaps); expect(map).to.have.deep.all.keys( [ + [{ key: 'Esc', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], + [{ key: '[', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }], [{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, { key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], [{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, From 5cd8c81fda2f07bc6ca5b1ee9264a02fae16c5c0 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 4 Mar 2018 21:32:50 +0900 Subject: [PATCH 3/3] increase timeout --- e2e/karma.conf.js | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/karma.conf.js b/e2e/karma.conf.js index 2b60ca9..6140ff3 100644 --- a/e2e/karma.conf.js +++ b/e2e/karma.conf.js @@ -34,6 +34,7 @@ module.exports = function (config) { }, reporters: ['mocha'], + browserDisconnectTimeout: 5000, plugins: [ require('./karma-webext-launcher'),