Skip to content

Commit c101c2e

Browse files
author
Maximilian Heinz
committed
fix: specs and remove form from component
1 parent 9224d3e commit c101c2e

File tree

9 files changed

+70
-121
lines changed

9 files changed

+70
-121
lines changed

src/App.css

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/App.spec.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/App.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/actions/__tests__/actions.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ describe('actions', () => {
44
it('should create incrementCounter action', () => {
55
const expectedAction = {
66
type: actions.INCREMENT_COUNTER,
7-
value: 0,
87
};
9-
expect(actions.incrementCounter(0)).toEqual(expectedAction);
8+
expect(actions.incrementCounter()).toEqual(expectedAction);
109
});
1110

1211
it('should create loadCount action', () => {

src/actions/index.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,65 @@ export type LOAD_COUNT_ERROR = typeof LOAD_COUNT_ERROR;
2020

2121
export type Action =
2222
// UI actions
23-
| { type: INCREMENT_COUNTER, value: number }
23+
| { type: INCREMENT_COUNTER }
2424
| { type: RESET_COUNTER }
2525

2626
// API Requests
27-
| { type: 'SAVE_COUNT', value: number }
27+
| { type: 'SAVE_COUNT'; value: number }
2828
| { type: 'SAVE_COUNT_SUCCESS' }
2929
| { type: 'SAVE_COUNT_ERROR' } & E
3030
| { type: 'LOAD_COUNT' }
31-
| { type: 'LOAD_COUNT_SUCCESS', value: number }
31+
| { type: 'LOAD_COUNT_SUCCESS'; value: number }
3232
| { type: 'LOAD_COUNT_ERROR' } & E;
3333

34-
export const incrementCounter = (value: number): Action => ({
35-
type: INCREMENT_COUNTER,
36-
value,
37-
});
34+
export function incrementCounter(): Action {
35+
return {
36+
type: INCREMENT_COUNTER,
37+
};
38+
}
3839

39-
export const resetCounter = (): Action => ({
40-
type: RESET_COUNTER,
41-
});
40+
export function resetCounter(): Action {
41+
return {
42+
type: RESET_COUNTER,
43+
};
44+
}
4245

43-
export const saveCount = (value: number): Action => ({
44-
type: SAVE_COUNT,
45-
value,
46-
});
46+
export function saveCount(value: number): Action {
47+
return {
48+
type: SAVE_COUNT,
49+
value,
50+
};
51+
}
4752

48-
export const saveCountSuccess = (): Action => ({
49-
type: SAVE_COUNT_SUCCESS,
50-
});
53+
export function saveCountSuccess(): Action {
54+
return {
55+
type: SAVE_COUNT_SUCCESS,
56+
};
57+
}
5158

52-
export const saveCountError = (error: Error): Action => ({
53-
type: SAVE_COUNT_ERROR,
54-
error,
55-
});
59+
export function saveCountError(error: Error): Action {
60+
return {
61+
type: SAVE_COUNT_ERROR,
62+
error,
63+
};
64+
}
5665

57-
export const loadCount = (): Action => ({
58-
type: LOAD_COUNT,
59-
});
66+
export function loadCount(): Action {
67+
return {
68+
type: LOAD_COUNT,
69+
};
70+
}
6071

61-
export const loadCountSuccess = (value: number): Action => {
72+
export function loadCountSuccess(value: number): Action {
6273
return {
6374
type: LOAD_COUNT_SUCCESS,
6475
value,
6576
};
66-
};
77+
}
6778

68-
export const loadCountError = (error: Error): Action => {
79+
export function loadCountError(error: Error): Action {
6980
return {
7081
type: LOAD_COUNT_ERROR,
7182
error,
7283
};
73-
};
84+
}

src/components/__tests__/__snapshots__/counter.spec.tsx.snap

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,22 @@ exports[`components/Counter renders 1`] = `
99
0
1010
</strong>
1111
</div>
12-
<form>
13-
<button
14-
onClick={[Function]}
15-
>
16-
click me!
17-
</button>
18-
<button
19-
disabled={false}
20-
onClick={[Function]}
21-
>
22-
save
23-
</button>
24-
<button
25-
disabled={false}
26-
onClick={[Function]}
27-
>
28-
load
29-
</button>
30-
</form>
12+
<button
13+
onClick={[Function]}
14+
>
15+
click me!
16+
</button>
17+
<button
18+
disabled={false}
19+
onClick={[Function]}
20+
>
21+
save
22+
</button>
23+
<button
24+
disabled={false}
25+
onClick={[Function]}
26+
>
27+
load
28+
</button>
3129
</div>
3230
`;

src/components/counter.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface StateProps {
1414
interface DispatchProps {
1515
loadCount: () => Action;
1616
saveCount: (value: number) => Action;
17-
incrementCounter: (value: number) => Action;
17+
incrementCounter: () => Action;
1818
}
1919

2020
interface OwnProps {}
@@ -27,7 +27,7 @@ class CounterContainerComponent extends React.Component<Props, {}> {
2727
};
2828

2929
increment = () => {
30-
this.props.incrementCounter(1);
30+
this.props.incrementCounter();
3131
};
3232

3333
render() {
@@ -36,18 +36,13 @@ class CounterContainerComponent extends React.Component<Props, {}> {
3636
<div className="hero">
3737
<strong>{this.props.counter}</strong>
3838
</div>
39-
<form>
40-
<button onClick={this.increment}>click me!</button>
41-
<button disabled={this.props.isSaving} onClick={this.saveCount}>
42-
{this.props.isSaving ? 'saving...' : 'save'}
43-
</button>
44-
<button
45-
disabled={this.props.isLoading}
46-
onClick={this.props.loadCount}
47-
>
48-
{this.props.isLoading ? 'loading...' : 'load'}
49-
</button>
50-
</form>
39+
<button onClick={this.increment}>click me!</button>
40+
<button disabled={this.props.isSaving} onClick={this.saveCount}>
41+
{this.props.isSaving ? 'saving...' : 'save'}
42+
</button>
43+
<button disabled={this.props.isLoading} onClick={this.props.loadCount}>
44+
{this.props.isLoading ? 'loading...' : 'load'}
45+
</button>
5146
</div>
5247
);
5348
}

src/reducers/__tests__/reducer.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ describe('reducer', () => {
2828
expect(reducer(undefined, { type: 'noOp' })).toEqual(state);
2929
});
3030

31-
it('incrementCounter() should return the initial state', () => {
32-
expect(reducer(undefined, incrementCounter(5))).toEqual({
31+
it('incrementCounter() should increment counter by 1', () => {
32+
expect(reducer(undefined, incrementCounter())).toEqual({
3333
...state,
34-
counter: 5,
34+
counter: 1,
3535
});
3636
});
3737

src/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const reducer: LoopReducer<All, actions.Action> = (
2222
): All | Loop<All, actions.Action> => {
2323
switch (action.type) {
2424
case 'INCREMENT_COUNTER':
25-
return { ...state, counter: state.counter + action.value };
25+
return { ...state, counter: state.counter + 1 };
2626
case 'RESET_COUNTER':
2727
return { ...state, counter: 0 };
2828
case 'LOAD_COUNT':

0 commit comments

Comments
 (0)