Skip to content

Commit 2bd89c4

Browse files
author
Shawn Toubeau
authored
Merge pull request #86 from path2finding/feature/reducer-action-tests
Adds more remainder+action tests
2 parents e2e5834 + b5b8858 commit 2bd89c4

File tree

7 files changed

+310
-44
lines changed

7 files changed

+310
-44
lines changed

src/actions/mazeActions/mazeActions.spec.ts

+75-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import {
44
handleChangeEnd,
55
makeWall,
66
makeEmpty,
7+
progressBFS,
8+
progressDFS,
9+
progressAstar,
710
CHANGE_START,
811
CHANGE_END,
912
MAKE_WALL,
1013
MAKE_EMPTY,
14+
PROGRESS_BFS,
15+
PROGRESS_DFS,
16+
PROGRESS_ASTAR,
1117
} from "./mazeActions";
1218
import { initialState } from "../../models/maze/initialState";
19+
import { Coord } from "../../models/maze";
1320

1421
describe("Maze Action Tests", () => {
1522
const mockStore = configureStore();
@@ -79,9 +86,74 @@ describe("Maze Action Tests", () => {
7986
});
8087
});
8188

82-
// TODO: progressBFS
89+
describe("Progress BFS", () => {
90+
it("Should call PROGRESS_BFS action", () => {
91+
const queue: Coord[] = [];
92+
const coord = { x: 0, y: 0 };
93+
const neighbors = [
94+
{ x: 1, y: 0 },
95+
{ x: 0, y: 1 },
96+
];
97+
98+
const expectedActions = [
99+
{
100+
type: PROGRESS_BFS,
101+
payload: {
102+
queue: queue,
103+
coord: coord,
104+
neighbors: neighbors,
105+
},
106+
},
107+
];
108+
reduxStore.dispatch(progressBFS(queue, coord, neighbors));
109+
expect(reduxStore.getActions()).toEqual(expectedActions);
110+
});
111+
});
112+
113+
describe("Progress DFS", () => {
114+
it("Should call PROGRESS_DFS action", () => {
115+
const stack: Coord[] = [];
116+
const coord = { x: 0, y: 0 };
117+
const neighbors = [
118+
{ x: 1, y: 0 },
119+
{ x: 0, y: 1 },
120+
];
121+
122+
const expectedActions = [
123+
{
124+
type: PROGRESS_DFS,
125+
payload: {
126+
stack: stack,
127+
coord: coord,
128+
neighbors: neighbors,
129+
},
130+
},
131+
];
132+
reduxStore.dispatch(progressDFS(stack, coord, neighbors));
133+
expect(reduxStore.getActions()).toEqual(expectedActions);
134+
});
135+
});
83136

84-
// TODO: progressDFS
137+
describe("Progress A*", () => {
138+
it("Should call PROGRESS_ASTAR action", () => {
139+
const openSet: Coord[] = [];
140+
const closedSet: Coord[] = [];
141+
const newMazeInfo = initialState.mazeInfo;
142+
const end = { x: 1, y: 1 };
85143

86-
// TODO: progressASTAR
144+
const expectedActions = [
145+
{
146+
type: PROGRESS_ASTAR,
147+
payload: {
148+
openSet: openSet,
149+
closedSet: closedSet,
150+
newMazeInfo: newMazeInfo,
151+
end: end,
152+
},
153+
},
154+
];
155+
reduxStore.dispatch(progressAstar(openSet, closedSet, newMazeInfo, end));
156+
expect(reduxStore.getActions()).toEqual(expectedActions);
157+
});
158+
});
87159
});

src/actions/menuActions/menuActions.spec.ts

+60-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import {
1616
handleChangeAlgo,
1717
loadMaze,
1818
LOAD_MAZE,
19+
CHANGE_SPEED,
20+
handleChangeSpeed,
21+
UPDATE_GRID_SIZE,
22+
handleChangeGridSize,
23+
RANDOMIZE_WALLS,
24+
randomizeWalls,
1925
} from "./menuActions";
2026
import { ButtonProps, DropdownProps } from "semantic-ui-react";
2127
import { initialState } from "../../models/menu/initialState";
@@ -30,7 +36,7 @@ describe("Navbar Action Tests", () => {
3036
});
3137

