Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8f480ef

Browse files
Refactor actions into constants
1 parent 47293c9 commit 8f480ef

File tree

14 files changed

+58
-37
lines changed

14 files changed

+58
-37
lines changed

‎__tests__/actions/actions.test.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
import { restart } from '../../src/actions/restart';
22
import { submitAnswer } from '../../src/actions/submitAnswer';
33
import { toggle, toggleJS, toggleMode } from '../../src/actions/toggle';
4+
import { SUBMIT, TOGGLE, TOGGLE_JS, TOGGLE_MODE, RESTART } from '../../src/data/constants';
45

56
describe('Action Creators', () => {
67
it('should dispatch RESTART action', () => {
78
expect(restart('restart')).toEqual({
8-
type: 'RESTART',
9+
type: RESTART,
910
payload: 'restart'
1011
});
1112
});
1213

1314
it('should dispatch SUBMIT action', () => {
1415
expect(submitAnswer('submit')).toEqual({
15-
type: 'SUBMIT',
16+
type: SUBMIT,
1617
payload: 'submit'
1718
});
1819
});
1920

2021
it('should dispatch TOGGLE action', () => {
2122
expect(toggle('toggle')).toEqual({
22-
type: 'TOGGLE',
23+
type: TOGGLE,
2324
payload: 'toggle'
2425
});
2526
});
2627

2728
it('should dispatch TOGGLE_JS action', () => {
2829
expect(toggleJS('toggle js')).toEqual({
29-
type: 'TOGGLE_JS',
30+
type: TOGGLE_JS,
3031
payload: 'toggle js'
3132
});
3233
});
3334

3435
it('should dispatch TOGGLE_MODE action', () => {
3536
expect(toggleMode('toggle mode')).toEqual({
36-
type: 'TOGGLE_MODE',
37+
type: TOGGLE_MODE,
3738
payload: 'toggle mode'
3839
});
3940
});

‎__tests__/components/ButtonContainer.test.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ButtonContainer, {
88
ButtonContainer as NotConnectedButtonContainer
99
} from '../../src/components/ButtonContainer';
1010
import { answers } from '../../src/store';
11+
import { SUBMIT } from '../../src/data/constants';
1112

1213
describe('<ButtonContainer /> connected', () => {
1314
const mockStore = configureMockStore();
@@ -33,7 +34,7 @@ describe('<ButtonContainer /> connected', () => {
3334
.simulate('click');
3435

3536
const actions = store.getActions();
36-
expect(actions).toMatchObject([{ type: 'SUBMIT' }]);
37+
expect(actions).toMatchObject([{ type: SUBMIT }]);
3738
});
3839
});
3940

‎__tests__/components/Toggle.test.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { themeLight } from '../../src/styles/themes/theme.light';
88
import { themeDark } from '../../src/styles/themes/theme.dark';
99
import 'jest-styled-components';
1010
import Toggle from '../../src/components/Toggle';
11+
import { TOGGLE } from '../../src/data/constants';
1112

1213
const mockClick = jest.fn();
1314
const mockStore = configureMockStore();
@@ -90,7 +91,7 @@ describe('<Toggle> actions', () => {
9091
toggle.find('button').simulate('click');
9192

9293
const actions = store.getActions();
93-
expect(actions).toMatchObject([{ type: 'TOGGLE', payload: 'mode' }]);
94+
expect(actions).toMatchObject([{ type: TOGGLE, payload: 'mode' }]);
9495
});
9596

9697
it('toggles MODE to DARK', () => {
@@ -111,7 +112,7 @@ describe('<Toggle> actions', () => {
111112
toggle.find('button').simulate('click');
112113

113114
const actions = store.getActions();
114-
expect(actions).toMatchObject([{ type: 'TOGGLE', payload: 'mode' }]);
115+
expect(actions).toMatchObject([{ type: TOGGLE, payload: 'mode' }]);
115116
});
116117

117118
it('toggles JS to ES6', () => {
@@ -132,7 +133,7 @@ describe('<Toggle> actions', () => {
132133
toggle.find('button').simulate('click');
133134

134135
const actions = store.getActions();
135-
expect(actions).toMatchObject([{ type: 'TOGGLE', payload: 'js' }]);
136+
expect(actions).toMatchObject([{ type: TOGGLE, payload: 'js' }]);
136137
});
137138

138139
it('toggles JS to ES5', () => {
@@ -153,6 +154,6 @@ describe('<Toggle> actions', () => {
153154
toggle.find('button').simulate('click');
154155

155156
const actions = store.getActions();
156-
expect(actions).toMatchObject([{ type: 'TOGGLE', payload: 'js' }]);
157+
expect(actions).toMatchObject([{ type: TOGGLE, payload: 'js' }]);
157158
});
158159
});

‎__tests__/middleware/submit.test.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import configureMockStore from 'redux-mock-store';
22
import { submitMiddleware } from '../../src/middleware/submit';
3+
import { SUBMIT } from '../../src/data/constants';
34

45
const next = jest.fn();
56
const mockStore = configureMockStore();
@@ -36,7 +37,7 @@ describe('Submit middleware', () => {
3637
current: patterns[0]
3738
}
3839
});
39-
const action = { type: 'SUBMIT', payload: 'abc123' };
40+
const action = { type: SUBMIT, payload: 'abc123' };
4041

4142
submitMiddleware(store)(next)(action);
4243

@@ -64,7 +65,7 @@ describe('Submit middleware', () => {
6465
}
6566
]
6667
},
67-
type: 'SUBMIT'
68+
type: SUBMIT
6869
});
6970
});
7071

