Convert app.test reducer and reducer test to ts
parent
f3ef13a54c
commit
431de42d66
|
@ -5,20 +5,28 @@ import {notifyPresentationMode} from 'src/shared/copy/notifications'
|
|||
|
||||
import {Dispatch} from 'redux'
|
||||
|
||||
import * as AppActions from 'src/types/actions/app'
|
||||
import {
|
||||
ActionTypes,
|
||||
EnablePresentationModeAction,
|
||||
DisablePresentationModeAction,
|
||||
DelayEnablePresentationModeDispatcher,
|
||||
SetAutoRefreshActionCreator,
|
||||
SetAutoRefreshAction,
|
||||
TemplateControlBarVisibilityToggledAction,
|
||||
} from 'src/types/actions/app'
|
||||
|
||||
// ephemeral state action creators
|
||||
|
||||
export const enablePresentationMode = (): AppActions.EnablePresentationModeAction => ({
|
||||
type: 'ENABLE_PRESENTATION_MODE',
|
||||
export const enablePresentationMode = (): EnablePresentationModeAction => ({
|
||||
type: ActionTypes.EnablePresentationMode,
|
||||
})
|
||||
|
||||
export const disablePresentationMode = (): AppActions.DisablePresentationModeAction => ({
|
||||
type: 'DISABLE_PRESENTATION_MODE',
|
||||
export const disablePresentationMode = (): DisablePresentationModeAction => ({
|
||||
type: ActionTypes.DisablePresentationMode,
|
||||
})
|
||||
|
||||
export const delayEnablePresentationMode: AppActions.DelayEnablePresentationModeDispatcher = () => async (
|
||||
dispatch: Dispatch<AppActions.EnablePresentationModeAction>
|
||||
export const delayEnablePresentationMode: DelayEnablePresentationModeDispatcher = () => async (
|
||||
dispatch: Dispatch<EnablePresentationModeAction>
|
||||
): Promise<NodeJS.Timer> =>
|
||||
setTimeout(() => {
|
||||
dispatch(enablePresentationMode())
|
||||
|
@ -27,20 +35,15 @@ export const delayEnablePresentationMode: AppActions.DelayEnablePresentationMode
|
|||
|
||||
// persistent state action creators
|
||||
|
||||
export const setAutoRefresh: AppActions.SetAutoRefreshActionCreator = (
|
||||
export const setAutoRefresh: SetAutoRefreshActionCreator = (
|
||||
milliseconds: number
|
||||
): AppActions.SetAutoRefreshAction => ({
|
||||
type: 'SET_AUTOREFRESH',
|
||||
): SetAutoRefreshAction => ({
|
||||
type: ActionTypes.SetAutoRefresh,
|
||||
payload: {
|
||||
milliseconds,
|
||||
},
|
||||
})
|
||||
|
||||
export const templateControlBarVisibilityToggled = (): AppActions.TemplateControlBarVisibilityToggledAction => ({
|
||||
type: 'TEMPLATE_CONTROL_BAR_VISIBILITY_TOGGLED',
|
||||
})
|
||||
|
||||
export const noop = (): AppActions.NoopAction => ({
|
||||
type: 'NOOP',
|
||||
payload: {},
|
||||
export const templateControlBarVisibilityToggled = (): TemplateControlBarVisibilityToggledAction => ({
|
||||
type: ActionTypes.TemplateControlBarVisibilityToggled,
|
||||
})
|
||||
|
|
|
@ -9,12 +9,15 @@ import {analyzeQueries} from 'src/shared/apis'
|
|||
import {DEFAULT_DURATION_MS} from 'src/shared/constants'
|
||||
import replaceTemplates, {replaceInterval} from 'src/tempVars/utils/replace'
|
||||
import {proxy} from 'src/utils/queryUrlGenerator'
|
||||
import {noop} from 'src/shared/actions/app'
|
||||
|
||||
import {Source} from 'src/types'
|
||||
|
||||
import {Template} from 'src/types'
|
||||
|
||||
const noop = () => ({
|
||||
type: 'NOOP',
|
||||
payload: {},
|
||||
})
|
||||
interface Query {
|
||||
text: string
|
||||
database?: string
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
import {combineReducers} from 'redux'
|
||||
|
||||
import {AUTOREFRESH_DEFAULT} from 'shared/constants'
|
||||
import {AUTOREFRESH_DEFAULT} from 'src/shared/constants'
|
||||
import {ActionTypes, Action} from 'src/types/actions/app'
|
||||
|
||||
const initialState = {
|
||||
interface State {
|
||||
ephemeral: {
|
||||
inPresentationMode: boolean
|
||||
}
|
||||
persisted: {
|
||||
autoRefresh: number
|
||||
showTemplateControlBar: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
ephemeral: {
|
||||
inPresentationMode: false,
|
||||
},
|
||||
|
@ -17,16 +28,19 @@ const {
|
|||
persisted: initialAppPersistedState,
|
||||
} = initialState
|
||||
|
||||
const appEphemeralReducer = (state = initialAppEphemeralState, action) => {
|
||||
const appEphemeralReducer = (
|
||||
state = initialAppEphemeralState,
|
||||
action: Action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case 'ENABLE_PRESENTATION_MODE': {
|
||||
case ActionTypes.EnablePresentationMode: {
|
||||
return {
|
||||
...state,
|
||||
inPresentationMode: true,
|
||||
}
|
||||
}
|
||||
|
||||
case 'DISABLE_PRESENTATION_MODE': {
|
||||
case ActionTypes.DisablePresentationMode: {
|
||||
return {
|
||||
...state,
|
||||
inPresentationMode: false,
|
||||
|
@ -38,16 +52,19 @@ const appEphemeralReducer = (state = initialAppEphemeralState, action) => {
|
|||
}
|
||||
}
|
||||
|
||||
const appPersistedReducer = (state = initialAppPersistedState, action) => {
|
||||
const appPersistedReducer = (
|
||||
state = initialAppPersistedState,
|
||||
action: Action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case 'SET_AUTOREFRESH': {
|
||||
case ActionTypes.SetAutoRefresh: {
|
||||
return {
|
||||
...state,
|
||||
autoRefresh: action.payload.milliseconds,
|
||||
}
|
||||
}
|
||||
|
||||
case 'TEMPLATE_CONTROL_BAR_VISIBILITY_TOGGLED': {
|
||||
case ActionTypes.TemplateControlBarVisibilityToggled: {
|
||||
const {showTemplateControlBar} = state
|
||||
|
||||
return {...state, showTemplateControlBar: !showTemplateControlBar}
|
||||
|
@ -58,7 +75,7 @@ const appPersistedReducer = (state = initialAppPersistedState, action) => {
|
|||
}
|
||||
}
|
||||
|
||||
const appReducer = combineReducers({
|
||||
const appReducer = combineReducers<State>({
|
||||
ephemeral: appEphemeralReducer,
|
||||
persisted: appPersistedReducer,
|
||||
})
|
|
@ -1,13 +1,27 @@
|
|||
import {Dispatch} from 'redux'
|
||||
|
||||
export enum ActionTypes {
|
||||
EnablePresentationMode = 'ENABLE_PRESENTATION_MODE',
|
||||
DisablePresentationMode = 'DISABLE_PRESENTATION_MODE',
|
||||
SetAutoRefresh = 'SET_AUTOREFRESH',
|
||||
TemplateControlBarVisibilityToggled = 'TemplateControlBarVisibilityToggledAction',
|
||||
Noop = 'NOOP',
|
||||
}
|
||||
|
||||
export type Action =
|
||||
| EnablePresentationModeAction
|
||||
| DisablePresentationModeAction
|
||||
| SetAutoRefreshAction
|
||||
| TemplateControlBarVisibilityToggledAction
|
||||
|
||||
export type EnablePresentationModeActionCreator = () => EnablePresentationModeAction
|
||||
|
||||
export interface EnablePresentationModeAction {
|
||||
type: 'ENABLE_PRESENTATION_MODE'
|
||||
type: ActionTypes.EnablePresentationMode
|
||||
}
|
||||
|
||||
export interface DisablePresentationModeAction {
|
||||
type: 'DISABLE_PRESENTATION_MODE'
|
||||
type: ActionTypes.DisablePresentationMode
|
||||
}
|
||||
|
||||
export type DelayEnablePresentationModeDispatcher = () => DelayEnablePresentationModeThunk
|
||||
|
@ -21,7 +35,7 @@ export type SetAutoRefreshActionCreator = (
|
|||
) => SetAutoRefreshAction
|
||||
|
||||
export interface SetAutoRefreshAction {
|
||||
type: 'SET_AUTOREFRESH'
|
||||
type: ActionTypes.SetAutoRefresh
|
||||
payload: {
|
||||
milliseconds: number
|
||||
}
|
||||
|
@ -30,10 +44,5 @@ export interface SetAutoRefreshAction {
|
|||
export type TemplateControlBarVisibilityToggledActionCreator = () => TemplateControlBarVisibilityToggledAction
|
||||
|
||||
export interface TemplateControlBarVisibilityToggledAction {
|
||||
type: 'TEMPLATE_CONTROL_BAR_VISIBILITY_TOGGLED'
|
||||
}
|
||||
|
||||
export interface NoopAction {
|
||||
type: 'NOOP'
|
||||
payload: object
|
||||
type: ActionTypes.TemplateControlBarVisibilityToggled
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import appReducer from 'shared/reducers/app'
|
||||
import appReducer from 'src/shared/reducers/app'
|
||||
import {
|
||||
enablePresentationMode,
|
||||
disablePresentationMode,
|
||||
setAutoRefresh,
|
||||
templateControlBarVisibilityToggled,
|
||||
} from 'shared/actions/app'
|
||||
} from 'src/shared/actions/app'
|
||||
|
||||
describe('Shared.Reducers.appReducer', () => {
|
||||
const initialState = {
|
Loading…
Reference in New Issue