Skip to content

Commit a2bc6bd

Browse files
author
Shawn Toubeau
authored
Merge pull request #84 from path2finding/refactor/code-cleanup
Code cleanup + UI changes
2 parents 61f1dd5 + b1f291b commit a2bc6bd

37 files changed

+1209
-17190
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict = true

package-lock.json

-16,079
This file was deleted.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"name": "visualizer",
33
"version": "0.1.0",
44
"private": true,
5+
"engines": {
6+
"node": ">=10.15.0",
7+
"npm": "please-use-yarn",
8+
"yarn": ">=1.0.0"
9+
},
510
"dependencies": {
611
"@testing-library/jest-dom": "^4.2.4",
712
"@testing-library/react": "^9.3.2",

public/path2phamming.png

-330 KB
Binary file not shown.
File renamed without changes.

src/actions/mazeActions/mazeActions.spec.ts

+4-37
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ import {
44
handleChangeEnd,
55
makeWall,
66
makeEmpty,
7-
loadMaze,
87
CHANGE_START,
98
CHANGE_END,
109
MAKE_WALL,
1110
MAKE_EMPTY,
12-
LOAD_MAZE,
13-
STOP_VISUALIZATION,
14-
handleStopVisualization,
1511
} from "./mazeActions";
16-
import { initialState, generateMaze } from "../../models/maze/initialState";
17-
import { ButtonProps } from "semantic-ui-react";
12+
import { initialState } from "../../models/maze/initialState";
1813

1914
describe("Maze Action Tests", () => {
2015
const mockStore = configureStore();
@@ -84,37 +79,9 @@ describe("Maze Action Tests", () => {
8479
});
8580
});
8681

87-
describe("Load Maze Test", () => {
88-
it("Should call LOAD_MAZE action", () => {
89-
const maze = generateMaze(5, 5, false);
82+
// TODO: progressBFS
9083

91-
const expectedActions = [
92-
{
93-
type: LOAD_MAZE,
94-
payload: { mazeInfo: maze },
95-
},
96-
];
97-
reduxStore.dispatch(loadMaze(maze));
98-
expect(reduxStore.getActions()).toEqual(expectedActions);
99-
});
100-
});
84+
// TODO: progressDFS
10185

102-
describe("Stop Visualization Test", () => {
103-
it("Should dispatch correct action", () => {
104-
const expectedActions = [
105-
{
106-
type: STOP_VISUALIZATION,
107-
payload: null,
108-
},
109-
];
110-
111-
reduxStore.dispatch(
112-
handleStopVisualization(
113-
{ target: {} } as React.MouseEvent<HTMLButtonElement, MouseEvent>,
114-
{} as ButtonProps
115-
)
116-
);
117-
expect(reduxStore.getActions()).toEqual(expectedActions);
118-
});
119-
});
86+
// TODO: progressASTAR
12087
});
+2-75
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import { AnyAction } from "redux";
2-
import { Coord, MazeInfo, Maze } from "../../models/maze";
3-
import { generateMaze } from "../../models/maze/initialState";
4-
import { ButtonProps } from "semantic-ui-react";
5-
import { PAUSE_VISUALIZATION } from "../menuActions/menuActions";
2+
import { Coord, MazeInfo } from "../../models/maze";
3+
64
export const CHANGE_START = "CHANGE_START";
75
export const CHANGE_END = "CHANGE_END";
86
export const MAKE_WALL = "MAKE_WALL";
97
export const MAKE_EMPTY = "MAKE_EMPTY";
10-
export const MAKE_VISITED = "MAKE_VISITED";
11-
export const LOAD_MAZE = "LOAD_MAZE";
12-
export const STOP_VISUALIZATION = "STOP_VISUALIZATION";
138
export const PROGRESS_BFS = "PROGRESS_BFS";
14-
export const UPDATE_GRID_SIZE = "UPDATE_GRID_SIZE";
159
export const PROGRESS_DFS = "PROGRESS_DFS";
1610
export const PROGRESS_ASTAR = "PROGRESS_ASTAR";
17-
export const UPDATE_OPEN_SET = "UPDATE_OPEN_SET";
18-
export const UPDATE_CLOSED_SET = "UPDATE_CLOSED_SET";
19-
export const RANDOMIZE_WALLS = "RANDOMIZE_WALLS";
2011

