-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dataDownloadListActions): Updated unit tests
- Loading branch information
1 parent
f5e8476
commit 30d9119
Showing
4 changed files
with
86 additions
and
6 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
61 changes: 61 additions & 0 deletions
61
...yDetails/DataDownloadList/ActionButtons/DownloadUtils/HandleDownloadManifestClick.test.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,61 @@ | ||
import HandleDownloadManifestClick from './HandleDownloadManifestClick'; | ||
import DownloadJsonFile from './DownloadJsonFile'; | ||
import { DiscoveryConfig } from '../../../../DiscoveryConfig'; | ||
|
||
// Mock the DownloadJsonFile module | ||
jest.mock('./DownloadJsonFile'); | ||
|
||
describe('HandleDownloadManifestClick', () => { | ||
it('should not call DownloadJsonFile when healICPSRLoginNeeded is true', () => { | ||
// Mock data | ||
const config = { | ||
features: { | ||
exportToWorkspace: { | ||
manifestFieldName: 'manifestFieldName', | ||
}, | ||
}, | ||
} as DiscoveryConfig; | ||
const selectedResources = [{ manifestFieldName: [{ item: 'value' }] }]; | ||
const healICPSRLoginNeeded = true; | ||
|
||
// Call the function | ||
HandleDownloadManifestClick(config, selectedResources, healICPSRLoginNeeded); | ||
|
||
// Assertions | ||
expect(DownloadJsonFile).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw an error when manifestFieldName is missing in the configuration', () => { | ||
// Mock data | ||
const config = { | ||
features: { | ||
exportToWorkspace: {}, | ||
}, | ||
} as DiscoveryConfig; | ||
const selectedResources = [{ manifestFieldName: [{ item: 'value' }] }]; | ||
const healICPSRLoginNeeded = false; | ||
|
||
// Assertions | ||
expect(() => HandleDownloadManifestClick(config, selectedResources, healICPSRLoginNeeded)).toThrowError( | ||
'Missing required configuration field `config.features.exportToWorkspace.manifestFieldName`', | ||
); | ||
}); | ||
it('should call DownloadJsonFile with the correct arguments when healICPSRLoginNeeded is false', () => { | ||
// Mock data | ||
const config = { | ||
features: { | ||
exportToWorkspace: { | ||
manifestFieldName: 'manifestFieldName', | ||
}, | ||
}, | ||
} as DiscoveryConfig; | ||
const selectedResources = [{ manifestFieldName: [{ item: 'value' }] }]; | ||
const healICPSRLoginNeeded = false; | ||
|
||
// Call the function | ||
HandleDownloadManifestClick(config, selectedResources, healICPSRLoginNeeded); | ||
|
||
// Assertions | ||
expect(DownloadJsonFile).toHaveBeenCalledWith('manifest', [{ item: 'value' }]); | ||
}); | ||
}); |
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