Skip to content

Commit

Permalink
Add test cases to the search input
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelhalimkhouas committed Jan 11, 2024
1 parent 5bf2513 commit 9b3192a
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions src/tests/LeftPanel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDataTestId } from '@chili-publish/grafx-shared-components';
import EditorSDK from '@chili-publish/studio-sdk';
import { render, waitFor } from '@testing-library/react';
import { render, waitFor, screen } from '@testing-library/react';
import { mock } from 'jest-mock-extended';
import { act } from 'react-dom/test-utils';
import LeftPanel from '../components/layout-panels/leftPanel/LeftPanel';
Expand All @@ -10,11 +10,11 @@ import { mockConnectors } from './mocks/mockConnectors';
import { variables } from './mocks/mockVariables';
import { getDataTestIdForSUI } from '../utils/dataIds';

jest.mock('@chili-publish/studio-sdk');
const mockSDK = mock<EditorSDK>();

beforeEach(() => {
jest.mock('@chili-publish/studio-sdk');
const mockSDK = mock<EditorSDK>();
global.URL.createObjectURL = jest.fn();

mockSDK.mediaConnector.query = jest
.fn()
.mockImplementation()
Expand Down Expand Up @@ -207,4 +207,58 @@ describe('Image Panel', () => {
expect(window.SDK.variable.setImageVariableConnector).toBeCalledTimes(1);
expect(window.SDK.variable.setValue).toBeCalledTimes(1);
});
test('Do not render search input when filtering is not supported', async () => {
mockSDK.mediaConnector.getCapabilities = jest
.fn()
.mockImplementation()
.mockReturnValue(
Promise.resolve({
parsedData: {
copy: false,
detail: true,
filtering: false,
query: true,
remove: false,
upload: false,
},
}),
);

const { getAllByTestId, getAllByRole } = render(
<VariablePanelContextProvider connectors={mockConnectors}>
<LeftPanel variables={variables} isDocumentLoaded />
</VariablePanelContextProvider>,
);
const imagePicker = await waitFor(() => getAllByTestId(getDataTestId('image-picker-content'))[0]);
await act(async () => {
imagePicker.click();
});
const image = getAllByRole('img', { name: /grafx/i })[0];

await act(async () => {
image.click();
});

const input = screen.queryByTestId(getDataTestIdForSUI('media-panel-search-input'));
expect(input).toBeNull();
});
test('Render search input when filtering is supported', async () => {
const { getAllByTestId, getAllByRole, getByTestId } = render(
<VariablePanelContextProvider connectors={mockConnectors}>
<LeftPanel variables={variables} isDocumentLoaded />
</VariablePanelContextProvider>,
);
const imagePicker = await waitFor(() => getAllByTestId(getDataTestId('image-picker-content'))[0]);
await act(async () => {
imagePicker.click();
});
const image = getAllByRole('img', { name: /grafx/i })[0];

await act(async () => {
image.click();
});

const input = getByTestId(getDataTestIdForSUI('media-panel-search-input'));
expect(input).toBeInTheDocument();
});
});

0 comments on commit 9b3192a

Please sign in to comment.