Skip to content

Commit b726b8d

Browse files
committed
refactor: refactor some constant names and fix typos
1 parent cc9a54b commit b726b8d

File tree

18 files changed

+73
-72
lines changed

18 files changed

+73
-72
lines changed

src/components/About/About.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
22
import { LIBRARIES } from 'helpers/const';
33
import About from 'components/About';
44
import { AppContext } from 'context/AppContext';
5-
import { AppAactions } from 'context/Reducer';
5+
import { AppActions } from 'context/Reducer';
66

77
describe('<About />', () => {
88
const state = {
@@ -23,11 +23,11 @@ describe('<About />', () => {
2323
expect(listElement.children.length).toEqual(LIBRARIES.length);
2424
});
2525

26-
it('calls dipatch on button click', () => {
26+
it('calls dispatch on button click', () => {
2727
fireEvent.click(screen.getByTestId('modal-close-btn'));
2828

2929
expect(dispatch).toHaveBeenCalledWith({
30-
type: AppAactions.TOGGLE_ABOUT_MODAL,
30+
type: AppActions.TOGGLE_ABOUT_MODAL,
3131
payload: 'none',
3232
});
3333
});

src/components/About/About.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useContext } from 'react';
22
import { LIBRARIES } from 'helpers/const';
33
import { AppContext } from 'context/AppContext';
4-
import { AppAactions } from 'context/Reducer';
4+
import { AppActions } from 'context/Reducer';
55
import Modal from 'components/Modal';
66

77
const About: React.FC = () => {
@@ -10,7 +10,7 @@ const About: React.FC = () => {
1010
const open = state.display !== 'none';
1111

1212
const handleClose = () => {
13-
dispatch({ type: AppAactions.TOGGLE_ABOUT_MODAL, payload: 'none' });
13+
dispatch({ type: AppActions.TOGGLE_ABOUT_MODAL, payload: 'none' });
1414
};
1515

1616
return (

src/components/App/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useContext, useEffect, useState } from 'react';
22
import Header from 'components/Header';
33
import About from 'components/About';
44
import { AppContext } from 'context/AppContext';
5-
import { AppAactions } from 'context/Reducer';
5+
import { AppActions } from 'context/Reducer';
66
import ContextMenu from 'components/ContextMenu';
77
import JsonView from 'components/JsonView';
88
import CodeEditor from 'components/CodeEditor';
@@ -16,7 +16,7 @@ const App: React.FC = () => {
1616
useEffect(() => {
1717
const consoleProxy = console.log;
1818
console.log = msg => {
19-
dispatch({ type: AppAactions.CODE_RUN_SUCCESS, payload: msg });
19+
dispatch({ type: AppActions.CODE_RUN_SUCCESS, payload: msg });
2020
consoleProxy(msg);
2121
};
2222
}, []);
@@ -49,7 +49,7 @@ const App: React.FC = () => {
4949
position={position}
5050
onClose={() => setPosition(null)}
5151
onClick={() => {
52-
dispatch({ type: AppAactions.TOGGLE_JSON_VIEW, payload: 'block' });
52+
dispatch({ type: AppActions.TOGGLE_JSON_VIEW, payload: 'block' });
5353
setPosition(null);
5454
}}
5555
/>

src/components/CodeEditor/CodeEditor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useContext, useEffect, useRef, useState } from 'react';
22
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
33

44
import { AppContext } from 'context/AppContext';
5-
import { AppAactions } from 'context/Reducer';
5+
import { AppActions } from 'context/Reducer';
66
import useCodeRunner from 'hooks/useCodeRunner';
77

88
const CodeEditor: React.FC = () => {
@@ -47,12 +47,12 @@ const CodeEditor: React.FC = () => {
4747
keybindings: [monaco.KeyMod.CtrlCmd + monaco.KeyCode.KeyL],
4848
contextMenuGroupId: 'navigation',
4949
contextMenuOrder: 1,
50-
run: () => dispatch({ type: AppAactions.CLEAR_RESULT }),
50+
run: () => dispatch({ type: AppActions.CLEAR_RESULT }),
5151
});
5252

5353
editorInstance.onDidChangeModelContent(() => {
5454
dispatch({
55-
type: AppAactions.UPDATE_CODE,
55+
type: AppActions.UPDATE_CODE,
5656
payload: editorInstance.getValue(),
5757
});
5858
});

src/components/Console/Console.spec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable react/jsx-no-constructed-context-values */
21
import { render, screen } from '@testing-library/react';
32
import Console from 'components/Console';
43
import { AppContext } from 'context/AppContext';
@@ -44,7 +43,7 @@ describe('<Console />', () => {
4443
);
4544
});
4645

47-
it('stringfy result that is not a string', () => {
46+
it('stringify result that is not a string', () => {
4847
const result = [{ message: 'result' }, 'item'];
4948
state.result = result;
5049
render(

src/components/Console/Console.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ const Console: React.FC = () => {
2424
return (
2525
<div data-testid="console-result" className={`console ${extraClass}`}>
2626
{result.map((item, index) => {
27-
const resut = !_.isString(item) ? JSON.stringify(item) : item;
27+
const consoleItem = !_.isString(item) ? JSON.stringify(item) : item;
2828
return (
2929
<div key={createKey(index)}>
3030
<pre>
3131
<span style={{ marginRight: 5 }}>&#8250;</span>
32-
<span data-testid={`console-result-item-${index}`}>{resut}</span>
32+
<span data-testid={`console-result-item-${index}`}>
33+
{consoleItem}
34+
</span>
3335
</pre>
3436
</div>
3537
);

src/components/ContextMenu/ContextMenu.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('<ContextMenu/>', () => {
77
onClick: jest.fn(),
88
onClose: jest.fn(),
99
};
10-
it('does not render if poistion is not defined', () => {
10+
it('does not render if position is not defined', () => {
1111
render(<ContextMenu {...props} position={null} />);
1212
expect(screen.queryByTestId('app-context-menu')).not.toBeInTheDocument();
1313
});

src/components/Header/Header.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
22
import Header from 'components/Header';
33
import { AppContext } from 'context/AppContext';
4-
import { AppAactions } from 'context/Reducer';
4+
import { AppActions } from 'context/Reducer';
55

66
describe('<Header />', () => {
77
describe('header actions', () => {
@@ -25,28 +25,28 @@ describe('<Header />', () => {
2525
fireEvent.click(screen.getByText('About'));
2626
expect(dispatch).toHaveBeenCalledWith({
2727
payload: 'block',
28-
type: AppAactions.TOGGLE_ABOUT_MODAL,
28+
type: AppActions.TOGGLE_ABOUT_MODAL,
2929
});
3030
});
3131
it('toggle the theme when toggle button is click', () => {
3232
fireEvent.click(screen.getByTestId('app-theme-button-vs-dark'));
3333
expect(dispatch).toHaveBeenCalledWith({
3434
payload: 'vs-dark',
35-
type: AppAactions.TOGGLE_THEME,
35+
type: AppActions.TOGGLE_THEME,
3636
});
3737
});
3838

3939
it('dispatch execute code action when run button is clicked', () => {
4040
fireEvent.click(screen.getByTestId('actionbutton-button-execute'));
4141
expect(dispatch).toHaveBeenCalledWith({
42-
type: AppAactions.CODE_RUNNING,
42+
type: AppActions.CODE_RUNNING,
4343
});
4444
});
4545

4646
it('dispatch clear result action when clear button is clicked', () => {
4747
fireEvent.click(screen.getByTestId('actionbutton-button-clear'));
4848
expect(dispatch).toHaveBeenCalledWith({
49-
type: AppAactions.CLEAR_RESULT,
49+
type: AppActions.CLEAR_RESULT,
5050
});
5151
});
5252

@@ -55,7 +55,7 @@ describe('<Header />', () => {
5555
target: { value: 'Axios' },
5656
});
5757
expect(dispatch).toHaveBeenCalledWith({
58-
type: AppAactions.LOAD_CODE_SAMPLE,
58+
type: AppActions.LOAD_CODE_SAMPLE,
5959
payload: expect.objectContaining({
6060
codeSampleName: 'Axios',
6161
}),

src/components/Header/Header.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ChangeEvent, useContext } from 'react';
22
import ActionButton from 'components/ActionButton';
33
import { AppContext } from 'context/AppContext';
4-
import { AppAactions } from 'context/Reducer';
4+
import { AppActions } from 'context/Reducer';
55
import { CODE_SAMPLES, EDITOR_THEMES } from 'helpers/const';
66
import useCodeRunner from 'hooks/useCodeRunner';
77

@@ -22,7 +22,7 @@ const Header: React.FC = () => {
2222
codeSampleName: value,
2323
};
2424

25-
dispatch({ type: AppAactions.LOAD_CODE_SAMPLE, payload });
25+
dispatch({ type: AppActions.LOAD_CODE_SAMPLE, payload });
2626
};
2727

2828
return (
@@ -40,7 +40,7 @@ const Header: React.FC = () => {
4040
style={{ cursor: 'pointer' }}
4141
onClick={() =>
4242
dispatch({
43-
type: AppAactions.TOGGLE_ABOUT_MODAL,
43+
type: AppActions.TOGGLE_ABOUT_MODAL,
4444
payload: 'block',
4545
})
4646
}
@@ -82,7 +82,7 @@ const Header: React.FC = () => {
8282
}`}
8383
onClick={() => {
8484
dispatch({
85-
type: AppAactions.TOGGLE_THEME,
85+
type: AppActions.TOGGLE_THEME,
8686
payload: item.value,
8787
});
8888
}}
@@ -95,13 +95,13 @@ const Header: React.FC = () => {
9595
<span style={{ marginLeft: 20, marginRight: 20 }} />
9696
<ActionButton
9797
type="clear"
98-
onClick={() => dispatch({ type: AppAactions.CLEAR_RESULT })}
98+
onClick={() => dispatch({ type: AppActions.CLEAR_RESULT })}
9999
/>
100100

101101
<span style={{ marginLeft: 20, marginRight: 20 }} />
102102
<ActionButton
103103
type="history"
104-
onClick={() => dispatch({ type: AppAactions.TOGGLE_HISTORY_MODAL })}
104+
onClick={() => dispatch({ type: AppActions.TOGGLE_HISTORY_MODAL })}
105105
/>
106106

107107
<span style={{ marginLeft: 20, marginRight: 20 }} />

src/components/HistoryModal/HistoryModal.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { fireEvent, render, screen } from '@testing-library/react';
33
import { AppContext } from 'context/AppContext';
4-
import { AppAactions } from 'context/Reducer';
4+
import { AppActions } from 'context/Reducer';
55
import HistoryModal from 'components/HistoryModal';
66
import * as StorageService from 'services/storage';
77

@@ -45,7 +45,7 @@ describe('<HistoryModal />', () => {
4545
fireEvent.click(screen.getByTestId('modal-close-btn'));
4646

4747
expect(dispatch).toHaveBeenCalledWith({
48-
type: AppAactions.TOGGLE_HISTORY_MODAL,
48+
type: AppActions.TOGGLE_HISTORY_MODAL,
4949
});
5050
});
5151

@@ -60,7 +60,7 @@ describe('<HistoryModal />', () => {
6060

6161
it('restore history when restore button click', () => {
6262
expect(dispatch).toHaveBeenNthCalledWith(1, {
63-
type: AppAactions.LOAD_CODE_SAMPLE,
63+
type: AppActions.LOAD_CODE_SAMPLE,
6464
payload: {
6565
codeSample: mockHistory[historyItemIndex].code,
6666
codeSampleName: '',
@@ -70,7 +70,7 @@ describe('<HistoryModal />', () => {
7070

7171
it('dismiss the modal', () => {
7272
expect(dispatch).toHaveBeenNthCalledWith(2, {
73-
type: AppAactions.TOGGLE_HISTORY_MODAL,
73+
type: AppActions.TOGGLE_HISTORY_MODAL,
7474
});
7575
});
7676
});

0 commit comments

Comments
 (0)