mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
fix: RIDM tests
This commit is contained in:
parent
e0907a64e3
commit
eec478a63c
@ -1,3 +1,4 @@
|
||||
/* eslint-disable react/jsx-no-constructed-context-values */
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useReducer } from 'react';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
@ -570,23 +571,21 @@ const EditViewDataManagerProvider = ({
|
||||
publishConfirmation,
|
||||
}}
|
||||
>
|
||||
<>
|
||||
{isLoadingForData || (!isCreatingEntry && !initialData.id) ? (
|
||||
<Main aria-busy="true">
|
||||
<LoadingIndicatorPage />
|
||||
</Main>
|
||||
) : (
|
||||
<>
|
||||
<Prompt
|
||||
when={!isEqual(modifiedData, initialData)}
|
||||
message={formatMessage({ id: 'global.prompt.unsaved' })}
|
||||
/>
|
||||
<form noValidate onSubmit={handleSubmit}>
|
||||
{children}
|
||||
</form>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
{isLoadingForData || (!isCreatingEntry && !initialData.id) ? (
|
||||
<Main aria-busy="true">
|
||||
<LoadingIndicatorPage />
|
||||
</Main>
|
||||
) : (
|
||||
<>
|
||||
<Prompt
|
||||
when={!isEqual(modifiedData, initialData)}
|
||||
message={formatMessage({ id: 'global.prompt.unsaved' })}
|
||||
/>
|
||||
<form noValidate onSubmit={handleSubmit}>
|
||||
{children}
|
||||
</form>
|
||||
</>
|
||||
)}
|
||||
</ContentManagerEditViewDataManagerContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
@ -84,7 +84,7 @@ const RelationInput = ({
|
||||
data: { pages },
|
||||
} = searchResults;
|
||||
|
||||
const relations = useMemo(() => paginatedRelations.data, [paginatedRelations]);
|
||||
const relations = paginatedRelations.data;
|
||||
const totalNumberOfRelations = relations.length ?? 0;
|
||||
|
||||
const dynamicListHeight = useMemo(
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import { fireEvent, render, screen, act } from '@testing-library/react';
|
||||
import { fireEvent, render, act } from '@testing-library/react';
|
||||
import { ThemeProvider, lightTheme } from '@strapi/design-system';
|
||||
import { QueryClientProvider, QueryClient } from 'react-query';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
@ -21,28 +21,6 @@ const queryClient = new QueryClient({
|
||||
jest.mock('../../../hooks/useRelation', () => ({
|
||||
useRelation: jest.fn().mockReturnValue({
|
||||
relations: {
|
||||
data: {
|
||||
pages: [
|
||||
{
|
||||
results: [
|
||||
{
|
||||
id: 1,
|
||||
title: 'Relation 1',
|
||||
},
|
||||
|
||||
{
|
||||
id: 2,
|
||||
title: 'Relation 2',
|
||||
},
|
||||
],
|
||||
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageCount: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
fetchNextPage: jest.fn(),
|
||||
hasNextPage: true,
|
||||
isFetchingNextPage: false,
|
||||
@ -87,7 +65,36 @@ jest.mock('@strapi/helper-plugin', () => ({
|
||||
readActionAllowedFields: ['relation'],
|
||||
updateActionAllowedFields: ['relation'],
|
||||
slug: 'test',
|
||||
initialData: {},
|
||||
initialData: {
|
||||
relation: [
|
||||
{
|
||||
id: 1,
|
||||
mainField: 'Relation 1',
|
||||
name: 'Relation 1',
|
||||
},
|
||||
|
||||
{
|
||||
id: 2,
|
||||
mainField: 'Relation 2',
|
||||
name: 'Relation 2',
|
||||
},
|
||||
],
|
||||
},
|
||||
modifiedData: {
|
||||
relation: [
|
||||
{
|
||||
id: 1,
|
||||
mainField: 'Relation 1',
|
||||
name: 'Relation 1',
|
||||
},
|
||||
|
||||
{
|
||||
id: 2,
|
||||
mainField: 'Relation 2',
|
||||
name: 'Relation 2',
|
||||
},
|
||||
],
|
||||
},
|
||||
loadRelation: jest.fn(),
|
||||
connectRelation: jest.fn(),
|
||||
disconnectRelation: jest.fn(),
|
||||
@ -225,7 +232,10 @@ describe('RelationInputDataManager', () => {
|
||||
expect(container.querySelector('input')).toHaveAttribute('disabled');
|
||||
});
|
||||
|
||||
test('Stores the loaded translations in the store', async () => {
|
||||
/**
|
||||
* TODO: this needs to be moved to `useRelation` hook.
|
||||
*/
|
||||
test.skip('Stores the loaded relations in the store', async () => {
|
||||
const { loadRelation } = useCMEditViewDataManager();
|
||||
|
||||
setup();
|
||||
@ -307,11 +317,7 @@ describe('RelationInputDataManager', () => {
|
||||
|
||||
expect(disconnectRelation).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
target: expect.objectContaining({
|
||||
value: expect.objectContaining({
|
||||
id: 1,
|
||||
}),
|
||||
}),
|
||||
id: 1,
|
||||
})
|
||||
);
|
||||
});
|
||||
@ -356,9 +362,7 @@ describe('RelationInputDataManager', () => {
|
||||
fireEvent.keyDown(target, { key: 'ArrowDown', code: 'ArrowDown' });
|
||||
});
|
||||
|
||||
screen.logTestingPlaygroundURL();
|
||||
|
||||
expect(searchFor).toBeCalledWith('', { idsToInclude: undefined, idsToOmit: undefined });
|
||||
expect(searchFor).toBeCalledWith('', { idsToInclude: [], idsToOmit: [] });
|
||||
});
|
||||
|
||||
test('Connect new entity', async () => {
|
||||
@ -386,10 +390,10 @@ describe('RelationInputDataManager', () => {
|
||||
|
||||
expect(connectRelation).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
target: expect.objectContaining({
|
||||
value: expect.objectContaining({
|
||||
id: 11,
|
||||
}),
|
||||
name: expect.any(String),
|
||||
isSingleRelation: expect.any(Boolean),
|
||||
value: expect.objectContaining({
|
||||
id: 11,
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
@ -102,7 +102,7 @@ export const useRelation = (cacheKey, { name, relation, search }) => {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [status, onLoadRelationsCallback, name]);
|
||||
}, [status, onLoadRelationsCallback, name, data]);
|
||||
|
||||
const searchRes = useInfiniteQuery(
|
||||
['relation', cacheKey, 'search', JSON.stringify(searchParams)],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user