Merge pull request #15757 from GitStartHQ/fix/display-order-menuItems-multiple-relations

fix: Sometimes the children display order is incorrect in list view
This commit is contained in:
Gustav Hansen 2023-02-10 10:40:02 +01:00 committed by GitHub
commit a6db2ba38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -67,7 +67,7 @@ const RelationMultiple = ({ fieldSchema, metadatas, name, entityId, value, conte
staleTime: 0,
select: (data) => ({
...data,
results: data.results.reverse(),
results: [...data.results].reverse(),
}),
}
);

View File

@ -17,6 +17,14 @@ jest.mock('@strapi/helper-plugin', () => ({
id: 1,
name: 'Relation entity 1',
},
{
id: 2,
name: 'Relation entity 2',
},
{
id: 3,
name: 'Relation entity 3',
},
],
pagination: {
@ -85,4 +93,19 @@ describe('DynamicTable / Cellcontent / RelationMultiple', () => {
expect(get).toHaveBeenCalledTimes(1);
await waitFor(() => expect(screen.getByText('Relation entity 1')).toBeInTheDocument());
});
it('Displays related entities in reversed order', async () => {
const { container } = render(<ComponentFixture />);
const button = container.querySelector('[type=button]');
fireEvent(button, new MouseEvent('mousedown', { bubbles: true }));
await waitFor(() => {
const buttons = screen.getAllByRole('menuitem');
expect(buttons[1]).toHaveTextContent('Relation entity 3');
expect(buttons[2]).toHaveTextContent('Relation entity 2');
expect(buttons[3]).toHaveTextContent('Relation entity 1');
});
});
});