Skip to content

Commit

Permalink
fix: Handle upgrading apps
Browse files Browse the repository at this point in the history
Apps can have an "upgrading" state and not just an
"installing" one. In that case, we want to display
the "Loading" tile, but then once the process is
done, we want to display the real tile and remove
the loading one.
  • Loading branch information
Crash-- committed Oct 3, 2023
1 parent 52fba09 commit 5b7fb21
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/AppTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const AppTileWrapper = ({ app }) => {
setAppInfo(fetchedAppInfo)
}

if (prevState.current === 'installing' && app.state === 'ready') {
if (
(prevState.current === 'installing' ||
prevState.current === 'upgrading') &&
app.state === 'ready'
) {
prevState.current = app.state
loadAppInfo()
}
Expand Down
46 changes: 46 additions & 0 deletions src/components/AppTile.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ const mockAppInstalling = {
state: 'installing'
}

const mockAppUpgrading = {
_id: 'mock-app-id',
name: 'mock-app-name',
slug: 'mock-app-slug',
state: 'upgrading'
}

describe('<AppTile />', () => {
it('renders loading icon when app is in installing state', () => {
const { getByText } = render(
Expand All @@ -47,6 +54,20 @@ describe('<AppTile />', () => {
expect(getByText('Installing…')).toBeInTheDocument()
})

it('renders loading icon when app is in upgrading state', () => {
const { getByText } = render(
<AppLike>
<MuiCozyTheme>
<I18n dictRequire={() => enLocale} lang="en">
<AppTileWrapper app={mockAppUpgrading} lang="en" />
</I18n>
</MuiCozyTheme>
</AppLike>
)

expect(getByText('Installing…')).toBeInTheDocument()
})

it('renders AppTile when app is in ready state', async () => {
const { queryByText } = render(
<AppLike client={mockClient}>
Expand Down Expand Up @@ -84,6 +105,31 @@ describe('<AppTile />', () => {
expect(appReadyElement).toBeInTheDocument()
})

it('updates app state from upgrading to ready and fetches app info', async () => {
const { rerender } = render(
<AppLike client={mockClient}>
<MuiCozyTheme>
<AppTileWrapper app={mockAppUpgrading} lang="en" />
</MuiCozyTheme>
</AppLike>
)

await act(async () => {
rerender(
<AppLike client={mockClient}>
<MuiCozyTheme>
<AppTileWrapper app={mockAppReady} lang="en" />
</MuiCozyTheme>
</AppLike>
)
})

const appReadyElement = await screen.findByText(
`${mockAppReady.name_prefix} ${mockAppReady.name}`
)
expect(appReadyElement).toBeInTheDocument()
})

it('does not update app state from installing to ready if app state is not ready', async () => {
const { rerender } = render(
<AppLike client={mockClient}>
Expand Down

0 comments on commit 5b7fb21

Please sign in to comment.