3238
describe("Start Visualization Test", () => {
33-
it("Should dispatch correct action", () => {
39+
it("Should call START_VISUALIZATION action", () => {
3440
const expectedActions = [
3541
{
3642
type: START_VISUALIZATION,
@@ -48,7 +54,7 @@ describe("Navbar Action Tests", () => {
4854
});
4955

5056
describe("Pause Visualization Test", () => {
51-
it("Should modify redux store", () => {
57+
it("Should call PAUSE_VISUALIZATION action", () => {
5258
const expectedActions = [
5359
{
5460
type: PAUSE_VISUALIZATION,
@@ -66,7 +72,7 @@ describe("Navbar Action Tests", () => {
6672
});
6773

6874
describe("Stop Visualization Test", () => {
69-
it("Should dispatch correct action", () => {
75+
it("Should call STOP_VISUALIZATION action", () => {
7076
const expectedActions = [
7177
{
7278
type: STOP_VISUALIZATION,
@@ -84,10 +90,26 @@ describe("Navbar Action Tests", () => {
8490
});
8591
});
8692

87-
// TODO: change speed
93+
describe("Change Visualization Speed", () => {
94+
it("Should call CHANGE_SPEED action", () => {
95+
const expectedActions = [
96+
{
97+
type: CHANGE_SPEED,
98+
payload: undefined,
99+
},
100+
];
101+
reduxStore.dispatch(
102+
handleChangeSpeed(
103+
{ target: {} } as React.MouseEvent<HTMLButtonElement, MouseEvent>,
104+
{} as DropdownProps
105+
)
106+
);
107+
expect(reduxStore.getActions()).toEqual(expectedActions);
108+
});
109+
});
88110

89111
describe("Change Algorithm Test", () => {
90-
it("Should dispatch correct action", () => {
112+
it("Should call CHANGE_ALGO action", () => {
91113
const expectedActions = [
92114
{
93115
type: CHANGE_ALGO,
@@ -104,10 +126,27 @@ describe("Navbar Action Tests", () => {
104126
});
105127
});
106128

107-
// TODO: change grid size
129+
describe("Change Grid Size Test", () => {
130+
it("Should call UPDATE_GRID_SIZE action", () => {
131+
const cols = 20;
132+
const rows = 20;
133+
134+
const expectedActions = [
135+
{
136+
type: UPDATE_GRID_SIZE,
137+
payload: {
138+
cols: cols,
139+
rows: rows,
140+
},
141+
},
142+
];
143+
reduxStore.dispatch(handleChangeGridSize(cols, rows));
144+
expect(reduxStore.getActions()).toEqual(expectedActions);
145+
});
146+
});
108147

109148
describe("Move Start Point Test", () => {
110-
it("Should modify redux store", () => {
149+
it("Should call TOGGLE_MOVE_START action", () => {
111150
const expectedActions = [
112151
{
113152
type: TOGGLE_MOVE_START,
@@ -125,7 +164,7 @@ describe("Navbar Action Tests", () => {
125164
});
126165

127166
describe("Move End Point Test", () => {
128-
it("Should modify redux store", () => {
167+
it("Should call TOGGLE_MOVE_END action", () => {
129168
const expectedActions = [
130169
{
131170
type: TOGGLE_MOVE_END,
@@ -142,10 +181,21 @@ describe("Navbar Action Tests", () => {
142181
});
143182
});
144183

145-
// TODO: randomize walls
184+
describe("Randomize Walls Test", () => {
185+
it("Should call RANDOMIZE_WALLS action", () => {
186+
const expectedActions = [
187+
{
188+
type: RANDOMIZE_WALLS,
189+
payload: null,
190+
},
191+
];
192+
reduxStore.dispatch(randomizeWalls());
193+
expect(reduxStore.getActions()).toEqual(expectedActions);
194+
});
195+
});
146196

147197
describe("Clear Grid Test", () => {
148-
it("Should dispatch correct action", () => {
198+
it("Should call CLEAR_GRID action", () => {
149199
const expectedActions = [
150200
{
151201
type: CLEAR_GRID,
@@ -162,8 +212,6 @@ describe("Navbar Action Tests", () => {
162212
});
163213
});
164214

165-
// TODO: save maze
166-
167215
describe("Load Maze Test", () => {
168216
it("Should call LOAD_MAZE action", () => {
169217
const maze = generateMaze(5, 5, false);

src/components/Maze/algorithms/A*.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getCoord,
99
} from "./";
1010

11-
const heuristic = (a: Coord, b: Coord): number => {
11+
export const heuristic = (a: Coord, b: Coord): number => {
1212
// Manhattan distance formula
1313
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
1414

src/components/Menu/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ class MenuBar extends React.Component<Props, State> {
282282
/>
283283
<span>Stop</span>
284284
</Button>
285-
{/* TODO: fix */}
286285
{isPlaying && startTime && !endTime ? (
287286
<Menu.Item>
288287
<Moment date={startTime} durationFromNow></Moment>

src/components/Menu/menu.spec.tsx

-18
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ describe("<Menu />", () => {
5252
<Menu {...props} />
5353
</Provider>
5454
);
55-
// console.log('wrapper is', wrapper.debug());
5655
expect(wrapper).toBeDefined();
5756
});
5857

@@ -114,21 +113,4 @@ describe("<Menu />", () => {
114113
wrapper.find(SemanticButton).at(3).simulate("click");
115114
expect(props.onClear).toHaveBeenCalled();
116115
});
117-
118-
// TODO: This fails because it's not hooked up to a reducer
119-
// it("Save Maze button calls action", () => {
120-
// wrapper
121-
// .find(SemanticButton)
122-
// .at(5)
123-
// .simulate("click");
124-
// expect(props.saveMaze).toHaveBeenCalled();
125-
// });
126-
127-
// it("Change dropdown selection", () => {
128-
// wrapper
129-
// .find(SemanticDropdown)
130-
// .simulate("click")
131-
// .simulate("keypress", { key: "Tab" });
132-
// expect(wrapper.find(SemanticDropdown).selectedAlgo).toBeDefined();
133-
// });
134116
});

0 commit comments

Comments
 (0)