-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: convert download button to stateful button
- Loading branch information
1 parent
9260cbd
commit 3152c32
Showing
6 changed files
with
142 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import axios from 'axios'; | ||
import EnterpriseCatalogApiService from './EnterpriseCatalogAPIService'; | ||
|
||
describe('generateCsvDownloadLink', () => { | ||
test('correctly formats csv download link', () => { | ||
const options = { enterprise_catalog_query_titles: 'test' }; | ||
const query = 'somequery'; | ||
const generatedDownloadLink = EnterpriseCatalogApiService.generateCsvDownloadLink( | ||
options, | ||
query, | ||
); | ||
expect(generatedDownloadLink).toEqual( | ||
`${process.env.CATALOG_SERVICE_BASE_URL}/api/v1/enterprise-catalogs/catalog_workbook?enterprise_catalog_query_titles=test&query=${query}`, | ||
); | ||
jest.mock('axios'); | ||
|
||
describe('EnterpriseCatalogApiService', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('generateCsvDownloadLink', () => { | ||
it('makes correct axios GET request with query parameters', async () => { | ||
const options = { enterprise_catalog_query_titles: 'test' }; | ||
const query = 'somequery'; | ||
const expectedUrl = `${process.env.CATALOG_SERVICE_BASE_URL}/api/v1/enterprise-catalogs/catalog_workbook?enterprise_catalog_query_titles=test&query=somequery`; | ||
|
||
const mockResponse = { data: 'test-data' }; | ||
axios.get.mockResolvedValue(mockResponse); | ||
|
||
const result = await EnterpriseCatalogApiService.generateCsvDownloadLink(options, query); | ||
|
||
expect(axios.get).toHaveBeenCalledTimes(1); | ||
expect(axios.get).toHaveBeenCalledWith(expectedUrl, { responseType: 'blob' }); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('handles axios error', async () => { | ||
const options = { enterprise_catalog_query_titles: 'test' }; | ||
const error = new Error('Network error'); | ||
axios.get.mockRejectedValue(error); | ||
|
||
await expect( | ||
EnterpriseCatalogApiService.generateCsvDownloadLink(options), | ||
).rejects.toThrow('Network error'); | ||
}); | ||
}); | ||
}); |