Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export function RecordSetAttachments<SCHEMA extends AnySchema>({
buttons={
<>
<Button.Info
disabled={
(attachmentsRef.current?.attachments.length ?? 0) === 0
}
title={attachmentsText.downloadAllDescription()}
onClick={(): void =>
recordSetId === undefined && !isComplete
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { screen } from '@testing-library/react';
import React from 'react';

import { clearIdStore } from '../../../hooks/useId';
import { requireContext } from '../../../tests/helpers';
import { mount } from '../../../tests/reactUtils';
import { f } from '../../../utils/functools';
import { LoadingContext } from '../../Core/Contexts';
import { RecordSetAttachments } from '../RecordSetAttachment';

requireContext();

beforeEach(() => {
clearIdStore();
});

describe('RecordSetAttachments', () => {
test('Download All button is disabled when there are no attachments', async () => {
jest.spyOn(console, 'warn').mockImplementation(() => {});

const mockRecord = {
specifyTable: {
name: 'TestTable',
},
populated: true,
rgetCollection: jest.fn().mockResolvedValue({
models: [],
}),
} as any;

const { user } = mount(
<LoadingContext.Provider value={f.void}>
<RecordSetAttachments
name="Test Record Set"
recordCount={1}
recordSetId={1}
records={[mockRecord]}
onFetch={undefined}
/>
</LoadingContext.Provider>
);

// Open attachments dialog
const galleryButton = screen.getByRole('button', {
name: /attachments/i,
});

await user.click(galleryButton);

// Assert dialog opens and Download All appears (but disabled)
const downloadAllButton = await screen.findByRole('button', {
name: /download all/i,
});

expect(downloadAllButton).toBeDisabled();
});
});
Loading