Files
frontend-app-authoring/src/library-authoring/component-info/ComponentInfo.test.tsx
Braden MacDonald 8c125df9aa feat: Open Editors in a Modal (library components only) [FC-0062] (#1357)
* feat: allow opening editors in modals

* refactor: add an EditorContext

* test: update tests accordingly

* test: make testUtils call clearAllMocks() automatically :)
2024-10-07 21:04:49 -05:00

64 lines
2.2 KiB
TypeScript

import {
initializeMocks,
render,
screen,
waitFor,
} from '../../testUtils';
import { mockContentLibrary, mockLibraryBlockMetadata } from '../data/api.mocks';
import { mockBroadcastChannel } from '../../generic/data/api.mock';
import { LibraryProvider } from '../common/context';
import ComponentInfo from './ComponentInfo';
mockBroadcastChannel();
mockContentLibrary.applyMock();
mockLibraryBlockMetadata.applyMock();
jest.mock('./ComponentPreview', () => ({
__esModule: true, // Required when mocking 'default' export
default: () => <div>Mocked preview</div>,
}));
jest.mock('./ComponentManagement', () => ({
__esModule: true, // Required when mocking 'default' export
default: () => <div>Mocked management tab</div>,
}));
const withLibraryId = (libraryId: string) => ({
extraWrapper: ({ children }: { children: React.ReactNode }) => (
<LibraryProvider libraryId={libraryId}>{children}</LibraryProvider>
),
});
describe('<ComponentInfo> Sidebar', () => {
it('should show a disabled "Edit" button when the component type is not editable', async () => {
initializeMocks();
render(
<ComponentInfo usageKey={mockLibraryBlockMetadata.usageKeyThirdPartyXBlock} />,
withLibraryId(mockContentLibrary.libraryId),
);
const editButton = await screen.findByRole('button', { name: /Edit component/ });
expect(editButton).toBeDisabled();
});
it('should show a disabled "Edit" button when the library is read-only', async () => {
initializeMocks();
render(
<ComponentInfo usageKey={mockLibraryBlockMetadata.usageKeyPublished} />,
withLibraryId(mockContentLibrary.libraryIdReadOnly),
);
const editButton = await screen.findByRole('button', { name: /Edit component/ });
expect(editButton).toBeDisabled();
});
it('should show a working "Edit" button for a normal component', async () => {
initializeMocks();
render(
<ComponentInfo usageKey={mockLibraryBlockMetadata.usageKeyPublished} />,
withLibraryId(mockContentLibrary.libraryId),
);
const editButton = await screen.findByRole('button', { name: /Edit component/ });
await waitFor(() => expect(editButton).not.toBeDisabled());
});
});