mirror of
https://github.com/strapi/strapi.git
synced 2025-09-21 14:31:16 +00:00
test: add dnd tests for relation input and data manager
This commit is contained in:
parent
7f7d4efb14
commit
6cc51a06ae
@ -427,8 +427,8 @@ const ListItem = ({ data, index, style }) => {
|
||||
}
|
||||
style={{
|
||||
...style,
|
||||
bottom: style.bottom + RELATION_GUTTER,
|
||||
height: style.height - RELATION_GUTTER,
|
||||
bottom: style.bottom ?? 0 + RELATION_GUTTER,
|
||||
height: style.height ?? 0 - RELATION_GUTTER,
|
||||
}}
|
||||
>
|
||||
<BoxEllipsis minWidth={0} paddingTop={1} paddingBottom={1} paddingRight={4}>
|
||||
|
@ -151,6 +151,20 @@ describe('Content-Manager || RelationInput', () => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('should call onRelationReorder', () => {
|
||||
const spy = jest.fn();
|
||||
setup({ onRelationReorder: spy });
|
||||
|
||||
const [draggedItem, dropZone] = screen.getAllByLabelText('Drag');
|
||||
|
||||
fireEvent.dragStart(draggedItem);
|
||||
fireEvent.dragEnter(dropZone);
|
||||
fireEvent.dragOver(dropZone);
|
||||
fireEvent.drop(dropZone);
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// TODO: check if it is possible to fire scroll event here
|
||||
// test.only('should call onSearchNextPage', () => {
|
||||
// const spy = jest.fn();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import { fireEvent, render, act } from '@testing-library/react';
|
||||
import { fireEvent, render, act, screen } from '@testing-library/react';
|
||||
import { ThemeProvider, lightTheme } from '@strapi/design-system';
|
||||
import { QueryClientProvider, QueryClient } from 'react-query';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
@ -100,6 +100,7 @@ jest.mock('@strapi/helper-plugin', () => ({
|
||||
loadRelation: jest.fn(),
|
||||
connectRelation: jest.fn(),
|
||||
disconnectRelation: jest.fn(),
|
||||
reorderRelation: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
@ -388,6 +389,20 @@ describe('RelationInputDataManager', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Reorder an entity', () => {
|
||||
const { reorderRelation } = useCMEditViewDataManager();
|
||||
setup();
|
||||
|
||||
const [draggedItem, dropZone] = screen.getAllByLabelText('Drag');
|
||||
|
||||
fireEvent.dragStart(draggedItem);
|
||||
fireEvent.dragEnter(dropZone);
|
||||
fireEvent.dragOver(dropZone);
|
||||
fireEvent.drop(dropZone);
|
||||
|
||||
expect(reorderRelation).toBeCalledWith({ name: 'relation', newIndex: 0, oldIndex: 1 });
|
||||
});
|
||||
|
||||
describe('Counting relations', () => {
|
||||
it('should not render a count value when there are no relations', () => {
|
||||
useCMEditViewDataManager.mockImplementation(() => ({
|
||||
|
Loading…
x
Reference in New Issue
Block a user