-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Schedules): Consolidate schedules react trees into one tree (#…
…2069) * refactor(Schedules): Consolidate schedules react trees into one tree * Added empty support and reworked data importing * Cleaned up code * Working on the tests * Rewrote tests, and working on updating react state properly * Reworked the schedule modal content tests * Fixed tests * Fixed linting * Reworked schedule loader into schedule page * Moved state management fully to react-redux * Fixed hours of operation tests * Updated schedule direction test * Removed console logs * Fixed tests for SchedulePage and the Line Diagram * Fixed ScheduleFinderModalTests * Fixed ScheduleModalContentTests * Removed un-needed import * Fixed schedulefinderformtest * Fixed schedule finder tests, and removed unsupported test * Removed old snapshots * Removed unused functions from the old schedule store * Fixed linting * Consolidated render logic to use new helper * Cleaned up comment * Fixed code covereage * Addressed PR feedback * Addressed linting * Changed schedule smoke test to support flexible directions * Actually fixed the smoke tests * Cleaned up skipped test
- Loading branch information
Showing
35 changed files
with
3,120 additions
and
3,662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
import { | ||
StoreProps, | ||
scheduleStoreReducer | ||
} from "../schedule/store/ScheduleStore"; | ||
import { Provider } from "react-redux"; | ||
import { render } from "@testing-library/react"; | ||
import { Store, createStore } from "redux"; | ||
|
||
// as allows the user to specify other things such as initialState, store. | ||
interface ExtendedRenderOptions { | ||
preloadedState?: Partial<StoreProps>; | ||
store?: Store; | ||
} | ||
|
||
const partialToStoreProps = ( | ||
preloadedState: Partial<StoreProps> | ||
): StoreProps => { | ||
return { | ||
selectedDirection: | ||
preloadedState.selectedDirection !== undefined | ||
? preloadedState.selectedDirection | ||
: 0, | ||
selectedOrigin: | ||
preloadedState.selectedOrigin !== undefined | ||
? preloadedState.selectedOrigin | ||
: "", | ||
modalOpen: !!preloadedState.modalOpen, | ||
modalMode: preloadedState.modalMode ? preloadedState.modalMode : "schedule" | ||
}; | ||
}; | ||
|
||
export const createScheduleStoreFromPartial = ( | ||
partialState: Partial<StoreProps> | ||
): Store => { | ||
const { | ||
selectedDirection, | ||
selectedOrigin, | ||
modalOpen, | ||
modalMode | ||
} = partialToStoreProps(partialState); | ||
return createStore(scheduleStoreReducer, { | ||
selectedDirection, | ||
selectedOrigin, | ||
modalOpen, | ||
modalMode | ||
}); | ||
}; | ||
|
||
export function renderWithProviders( | ||
ui: React.ReactElement, | ||
extendedRenderOptions: ExtendedRenderOptions = {} | ||
) { | ||
const { | ||
preloadedState = {}, | ||
// Automatically create a store instance if no store was passed in | ||
store = createScheduleStoreFromPartial(preloadedState), | ||
...renderOptions | ||
} = extendedRenderOptions; | ||
|
||
const Wrapper = ({ children }: PropsWithChildren<React.ReactNode>) => { | ||
return <Provider store={store}>{children}</Provider>; | ||
}; | ||
|
||
// Return an object with the store and all of RTL's query functions | ||
return { | ||
store, | ||
...render(ui, { wrapper: Wrapper, ...renderOptions }) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.