Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 settings add tabs with numpad enter works #212

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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