Skip to content

Commit

Permalink
call the actions instead of the sagas
Browse files Browse the repository at this point in the history
  • Loading branch information
josephaxisa committed Apr 20, 2023
1 parent 8bdd542 commit 5486cef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/embed-components/src/Theme/SelectTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const SelectTheme = () => {
return (
<SpaceVertical gap="xxxsmall">
<Select
disabled={themes.length === 1}
disabled={themes.length <= 1}
isLoading={!initialized || working}
validationType={error ? 'error' : undefined}
value={selectedTheme.name}
Expand Down
21 changes: 6 additions & 15 deletions packages/embed-components/src/Theme/state/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,15 @@ describe('SelectTheme sagas', () => {
})

describe('selectThemeSaga', () => {
const {
selectThemeAction,
getThemesSuccessAction,
getDefaultThemeSuccessAction,
selectThemeSuccessAction,
setFailureAction,
} = themeActions
const { selectThemeAction, selectThemeSuccessAction, setFailureAction } =
themeActions

it('sends selectThemeSuccessAction on success', async () => {
registerThemeService()
const service = getThemeService()
const selectedTheme = { name: 'Looker', id: '1' } as ITheme

jest.spyOn(service, 'expired').mockReturnValue(false)
const getSpy = jest
.spyOn(service, 'get')
.mockResolvedValueOnce(selectedTheme)
Expand All @@ -263,18 +260,12 @@ describe('SelectTheme sagas', () => {

await sagaTester.waitFor('themes/selectThemeSuccessAction')
const calledActions = sagaTester.getCalledActions()
expect(calledActions).toHaveLength(4)
expect(calledActions).toHaveLength(2)
expect(calledActions[0]).toEqual(
selectThemeAction({ id: selectedTheme.id! })
)
expect(calledActions[1]).toEqual(
getThemesSuccessAction({ themes: service.items })
)
expect(calledActions[2]).toEqual(
getDefaultThemeSuccessAction({ defaultTheme: selectedTheme })
)
expect(getSpy).toHaveBeenCalledWith(selectedTheme.id)
expect(calledActions[3]).toEqual(
expect(calledActions[1]).toEqual(
selectThemeSuccessAction({ selectedTheme })
)
})
Expand Down
11 changes: 8 additions & 3 deletions packages/embed-components/src/Theme/state/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ function* getDefaultThemeSaga() {
* @param action containing id of theme to select
*/
function* selectThemeSaga(action: PayloadAction<SelectThemeAction>) {
const { selectThemeSuccessAction, setFailureAction } = themeActions
const {
selectThemeSuccessAction,
getThemesAction,
getDefaultThemeAction,
setFailureAction,
} = themeActions
try {
const service = getThemeService()
if (service.expired()) {
yield* call(getThemesSaga)
yield* call(getDefaultThemeSaga)
yield* call(getThemesAction)
yield* call(getDefaultThemeAction)
}
const selectedTheme = yield* call([service, 'get'], action.payload.id)
yield* put(selectThemeSuccessAction({ selectedTheme }))
Expand Down
1 change: 0 additions & 1 deletion packages/embed-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@
*/
export * from './GlobalStore'
export * from './QuickEmbed'
export * from './Theme'

0 comments on commit 5486cef

Please sign in to comment.