mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-25 06:46:59 +00:00
- Refactored `DownloadAll` component to utilize platform capabilities for download types, improving flexibility in handling various download methods. - Introduced `buildEnabledDownloadModes` function to determine available download modes based on user settings and platform capabilities. - Updated `FileRow` and `PanelGeneral` components to conditionally render download options based on platform capabilities. - Added tests for new functionalities in `DownloadAll`, `FileRow`, and `PanelGeneral` to ensure correct behavior under different platform conditions. - Enhanced error handling for unsupported download methods, providing clearer feedback to users.
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { BatchDownloadType } from '~/platform/capabilities';
|
|
import { buildEnabledDownloadModes } from '~/platform/buildEnabledDownloadModes';
|
|
import type { BatchDownloadSettings } from '~/features/settings/settingsSlice';
|
|
|
|
const allOn: Pick<BatchDownloadSettings, 'directoryPicker' | 'streamingZip' | 'blobZip'> = {
|
|
directoryPicker: true,
|
|
streamingZip: true,
|
|
blobZip: true,
|
|
};
|
|
|
|
const allOff: Pick<BatchDownloadSettings, 'directoryPicker' | 'streamingZip' | 'blobZip'> = {
|
|
directoryPicker: false,
|
|
streamingZip: false,
|
|
blobZip: false,
|
|
};
|
|
|
|
describe('buildEnabledDownloadModes', () => {
|
|
test('intersects settings with capabilities in fallback order', () => {
|
|
expect(
|
|
buildEnabledDownloadModes(allOn, [
|
|
BatchDownloadType.SelectDirectory,
|
|
BatchDownloadType.StreamZip,
|
|
BatchDownloadType.PackZip,
|
|
]),
|
|
).toEqual([BatchDownloadType.SelectDirectory, BatchDownloadType.StreamZip, BatchDownloadType.PackZip]);
|
|
});
|
|
|
|
test('omits modes disabled in settings even when capable', () => {
|
|
expect(
|
|
buildEnabledDownloadModes({ directoryPicker: false, streamingZip: true, blobZip: true }, [
|
|
BatchDownloadType.SelectDirectory,
|
|
BatchDownloadType.StreamZip,
|
|
BatchDownloadType.PackZip,
|
|
]),
|
|
).toEqual([BatchDownloadType.StreamZip, BatchDownloadType.PackZip]);
|
|
});
|
|
|
|
test('omits modes missing from capabilities even when enabled in settings', () => {
|
|
expect(buildEnabledDownloadModes(allOn, [BatchDownloadType.PackZip])).toEqual([BatchDownloadType.PackZip]);
|
|
});
|
|
|
|
test('returns empty when no overlap', () => {
|
|
expect(buildEnabledDownloadModes(allOff, [BatchDownloadType.PackZip])).toEqual([]);
|
|
expect(buildEnabledDownloadModes(allOn, [])).toEqual([]);
|
|
});
|
|
});
|