-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display error message when download fails
Fix: disappearing file on edit save
- Loading branch information
Showing
7 changed files
with
78 additions
and
10 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
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
50 changes: 50 additions & 0 deletions
50
admin-frontend/src/components/announcements/__tests__/AttachmentResource.spec.ts
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,50 @@ | ||
import { fireEvent, render } from '@testing-library/vue'; | ||
import AttachmentResource from '../AttachmentResource.vue'; | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { FILE_DOWNLOAD_ERROR } from '../../../constants'; | ||
|
||
const mockDownloadFile = vi.fn(); | ||
|
||
vi.mock('../../../services/apiService', () => ({ | ||
default: { | ||
downloadFile: (...args) => mockDownloadFile(...args), | ||
}, | ||
})); | ||
|
||
const pushNotificationErrorMock = vi.fn(); | ||
vi.mock('../../../services/notificationService', () => ({ | ||
NotificationService: { | ||
pushNotificationError: (...args) => pushNotificationErrorMock(...args), | ||
}, | ||
})); | ||
|
||
describe('AttachmentResource', () => { | ||
it('should download file', async () => { | ||
const attachment = { | ||
id: 1, | ||
name: 'Test file', | ||
}; | ||
const { getByLabelText } = await render(AttachmentResource, { | ||
props: { ...attachment }, | ||
}); | ||
const link = await getByLabelText('Test file'); | ||
expect(link).toBeInTheDocument(); | ||
await fireEvent.click(link); | ||
await expect(mockDownloadFile).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it('should display error message when download fails', async () => { | ||
mockDownloadFile.mockRejectedValue(new Error('Download failed')); | ||
const attachment = { | ||
id: 1, | ||
name: 'Test file', | ||
}; | ||
const { getByLabelText } = await render(AttachmentResource, { | ||
props: { ...attachment }, | ||
}); | ||
const link = await getByLabelText('Test file'); | ||
expect(link).toBeInTheDocument(); | ||
await fireEvent.click(link); | ||
await expect(pushNotificationErrorMock).toHaveBeenCalledWith(FILE_DOWNLOAD_ERROR, '', 30000); | ||
}); | ||
}); |
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