Merge pull request #354 from ueokande/hide-console

Hide console
jh-changes
Shin'ya Ueoka 7 years ago committed by GitHub
commit 72bf3cc2bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      e2e/karma.conf.js
  2. 4
      src/background/actions/operation.js
  3. 8
      src/console/actions/console.js
  4. 1
      src/console/actions/index.js
  5. 2
      src/console/index.js
  6. 4
      src/console/reducers/index.js
  7. 9
      src/content/actions/setting.js
  8. 1
      src/shared/messages.js
  9. 3
      src/shared/operations.js
  10. 1
      test/background/reducers/setting.test.js
  11. 6
      test/console/actions/console.test.js
  12. 6
      test/console/reducers/console.test.js
  13. 2
      test/content/actions/setting.test.js

@ -34,6 +34,7 @@ module.exports = function (config) {
}, },
reporters: ['mocha'], reporters: ['mocha'],
browserDisconnectTimeout: 5000,
plugins: [ plugins: [
require('./karma-webext-launcher'), require('./karma-webext-launcher'),

@ -73,6 +73,10 @@ const exec = (operation, tab) => {
return browser.tabs.sendMessage(tab.id, { return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_FIND type: messages.CONSOLE_SHOW_FIND
}); });
case operations.CANCEL:
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_HIDE,
});
default: default:
return Promise.resolve(); return Promise.resolve();
} }

@ -1,5 +1,11 @@
import actions from 'console/actions'; import actions from 'console/actions';
const hide = () => {
return {
type: actions.CONSOLE_HIDE,
};
};
const showCommand = (text) => { const showCommand = (text) => {
return { return {
type: actions.CONSOLE_SHOW_COMMAND, type: actions.CONSOLE_SHOW_COMMAND,
@ -61,6 +67,6 @@ const completionPrev = () => {
}; };
export { export {
showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText,
setCompletions, completionNext, completionPrev setCompletions, completionNext, completionPrev
}; };

@ -1,5 +1,6 @@
export default { export default {
// console commands // console commands
CONSOLE_HIDE: 'console.hide',
CONSOLE_SHOW_COMMAND: 'console.show.command', CONSOLE_SHOW_COMMAND: 'console.show.command',
CONSOLE_SHOW_ERROR: 'console.show.error', CONSOLE_SHOW_ERROR: 'console.show.error',
CONSOLE_SHOW_INFO: 'console.show.info', CONSOLE_SHOW_INFO: 'console.show.info',

@ -24,6 +24,8 @@ const onMessage = (message) => {
return store.dispatch(consoleActions.showError(message.text)); return store.dispatch(consoleActions.showError(message.text));
case messages.CONSOLE_SHOW_INFO: case messages.CONSOLE_SHOW_INFO:
return store.dispatch(consoleActions.showInfo(message.text)); return store.dispatch(consoleActions.showInfo(message.text));
case messages.CONSOLE_HIDE:
return store.dispatch(consoleActions.hide());
} }
}; };

@ -53,6 +53,10 @@ const nextConsoleText = (completions, group, item, defaults) => {
export default function reducer(state = defaultState, action = {}) { export default function reducer(state = defaultState, action = {}) {
switch (action.type) { switch (action.type) {
case actions.CONSOLE_HIDE:
return Object.assign({}, state, {
mode: '',
});
case actions.CONSOLE_SHOW_COMMAND: case actions.CONSOLE_SHOW_COMMAND:
return Object.assign({}, state, { return Object.assign({}, state, {
mode: 'command', mode: 'command',

@ -1,10 +1,17 @@
import actions from 'content/actions'; import actions from 'content/actions';
import * as keyUtils from 'shared/utils/keys'; import * as keyUtils from 'shared/utils/keys';
import operations from 'shared/operations';
const reservedKeymaps = {
'<Esc>': { type: operations.CANCEL },
'<C-[>': { type: operations.CANCEL },
};
const set = (value) => { const set = (value) => {
let entries = []; let entries = [];
if (value.keymaps) { if (value.keymaps) {
entries = Object.entries(value.keymaps).map((entry) => { let keymaps = Object.assign({}, value.keymaps, reservedKeymaps);
entries = Object.entries(keymaps).map((entry) => {
return [ return [
keyUtils.fromMapKeys(entry[0]), keyUtils.fromMapKeys(entry[0]),
entry[1], entry[1],

@ -32,6 +32,7 @@ export default {
CONSOLE_SHOW_ERROR: 'console.show.error', CONSOLE_SHOW_ERROR: 'console.show.error',
CONSOLE_SHOW_INFO: 'console.show.info', CONSOLE_SHOW_INFO: 'console.show.info',
CONSOLE_SHOW_FIND: 'console.show.find', CONSOLE_SHOW_FIND: 'console.show.find',
CONSOLE_HIDE: 'console.hide',
FOLLOW_START: 'follow.start', FOLLOW_START: 'follow.start',
FOLLOW_REQUEST_COUNT_TARGETS: 'follow.request.count.targets', FOLLOW_REQUEST_COUNT_TARGETS: 'follow.request.count.targets',

@ -1,4 +1,7 @@
export default { export default {
// Hide console, or cancel some user actions
CANCEL: 'cancel',
// Addons // Addons
ADDON_ENABLE: 'addon.enable', ADDON_ENABLE: 'addon.enable',
ADDON_DISABLE: 'addon.disable', ADDON_DISABLE: 'addon.disable',

@ -30,7 +30,6 @@ describe("setting reducer", () => {
}; };
state = settingReducer(state, action); state = settingReducer(state, action);
console.log(state);
expect(state.value.properties).to.have.property('smoothscroll', true); expect(state.value.properties).to.have.property('smoothscroll', true);
expect(state.value.properties).to.have.property('encoding', 'utf-8'); expect(state.value.properties).to.have.property('encoding', 'utf-8');
}); });

@ -3,6 +3,12 @@ import actions from 'console/actions';
import * as consoleActions from 'console/actions/console'; import * as consoleActions from 'console/actions/console';
describe("console actions", () => { describe("console actions", () => {
describe('hide', () => {
it('create CONSOLE_HIDE action', () => {
let action = consoleActions.hide();
expect(action.type).to.equal(actions.CONSOLE_HIDE);
});
});
describe("showCommand", () => { describe("showCommand", () => {
it('create CONSOLE_SHOW_COMMAND action', () => { it('create CONSOLE_SHOW_COMMAND action', () => {
let action = consoleActions.showCommand('hello'); let action = consoleActions.showCommand('hello');

@ -13,6 +13,12 @@ describe("console reducer", () => {
expect(state).to.have.property('itemSelection', -1); 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', () => { it('return next state for CONSOLE_SHOW_COMMAND', () => {
let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' };
let state = reducer({}, action); let state = reducer({}, action);

@ -23,6 +23,8 @@ describe("setting actions", () => {
let map = new Map(keymaps); let map = new Map(keymaps);
expect(map).to.have.deep.all.keys( 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: '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 }, [{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false },