2112
export const handleChangeStart = (newPos: Coord): AnyAction => {
2213
return {
@@ -46,40 +37,6 @@ export const makeEmpty = (coord: Coord): AnyAction => {
4637
};
4738
};
4839

49-
export const makeVisited = (coord: Coord): AnyAction => {
50-
return {
51-
type: MAKE_VISITED,
52-
payload: coord,
53-
};
54-
};
55-
56-
export const loadMaze = (mazeInfo: MazeInfo): AnyAction => {
57-
return {
58-
type: LOAD_MAZE,
59-
payload: { mazeInfo: mazeInfo },
60-
};
61-
};
62-
63-
export const handlePauseVisualization = (
64-
_?: React.MouseEvent<HTMLButtonElement, MouseEvent>,
65-
data?: ButtonProps
66-
) => {
67-
return {
68-
type: PAUSE_VISUALIZATION,
69-
payload: null,
70-
};
71-
};
72-
73-
export const handleStopVisualization = (
74-
_?: React.MouseEvent<HTMLButtonElement, MouseEvent>,
75-
data?: ButtonProps
76-
) => {
77-
return {
78-
type: STOP_VISUALIZATION,
79-
payload: null,
80-
};
81-
};
82-
8340
export const progressBFS = (
8441
queue: Coord[],
8542
coord: Coord,
@@ -110,15 +67,6 @@ export const progressDFS = (
11067
};
11168
};
11269

113-
export const updateGridSize = (cols: number, rows: number) => {
114-
return {
115-
type: UPDATE_GRID_SIZE,
116-
payload: {
117-
cols: cols,
118-
rows: rows,
119-
},
120-
};
121-
};
12270
export const progressAstar = (
12371
openSet: Coord[],
12472
closedSet: Coord[],
@@ -135,24 +83,3 @@ export const progressAstar = (
13583
},
13684
};
13785
};
138-
139-
export const handleUpdateOpenSet = (openSet: Coord[]) => {
140-
return {
141-
type: UPDATE_OPEN_SET,
142-
payload: openSet,
143-
};
144-
};
145-
146-
export const handleUpdateClosedSet = (closedSet: Coord[]) => {
147-
return {
148-
type: UPDATE_CLOSED_SET,
149-
payload: closedSet,
150-
};
151-
};
152-
153-
export const randomizeWalls = () => {
154-
return {
155-
type: RANDOMIZE_WALLS,
156-
payload: null,
157-
};
158-
};

src/actions/menuActions/menuActions.spec.ts

+58-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ import configureStore from "redux-mock-store";
22
import {
33
handleStartVisualization,
44
handlePauseVisualization,
5+
handleStopVisualization,
56
handleClearGrid,
67
START_VISUALIZATION,
78
PAUSE_VISUALIZATION,
9+
STOP_VISUALIZATION,
810
CLEAR_GRID,
911
CHANGE_ALGO,
1012
TOGGLE_MOVE_START,
1113
TOGGLE_MOVE_END,
1214
toggleMoveStart,
1315
toggleMoveEnd,
14-
handleDropdownChange,
16+
handleChangeAlgo,
17+
loadMaze,
18+
LOAD_MAZE,
1519
} from "./menuActions";
1620
import { ButtonProps, DropdownProps } from "semantic-ui-react";
1721
import { initialState } from "../../models/menu/initialState";
22+
import { generateMaze } from "../../models/maze/initialState";
1823

1924
describe("Navbar Action Tests", () => {
2025
const mockStore = configureStore();
@@ -60,6 +65,47 @@ describe("Navbar Action Tests", () => {
6065
});
6166
});
6267

68+
describe("Stop Visualization Test", () => {
69+
it("Should dispatch correct action", () => {
70+
const expectedActions = [
71+
{
72+
type: STOP_VISUALIZATION,
73+
payload: null,
74+
},
75+
];
76+
77+
reduxStore.dispatch(
78+
handleStopVisualization(
79+
{ target: {} } as React.MouseEvent<HTMLButtonElement, MouseEvent>,
80+
{} as ButtonProps
81+
)
82+
);
83+
expect(reduxStore.getActions()).toEqual(expectedActions);
84+
});
85+
});
86+
87+
// TODO: change speed
88+
89+
describe("Change Algorithm Test", () => {
90+
it("Should dispatch correct action", () => {
91+
const expectedActions = [
92+
{
93+
type: CHANGE_ALGO,
94+
payload: undefined,
95+
},
96+
];
97+
reduxStore.dispatch(
98+
handleChangeAlgo(
99+
{ target: {} } as React.MouseEvent<HTMLButtonElement, MouseEvent>,
100+
{} as DropdownProps
101+
)
102+
);
103+
expect(reduxStore.getActions()).toEqual(expectedActions);
104+
});
105+
});
106+
107+
// TODO: change grid size
108+
63109
describe("Move Start Point Test", () => {
64110
it("Should modify redux store", () => {
65111
const expectedActions = [
@@ -96,6 +142,8 @@ describe("Navbar Action Tests", () => {
96142
});
97143
});
98144

145+
// TODO: randomize walls
146+
99147
describe("Clear Grid Test", () => {
100148
it("Should dispatch correct action", () => {
101149
const expectedActions = [
@@ -114,20 +162,19 @@ describe("Navbar Action Tests", () => {
114162
});
115163
});
116164

117-
describe("Change Algorithm Test", () => {
118-
it("Should dispatch correct action", () => {
165+
// TODO: save maze
166+
167+
describe("Load Maze Test", () => {
168+
it("Should call LOAD_MAZE action", () => {
169+
const maze = generateMaze(5, 5, false);
170+
119171
const expectedActions = [
120172
{
121-
type: CHANGE_ALGO,
122-
payload: undefined,
173+
type: LOAD_MAZE,
174+
payload: { mazeInfo: maze },
123175
},
124176
];
125-
reduxStore.dispatch(
126-
handleDropdownChange(
127-
{ target: {} } as React.MouseEvent<HTMLButtonElement, MouseEvent>,
128-
{} as DropdownProps
129-
)
130-
);
177+
reduxStore.dispatch(loadMaze(maze));
131178
expect(reduxStore.getActions()).toEqual(expectedActions);
132179
});
133180
});

0 commit comments

Comments
 (0)