|
1 | 1 | import { act, renderHook, waitFor } from '@testing-library/react' |
| 2 | +import { ReadError } from '@iqss/dataverse-client-javascript' |
2 | 3 | import { useUploadLimit } from '@/sections/shared/file-uploader/file-upload-input/useUploadLimit' |
3 | 4 | import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' |
4 | 5 |
|
@@ -43,4 +44,46 @@ describe('useUploadLimit', () => { |
43 | 44 | expect(result.current.uploadLimit).to.deep.equal({}) |
44 | 45 | }) |
45 | 46 | }) |
| 47 | + |
| 48 | + describe('Error handling', () => { |
| 49 | + it('returns the ReadError message when upload limits fetch fails with ReadError', async () => { |
| 50 | + const fetchUploadLimits = cy.stub().rejects(new ReadError('Error message')) |
| 51 | + |
| 52 | + const { result } = renderHook(() => |
| 53 | + useUploadLimit(DATASET_PERSISTENT_ID, datasetRepository, fetchUploadLimits) |
| 54 | + ) |
| 55 | + |
| 56 | + await act(() => { |
| 57 | + expect(result.current.isLoadingUploadLimits).to.deep.equal(true) |
| 58 | + return expect(result.current.errorUploadLimits).to.deep.equal(null) |
| 59 | + }) |
| 60 | + |
| 61 | + await act(() => { |
| 62 | + expect(result.current.isLoadingUploadLimits).to.deep.equal(false) |
| 63 | + expect(result.current.uploadLimit).to.deep.equal({}) |
| 64 | + return expect(result.current.errorUploadLimits).to.deep.equal('Error message') |
| 65 | + }) |
| 66 | + }) |
| 67 | + |
| 68 | + it('returns the default error message when upload limits fetch fails with a non-ReadError', async () => { |
| 69 | + const fetchUploadLimits = cy.stub().rejects('Error message') |
| 70 | + |
| 71 | + const { result } = renderHook(() => |
| 72 | + useUploadLimit(DATASET_PERSISTENT_ID, datasetRepository, fetchUploadLimits) |
| 73 | + ) |
| 74 | + |
| 75 | + await act(() => { |
| 76 | + expect(result.current.isLoadingUploadLimits).to.deep.equal(true) |
| 77 | + return expect(result.current.errorUploadLimits).to.deep.equal(null) |
| 78 | + }) |
| 79 | + |
| 80 | + await act(() => { |
| 81 | + expect(result.current.isLoadingUploadLimits).to.deep.equal(false) |
| 82 | + expect(result.current.uploadLimit).to.deep.equal({}) |
| 83 | + return expect(result.current.errorUploadLimits).to.deep.equal( |
| 84 | + 'Something went wrong getting the upload limits. Try again later.' |
| 85 | + ) |
| 86 | + }) |
| 87 | + }) |
| 88 | + }) |
46 | 89 | }) |
0 commit comments