‎__tests__/middleware/toggle.test.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import configureMockStore from 'redux-mock-store';
22
import { toggleMiddleware } from '../../src/middleware/toggle';
3+
import { TOGGLE, TOGGLE_JS, TOGGLE_MODE } from '../../src/data/constants';
34

45
const next = jest.fn();
56
const mockStore = configureMockStore();
@@ -12,12 +13,12 @@ describe('Toggle middleware', () => {
1213
js: 'es5',
1314
dispatch: mockDispatch
1415
});
15-
const action = { type: 'TOGGLE', payload: 'js' };
16+
const action = { type: TOGGLE, payload: 'js' };
1617

1718
toggleMiddleware(store)(next)(action);
1819

1920
expect(store.getActions()[0]).toEqual({
20-
type: 'TOGGLE_JS',
21+
type: TOGGLE_JS,
2122
payload: 'es6'
2223
});
2324

@@ -31,12 +32,12 @@ describe('Toggle middleware', () => {
3132
js: 'es6',
3233
dispatch: mockDispatch
3334
});
34-
const action = { type: 'TOGGLE', payload: 'js' };
35+
const action = { type: TOGGLE, payload: 'js' };
3536

3637
toggleMiddleware(store)(next)(action);
3738

3839
expect(store.getActions()[0]).toEqual({
39-
type: 'TOGGLE_JS',
40+
type: TOGGLE_JS,
4041
payload: 'es5'
4142
});
4243

@@ -50,12 +51,12 @@ describe('Toggle middleware', () => {
5051
mode: 'dark',
5152
dispatch: mockDispatch
5253
});
53-
const action = { type: 'TOGGLE', payload: 'mode' };
54+
const action = { type: TOGGLE, payload: 'mode' };
5455

5556
toggleMiddleware(store)(next)(action);
5657

5758
expect(store.getActions()[0]).toEqual({
58-
type: 'TOGGLE_MODE',
59+
type: TOGGLE_MODE,
5960
payload: 'light'
6061
});
6162
});
@@ -67,12 +68,12 @@ describe('Toggle middleware', () => {
6768
mode: 'light',
6869
dispatch: mockDispatch
6970
});
70-
const action = { type: 'TOGGLE', payload: 'mode' };
71+
const action = { type: TOGGLE, payload: 'mode' };
7172

7273
toggleMiddleware(store)(next)(action);
7374

7475
expect(store.getActions()[0]).toEqual({
75-
type: 'TOGGLE_MODE',
76+
type: TOGGLE_MODE,
7677
payload: 'dark'
7778
});
7879
});

‎__tests__/pages/Game.test.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { themeDark } from '../../src/styles/themes/theme.dark';
99
import styleLight from '../../src/styles/hljs/hljs.light';
1010
import styleDark from '../../src/styles/hljs/hljs.dark';
1111
import Game from '../../src/pages/Game';
12+
import { RESTART } from '../../src/data/constants';
1213

1314
const patterns = [
1415
{
@@ -179,6 +180,6 @@ describe('Game page - RESULTS', () => {
179180
it('reacts to button click', () => {
180181
tree.find('button').simulate('click');
181182
const actions = store.getActions();
182-
expect(actions).toMatchObject([{ type: 'RESTART' }]);
183+
expect(actions).toMatchObject([{ type: RESTART }]);
183184
});
184185
});

‎__tests__/reducers/reducers.test.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import reducer from '../../src/reducers';
2+
import { SUBMIT, TOGGLE, TOGGLE_JS, TOGGLE_MODE } from '../../src/data/constants';
23

34
const answers = [
45
{
@@ -41,7 +42,7 @@ describe('Reducers', () => {
4142

4243
it('should return unchanged state on toggle', () => {
4344
const action = {
44-
type: 'TOGGLE',
45+
type: TOGGLE,
4546
payload: null
4647
};
4748

@@ -52,7 +53,7 @@ describe('Reducers', () => {
5253

5354
it('should toggle JS', () => {
5455
const action = {
55-
type: 'TOGGLE_JS',
56+
type: TOGGLE_JS,
5657
payload: 'es6'
5758
};
5859

@@ -64,7 +65,7 @@ describe('Reducers', () => {
6465

6566
it('should toggle MODE', () => {
6667
const action = {
67-
type: 'TOGGLE_MODE',
68+
type: TOGGLE_MODE,
6869
payload: 'light'
6970
};
7071

@@ -76,7 +77,7 @@ describe('Reducers', () => {
7677

7778
xit('should handle SUBMIT', () => {
7879
const action = {
79-
type: 'SUBMIT',
80+
type: SUBMIT,
8081
payload: {
8182
currentIndex: 0,
8283
remainingPatterns: answers[1],

‎src/actions/restart.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { RESTART } from '../data/constants';
2+
13
export const restart = payload => ({
2-
type: 'RESTART',
4+
type: RESTART,
35
payload
46
});

‎src/actions/submitAnswer.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { SUBMIT } from '../data/constants';
2+
13
export const submitAnswer = payload => ({
2-
type: 'SUBMIT',
4+
type: SUBMIT,
35
payload
46
});

‎src/actions/toggle.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import { TOGGLE, TOGGLE_JS, TOGGLE_MODE } from '../data/constants';
2+
13
export const toggle = payload => ({
2-
type: 'TOGGLE',
4+
type: TOGGLE,
35
payload
46
});
57

68
export const toggleJS = payload => ({
7-
type: 'TOGGLE_JS',
9+
type: TOGGLE_JS,
810
payload
911
});
1012

1113
export const toggleMode = payload => ({
12-
type: 'TOGGLE_MODE',
14+
type: TOGGLE_MODE,
1315
payload
1416
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /