Skip to content

Commit

Permalink
refactor(backup): adds test for error messages
Browse files Browse the repository at this point in the history
Refs: #347
  • Loading branch information
GentlemanHal committed Jun 16, 2023
1 parent bee1249 commit d4a2426
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions src/client/settings/backup/export/ExportRemotePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jest.mock('../../../configuration/ReduxStore', () => {
}
})

it('should export configuration', async () => {
it('should show an error message if configuration can not be exported', async () => {
const remoteLocation = buildRemoteBackupLocation({
internalId: 'locationId',
externalId: 'some-remote-id',
Expand All @@ -37,9 +37,9 @@ it('should export configuration', async () => {
},
},
}
jest.spyOn(BackupGateway, 'exportConfiguration').mockResolvedValueOnce({
id: 'some-remote-id',
})
jest
.spyOn(BackupGateway, 'exportConfiguration')
.mockRejectedValueOnce(new Error('Some error message'))

const { user } = render(<ExportRemotePage />, {
state,
Expand All @@ -49,13 +49,47 @@ it('should export configuration', async () => {
await user.click(screen.getByRole('button', { name: 'Export' }))

await waitFor(() => {
expect(
screen.getByText('Successfully exported configuration')
).toBeInTheDocument()
expect(screen.getByText('Some error message')).toBeInTheDocument()
})
expect(BackupGateway.exportConfiguration).toHaveBeenCalledTimes(1)
})

it('should show an error message if the 2nd export fails', async () => {
const remoteLocation = buildRemoteBackupLocation({
where: RemoteLocationOptions.gitHub,
internalId: 'locationId',
externalId: '',
})
const state = {
[remoteLocationsRoot]: {
locationId: remoteLocation,
},
[personalSettingsRoot]: {
backupRemoteLocations: {
locationId: {},
},
},
}
jest
.spyOn(BackupGateway, 'exportConfiguration')
.mockResolvedValueOnce({ id: 'external-id' })
.mockRejectedValueOnce(new Error('Some error message'))

const { user, store } = render(<ExportRemotePage />, {
state,
outletContext: remoteLocation,
})

mockSomeConstantValueGetter.mockReturnValueOnce(store)

await user.click(screen.getByRole('button', { name: 'Export' }))

await waitFor(() => {
expect(screen.getByText('Some error message')).toBeInTheDocument()
})
expect(BackupGateway.exportConfiguration).toHaveBeenCalledTimes(2)
})

it.each([RemoteLocationOptions.gitHub, RemoteLocationOptions.gitLab])(
'should export configuration to a new %s location twice to make sure the exported configuration contains the external ID',
async (where) => {
Expand Down

0 comments on commit d4a2426

Please sign in to comment.