diff --git a/src/components/Temp/TempActions.tsx b/src/components/Temp/TempActions.tsx deleted file mode 100644 index b8efe41324..0000000000 --- a/src/components/Temp/TempActions.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import axios from "axios"; - -import { StoreStateDispatch } from "types/actions"; -import { RuntimeConfig } from "types/runtimeConfig"; - -export const PRESS_BUTTON = "PRESS_BUTTON"; -export type PRESS_BUTTON = typeof PRESS_BUTTON; - -//action types -export interface ButtonPressed { - type: PRESS_BUTTON; -} - -var server = axios.create({ - baseURL: RuntimeConfig.getInstance().baseUrl(), - timeout: 1000, - headers: { "Content-Type": "application/json" }, -}); - -//thunk action creator -export function asyncPressButton() { - return async (dispatch: StoreStateDispatch) => { - //console.log('asyncPressButton called'); - dispatch(pressButton()); - await server - .post("/words", { - Vernacular: "test", - Gloss: "test2", - Audio: "sound", - Timestamp: "now", - }) - .then(function (response) { - //console.log(response); - }); - }; -} - -//pure action creator. LEAVE PURE! -export function pressButton(): ButtonPressed { - //console.log('PressButton called'); - return { - type: PRESS_BUTTON, - }; -} - -export type TempAction = ButtonPressed; // | OtherAction diff --git a/src/components/Temp/TempComponent.tsx b/src/components/Temp/TempComponent.tsx deleted file mode 100644 index 50b8c21c08..0000000000 --- a/src/components/Temp/TempComponent.tsx +++ /dev/null @@ -1,63 +0,0 @@ -/* THIS COMPONENT IS INTENDED TO BE AN EXAMPLE ONLY. - IT WILL NOT BE USED IN THE APPLICATION. -*/ - -//external modules -import Button from "@material-ui/core/Button"; -import * as React from "react"; -import { - Translate, - LocalizeContextProps, - withLocalize, -} from "react-localize-redux"; - -//interface for component props -export interface TempProps { - text: string; - buttonClicked?: () => void; -} - -//interface for component state -interface TempState { - clickCount: number; -} - -class Temp extends React.Component< - TempProps & LocalizeContextProps, - TempState -> { - constructor(props: TempProps & LocalizeContextProps) { - super(props); - this.state = { clickCount: 0 }; - } - - handleButtonClick() { - if (this.props.buttonClicked) { - this.props.buttonClicked(); - } - this.setState((prevState) => ({ clickCount: prevState.clickCount + 1 })); - } - - render() { - //extract text from props - const { text } = this.props; - - //visual definition - return ( -
-
- {text}
- {" "} -
- -
- ); - } -} - -//export class as default -export default withLocalize(Temp); diff --git a/src/components/Temp/TempReducer.tsx b/src/components/Temp/TempReducer.tsx deleted file mode 100644 index c6ec0021db..0000000000 --- a/src/components/Temp/TempReducer.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { TempAction } from "components/Temp/TempActions"; -import { PRESS_BUTTON } from "components/Temp/TempActions"; -import { StoreAction, StoreActions } from "rootActions"; - -export interface TempState { - tempText: string; -} - -export const defaultState: TempState = { - tempText: "default text from reducer", -}; - -export const tempReducer = ( - state: TempState | undefined, //createStore() calls each reducer with undefined state - action: StoreAction | TempAction -): TempState => { - if (!state) return defaultState; - switch (action.type) { - case PRESS_BUTTON: - return { ...state, tempText: "BUTTON PRESSED! REDUX WORKING!" }; - case StoreActions.RESET: - return defaultState; - default: - return state; - } -}; diff --git a/src/components/Temp/index.tsx b/src/components/Temp/index.tsx deleted file mode 100644 index f0269e0da1..0000000000 --- a/src/components/Temp/index.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { connect } from "react-redux"; - -import { StoreState } from "types"; -import { StoreStateDispatch } from "types/actions"; -import * as actions from "components/Temp/TempActions"; -import Temp from "components/Temp/TempComponent"; - -//Temp Container Component - -export function mapStateToProps(state: StoreState) { - return { - text: state.tempState.tempText, - }; -} - -export function mapDispatchToProps(dispatch: StoreStateDispatch) { - return { - buttonClicked: () => { - //console.log('clicked test!'); - dispatch(actions.asyncPressButton()); - }, - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(Temp); diff --git a/src/components/Temp/tests/TempActions.test.tsx b/src/components/Temp/tests/TempActions.test.tsx deleted file mode 100644 index 4d564cfeb1..0000000000 --- a/src/components/Temp/tests/TempActions.test.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import configureMockStore from "redux-mock-store"; -import thunk from "redux-thunk"; -import axios from "axios"; - -import * as action from "components/Temp/TempActions"; -import { defaultState } from "components/Temp/TempReducer"; - -// Create a mock redux store with the specified middlewares applied in -// an array (here, just thunk) -const createMockStore = configureMockStore([thunk]); - -// Required to check-up on what our mock Axios did during function calls -const mockAxios = axios as jest.Mocked; - -describe("TempAction Tests", () => { - let mockState = { - // Missing localize variable, but that's fine for our test - tempState: { - ...defaultState, - }, - }; - let bP: action.ButtonPressed = { - type: action.PRESS_BUTTON, - }; - - // Test whether pressButton returns a proper value - test("pressButton returns correct value", () => { - expect(action.pressButton()).toEqual(bP); - }); - - // Test whether asyncPressButton results in certain changes to state - test("asyncButtonPress correctly affects state", () => { - // Create a mock store to act on - const mockStore = createMockStore(mockState); - - // This just simplifies syntax. dispatch asyncPressButton to mockStore - // ( flag sidesteps type errors) - const mockDispatch = mockStore.dispatch(action.asyncPressButton()); - - mockDispatch - .then(() => { - // Check what actions have been executed on the mockStore, and see if it is - // equal to the array of actions provided (here, only one action is expected) - expect(mockStore.getActions()).toEqual([bP]); - - // Inspect mockAxios/axios to determine what was called on it. - // mockAxios.function.mocks.calls[X][Y]: Check the 'Y' parameter of the 'X' - // call to function. For us, saying y=0 will let us check what route was called on post. - expect(mockAxios.post).toHaveBeenCalled(); - expect(mockAxios.post.mock.calls[0][0]).toEqual("/words"); - }) - .catch(() => { - console.error("Error: dispatch failed"); - fail(); - }); - }); -}); diff --git a/src/components/Temp/tests/TempReducer.test.tsx b/src/components/Temp/tests/TempReducer.test.tsx deleted file mode 100644 index 4be461cfb2..0000000000 --- a/src/components/Temp/tests/TempReducer.test.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import * as reducer from "components/Temp/TempReducer"; -import { TempAction, PRESS_BUTTON } from "components/Temp/TempActions"; -import { StoreAction, StoreActions } from "rootActions"; - -describe("tempReducer Tests", () => { - let dummySt: reducer.TempState = reducer.defaultState; - let resultState: reducer.TempState = { - tempText: "BUTTON PRESSED! REDUX WORKING!", - }; - - let dummyAc: TempAction = { - type: PRESS_BUTTON, - }; - - // Test with no state - test("no state, expecting default state", () => { - expect(reducer.tempReducer(undefined, dummyAc)).toEqual( - reducer.defaultState - ); - }); - - // Test PRESS_BUTTON - test("default state, expecting pressed state", () => { - expect(reducer.tempReducer(dummySt, dummyAc)).toEqual(resultState); - }); - - test("passing reset action returns default state", () => { - const action: StoreAction = { - type: StoreActions.RESET, - }; - - expect(reducer.tempReducer({} as reducer.TempState, action)).toEqual( - reducer.defaultState - ); - }); -}); diff --git a/src/rootReducer.tsx b/src/rootReducer.tsx index 590aedf5fa..b30f401ab4 100644 --- a/src/rootReducer.tsx +++ b/src/rootReducer.tsx @@ -8,7 +8,6 @@ import { projectReducer } from "components/Project/ProjectReducer"; import { exportProjectReducer } from "components/ProjectExport/ExportProjectReducer"; import { createProjectReducer } from "components/ProjectScreen/CreateProject/CreateProjectReducer"; import { pronunciationsReducer } from "components/Pronunciations/PronunciationsReducer"; -import { tempReducer } from "components/Temp/TempReducer"; import { treeViewReducer } from "components/TreeView/TreeViewReducer"; import { characterInventoryReducer } from "goals/CharInventoryCreation/CharacterInventoryReducer"; import { mergeDupStepReducer } from "goals/MergeDupGoal/MergeDupStep/MergeDupStepReducer"; @@ -41,7 +40,4 @@ export const rootReducer: Reducer = combineReducers({ //character inventory goal characterInventoryState: characterInventoryReducer, - - //temporary - tempState: tempReducer, }); diff --git a/src/types/index.tsx b/src/types/index.tsx index b8d2fb2df1..49db1cb7d2 100644 --- a/src/types/index.tsx +++ b/src/types/index.tsx @@ -5,7 +5,6 @@ import { PasswordResetState } from "components/PasswordReset/reducer"; import { ExportProjectState } from "components/ProjectExport/ExportProjectReducer"; import { CreateProjectState } from "components/ProjectScreen/CreateProject/CreateProjectReducer"; import { PronunciationsState } from "components/Pronunciations/PronunciationsReducer"; -import { TempState } from "components/Temp/TempReducer"; import { TreeViewState } from "components/TreeView/TreeViewReducer"; import { CharacterInventoryState } from "goals/CharInventoryCreation/CharacterInventoryReducer"; import { MergeTreeState } from "goals/MergeDupGoal/MergeDupStep/MergeDupStepReducer"; @@ -40,7 +39,4 @@ export interface StoreState { //character inventory goal characterInventoryState: CharacterInventoryState; - - //temporary - tempState: TempState; }