Skip to content

Commit

Permalink
🐛 settings add tabs with numpad enter works
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Nov 18, 2022
1 parent 4a29e53 commit 2cd2837
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/settings/__tests__/settings.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ describe('Settings in Browser test suite', () => {
await waitFor(() => expect($input.value).toBe('A'));
expect($tabContainer.childElementCount).toBe(2);
});
describe('keydown event, Enter key with URLS', () => {
describe.each([
'Enter',
'NumpadEnter'
])('keydown event, "%s" key with URLS', code => {
test('Empty URL, should do nothing', async () => {
// Given
fireEvent.input($input, {target: {value: ''}});
// When
fireEvent.keyDown($input, {code: 'Enter'});
fireEvent.keyDown($input, {code});
// Then
expect($tabContainer.childElementCount).toBe(2);
expect($addTabButton.hasAttribute('disabled')).toBe(true);
Expand All @@ -100,7 +103,7 @@ describe('Settings in Browser test suite', () => {
// Given
fireEvent.input($input, {target: {value: 'invalid:1337:url'}});
// When
fireEvent.keyDown($input, {code: 'Enter'});
fireEvent.keyDown($input, {code});
// Then
expect($tabContainer.childElementCount).toBe(2);
await waitFor(() =>
Expand All @@ -114,7 +117,7 @@ describe('Settings in Browser test suite', () => {
// Given
fireEvent.input($input, {target: {value: 'info.cern.ch'}});
// When
fireEvent.keyDown($input, {code: 'Enter'});
fireEvent.keyDown($input, {code});
// Then
await waitFor(() =>
expect($tabContainer.childElementCount).toBe(3));
Expand All @@ -129,7 +132,7 @@ describe('Settings in Browser test suite', () => {
// Given
fireEvent.input($input, {target: {value: 'http://info.cern.ch'}});
// When
fireEvent.keyDown($input, {code: 'Enter'});
fireEvent.keyDown($input, {code});
// Then
await waitFor(() =>
expect($tabContainer.childElementCount).toBe(3));
Expand Down
10 changes: 5 additions & 5 deletions src/settings/settings.browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {ipcRenderer} = window;

import {APP_EVENTS, html, render, useReducer, Checkbox, IconButton, TopAppBar} from '../components/index.mjs';
import {
ACTIONS, reducer, dictionariesEnabled, setTabProperty, toggleTabProperty
ACTIONS, reducer, addTab, dictionariesEnabled, setTabProperty, toggleTabProperty
} from './settings.reducer.browser.mjs';
import {
OtherContainer
Expand Down Expand Up @@ -106,10 +106,10 @@ const Settings = ({initialState}) => {
type: ACTIONS.UPDATE_NEW_TAB_VALUE,
payload: value
});
const addTab = () => dispatch({type: ACTIONS.ADD});
const onAddTab = addTab({dispatch});
const onNewKeyDown = ({code}) => {
if (code === 'Enter') {
addTab();
if (code === 'Enter' || code === 'NumpadEnter') {
onAddTab();
}
};
const save = () => ipcRenderer.send(APP_EVENTS.settingsSave, {
Expand Down Expand Up @@ -140,7 +140,7 @@ const Settings = ({initialState}) => {
onkeydown=${onNewKeyDown}
/>
</div>
<${SettingsButton} icon='fa-plus' onClick=${addTab} disabled=${!state.newTabValid} />
<${SettingsButton} icon='fa-plus' onClick=${onAddTab} disabled=${!state.newTabValid} />
</div>
<div class="settings__tabs container field">
${state.tabs.map(tab => (html`
Expand Down
2 changes: 2 additions & 0 deletions src/settings/settings.reducer.browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export const reducer = (state, action) => {
};

// Action creators
export const addTab = ({dispatch}) =>
() => dispatch({type: ACTIONS.ADD});
export const setTabProperty = ({dispatch, property, value, id}) =>
dispatch({type: ACTIONS.SET_TAB_PROPERTY, payload: {id, property, value}});
export const setTheme = ({dispatch}) =>
Expand Down

0 comments on commit 2cd2837

Please sign in to comment.