Skip to content

Commit de3ef44

Browse files
authored
Merge pull request #26 from oslabs-beta/staging
Staging to Main Typescript Refactoring for Acc Test Suite
2 parents f2bf901 + 7908884 commit de3ef44

File tree

11 files changed

+171
-241
lines changed

11 files changed

+171
-241
lines changed

src/components/AccTestComponent/DescribeRenderer/DescribeRenderer.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, { useRef, useEffect } from 'react';
1+
import React, { useRef, useEffect, ChangeEvent } from 'react';
22
import cn from 'classnames';
33
import { Draggable, Droppable } from 'react-beautiful-dnd';
44
import ItRenderer from '../ItRenderer/ItRenderer';
55
import styles from './DescribeRenderer.module.scss';
66
import { deleteDescribeBlock, addItStatement } from '../../../context/actions/accTestCaseActions';
7+
import { AccTestCaseState } from '../../../utils/accTypes';
78

89
const DescribeRenderer = ({
910
dispatcher,
@@ -12,25 +13,25 @@ const DescribeRenderer = ({
1213
handleChangeDescribeText,
1314
handleChangeItStatementText,
1415
type,
15-
}) => {
16-
const testDescription = useRef(null);
16+
}): AccTestCaseState => {
17+
const testDescription = useRef<HTMLInputElement>(null!);
1718

1819
useEffect(() => {
1920
testDescription.current.focus();
2021
}, []);
2122

22-
const deleteDescribeBlockHandleClick = (e) => {
23+
const deleteDescribeBlockHandleClick = (e: ChangeEvent) => {
2324
e.stopPropagation();
2425
const describeId = e.target.id;
2526
dispatcher(deleteDescribeBlock(describeId));
2627
};
2728

28-
const addItStatementHandleClick = (e) => {
29+
const addItStatementHandleClick = (e: ChangeEvent) => {
2930
const describeId = e.target.id;
3031
dispatcher(addItStatement(describeId));
3132
};
3233

33-
return describeBlocks.allIds.map((id, i) => (
34+
return describeBlocks.allIds.map((id: string, i: number) => (
3435
<Draggable
3536
key={id}
3637
draggableId={id}

src/components/AccTestComponent/ItRenderer/ItRenderer.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from 'react';
1+
import React, { ChangeEvent, useContext } from 'react';
22
import cn from 'classnames';
33
import { Draggable } from 'react-beautiful-dnd';
44
import { AccTestCaseContext } from '../../../context/reducers/accTestCaseReducer';
@@ -12,20 +12,19 @@ import CustomInput from '../CustomInput/CustomInput';
1212
import styles from './ItRenderer.module.scss';
1313

1414
const ItRenderer = ({
15-
type,
1615
itStatements,
1716
describeId,
1817
handleChangeItStatementText,
1918
}) => {
2019

2120
const [, dispatchToAccTestCase] = useContext(AccTestCaseContext);
2221

23-
const deleteItStatementHandleClick = (e) => {
22+
const deleteItStatementHandleClick = (e: ChangeEvent) => {
2423
const itId = e.target.id;
2524
dispatchToAccTestCase(deleteItStatement(describeId, itId));
2625
};
2726

28-
return itStatements.allIds[describeId].map((id, i) => (
27+
return itStatements.allIds[describeId].map((id: string, i:number) => (
2928
<Draggable
3029
draggableId={id}
3130
index={i}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useContext, useReducer } from 'react';
1+
import React, { useContext, ChangeEvent } from 'react';
22
import cn from 'classnames';
3-
import { DragDropContext, Droppable } from 'react-beautiful-dnd';
3+
import { DragDropContext, Droppable, DropResult } from 'react-beautiful-dnd';
44
import styles from './TestCase.module.scss';
55
import {
66
updateDescribeText,
@@ -17,8 +17,6 @@ import DecribeRenderer from '../AccTestComponent/DescribeRenderer/DescribeRender
1717
import { updateImportFilePath } from '../../context/actions/accTestCaseActions';
1818
import {
1919
AccTestCaseContext,
20-
accTestCaseState,
21-
accTestCaseReducer,
2220
} from '../../context/reducers/accTestCaseReducer';
2321

2422
const AccTestCase = () => {
@@ -28,28 +26,28 @@ const AccTestCase = () => {
2826

2927
const { describeBlocks, itStatements } = accTestCase;
3028

31-
const [{ filePathMap }] = useContext(GlobalContext);
29+
const [{ filePathMap }] = useContext<any>(GlobalContext);
3230

33-
const handleChangeDescribeText = (e) => {
31+
const handleChangeDescribeText = (e: ChangeEvent<HTMLInputElement>) => {
3432
const text = e.target.value;
3533
const describeId = e.target.id;
3634
dispatchToAccTestCase(updateDescribeText(text, describeId));
3735
};
3836

39-
const handleChangeItStatementText = (e) => {
37+
const handleChangeItStatementText = (e: ChangeEvent<HTMLInputElement>) => {
4038
const text = e.target.value;
4139
const itId = e.target.id;
4240
dispatchToAccTestCase(updateItStatementText(text, itId));
4341
};
4442

45-
const reorder = (list, startIndex, endIndex) => {
43+
const reorder = (list: Array<any>, startIndex: number, endIndex: number) => {
4644
const result = Array.from(list);
4745
const [removed] = result.splice(startIndex, 1);
4846
result.splice(endIndex, 0, removed);
4947
return result;
5048
};
5149

52-
const onDragEnd = (result) => {
50+
const onDragEnd = (result: DropResult) => {
5351
// edge cases: dropped to a non-destination, or dropped where it was grabbed (no change)
5452
if (!result.destination) return;
5553
if (result.destination.index === result.source.index) return;

src/components/TestMenu/AccTestMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const AccTestMenu = () => {
2222
// initialize hooks
2323
const { title, isModalOpen, openModal, openScriptModal, closeModal } = useToggleModal('acc');
2424
const [accTestCase, dispatchToAccTestCase] = useContext(AccTestCaseContext);
25-
const [{ projectFilePath, file, exportBool }, dispatchToGlobal] = useContext(GlobalContext);
25+
const [{ projectFilePath, file, exportBool }, dispatchToGlobal] = useContext<any>(GlobalContext);
2626
const generateTest = useGenerateTest('acc', projectFilePath);
2727

2828
// setValidCode to true on load.
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const actionTypes = {
1717

1818
UPDATE_FILE_PATH: 'UPDATE_FILE_PATH',
1919

20-
// not yet implemented:
2120
TOGGLE_ACC: 'TOGGLE_ACC',
2221
};
2322

@@ -29,44 +28,44 @@ export const addDescribeBlock = () => {
2928
};
3029
};
3130

32-
export const deleteDescribeBlock = (describeId) => {
31+
export const deleteDescribeBlock = (describeId: string) => {
3332
return {
3433
type: actionTypes.DELETE_DESCRIBE_BLOCK,
3534
describeId,
3635
};
3736
};
3837

39-
export const updateDescribeText = (text, describeId) => ({
38+
export const updateDescribeText = (text: string, describeId: string) => ({
4039
type: actionTypes.UPDATE_DESCRIBE_TEXT,
4140
text,
4241
describeId,
4342
});
4443

45-
export const updateDescribeOrder = (reorderedDescribe) => {
44+
export const updateDescribeOrder = (reorderedDescribe: Array<string>) => {
4645
return {
4746
type: actionTypes.UPDATE_DESCRIBE_ORDER,
4847
reorderedDescribe,
4948
};
5049
};
5150

52-
export const addItStatement = (describeId) => ({
51+
export const addItStatement = (describeId: string) => ({
5352
type: actionTypes.ADD_ITSTATEMENT,
5453
describeId,
5554
});
5655

57-
export const deleteItStatement = (describeId, itId) => ({
56+
export const deleteItStatement = (describeId: string, itId: string) => ({
5857
type: actionTypes.DELETE_ITSTATEMENT,
5958
describeId,
6059
itId,
6160
});
6261

63-
export const updateItStatementText = (text, itId) => ({
62+
export const updateItStatementText = (text: string, itId: string) => ({
6463
type: actionTypes.UPDATE_ITSTATEMENT_TEXT,
6564
itId,
6665
text,
6766
});
6867

69-
export const updateItStatementOrder = (reorderedIt, describeId) => {
68+
export const updateItStatementOrder = (reorderedIt: Array<string>, describeId: string) => {
7069
return {
7170
type: actionTypes.UPDATE_ITSTATEMENT_ORDER,
7271
reorderedIt,
@@ -86,7 +85,7 @@ export const closeInfoModal = () => {
8685
return { type: actionTypes.CLOSE_INFO_MODAL };
8786
};
8887

89-
export const updateImportFilePath = (fileName, filePath) => ({
88+
export const updateImportFilePath = (fileName: string, filePath: string) => ({
9089
type: actionTypes.UPDATE_FILE_PATH,
9190
fileName,
9291
filePath,

src/context/reducers/accTestCaseReducer.js renamed to src/context/reducers/accTestCaseReducer.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { createContext } from 'react';
1+
import { createContext } from 'react';
2+
import { AccTestCaseState, Action} from '../../utils/accTypes';
23
import { actionTypes } from '../actions/accTestCaseActions';
34

4-
export const AccTestCaseContext = createContext([]);
5+
export const AccTestCaseContext:any = createContext([]);
56

6-
export const accTestCaseState = {
7+
export const accTestCaseState: AccTestCaseState = {
78
modalOpen: false,
89

910
describeId: 1,
1011
itId: 1,
1112
statementId: 1,
1213
propId: 1,
13-
describeBlocks: {
14-
byId: {
14+
describeBlocks: {
15+
byId: {
1516
describe0: {
1617
id: 'describe0',
1718
text: '',
@@ -37,22 +38,22 @@ export const accTestCaseState = {
3738

3839
/* ---------------------------- Helper Functions ---------------------------- */
3940

40-
const createDescribeBlock = (describeId) => {
41+
const createDescribeBlock = (describeId: string) => {
4142
return {
4243
id: describeId,
4344
text: '',
4445
};
4546
};
4647

47-
const createItStatement = (describeId, itId) => ({
48+
const createItStatement = (describeId: string , itId: string) => ({
4849
id: itId,
4950
describeId,
5051
text: '',
5152
});
5253

5354
/* ------------------------- Accessibility Test Case Reducer ------------------------ */
5455

55-
export const accTestCaseReducer = (state, action) => {
56+
export const accTestCaseReducer = (state: AccTestCaseState, action: Action) => {
5657
Object.freeze(state);
5758

5859
let describeBlocks;
@@ -97,10 +98,10 @@ export const accTestCaseReducer = (state, action) => {
9798
// delete it from describeBlocks.byId
9899
delete newDescById[describeId];
99100
// delete it from describeBlocks.allIds
100-
const newDescAllIds = describeBlocks.allIds.filter((id) => id !== describeId);
101+
const newDescAllIds = describeBlocks.allIds.filter((id: string) => id !== describeId);
101102

102103
// delete from itStatements.byId
103-
itStatements.allIds[describeId].forEach((itId) => {
104+
itStatements.allIds[describeId].forEach((itId: number) => {
104105
delete newItById[itId];
105106
});
106107
// delete from itStatements.allIds
@@ -172,7 +173,7 @@ export const accTestCaseReducer = (state, action) => {
172173
const { itId, describeId } = action;
173174
const byId = { ...itStatements.byId };
174175
delete byId[itId];
175-
const newAllIds = itStatements.allIds[describeId].filter((id) => id !== itId);
176+
const newAllIds = itStatements.allIds[describeId].filter((id: number) => id !== itId);
176177

177178
return {
178179
...state,

src/context/reducers/endpointTestCaseReducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const deepCopy = (endpointStatements: EndpointObj[]) => {
6666

6767
export const endpointTestCaseReducer = (state: EndpointTestCaseState, action: Action) => {
6868
Object.freeze(state);
69-
let endpointStatements = [...state.endpointStatements];
69+
let endpointStatements: Array<any> = [...state.endpointStatements];
7070

7171
switch (action.type) {
7272
case actionTypes.ADD_ENDPOINT:
@@ -106,7 +106,7 @@ export const endpointTestCaseReducer = (state: EndpointTestCaseState, action: Ac
106106
endpointStatements,
107107
};
108108
case actionTypes.UPDATE_SERVER_FILEPATH:
109-
const { serverFilePath, serverFileName } = action;
109+
const { serverFilePath, serverFileName } = action;
110110
return {
111111
...state,
112112
serverFilePath,

src/context/reducers/hooksTestCaseReducer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createContext } from 'react';
22
// import { actionTypes } from '../actions/hooksTestCaseActions';
3-
import { HooksTestCaseState, Assertion, Action, Hooks, Callback } from '../../utils/hooksTypes';
3+
import { HooksTestCaseState, Assertion, HooksAction, Hooks, Callback } from '../../utils/hooksTypes';
44

55
export const HooksTestCaseContext: any = createContext(null);
66

@@ -62,6 +62,8 @@ export const hooksTestCaseState: HooksTestCaseState = {
6262
hooksTestStatement: '',
6363
hooksStatements: [],
6464
statementId: 0,
65+
hookFileName: '',
66+
hookFilePath: '',
6567
};
6668

6769
// const createContexts = (statementId: number) => ({
@@ -106,7 +108,7 @@ const deepCopy = (hooksStatements: Hooks[]) => {
106108
return fullCopy;
107109
};
108110

109-
export const hooksTestCaseReducer = (state: HooksTestCaseState, action: Action) => {
111+
export const hooksTestCaseReducer = (state: HooksTestCaseState, action: HooksAction) => {
110112
Object.freeze(state);
111113
let hooksStatements = [...state.hooksStatements];
112114

0 commit comments

Comments
 (0)