ML: Add truncation test for header, simplify code

This commit is contained in:
Gustav Hansen 2022-05-23 09:28:32 +02:00
parent 989f22b089
commit 5e02bd6fe6
2 changed files with 33 additions and 8 deletions

View File

@ -28,14 +28,9 @@ export const Header = ({
},
] = useQueryParams();
const { data: folderStructure, isLoading: folderStructureIsLoading } = useFolderStructure();
const isNestedFolder = folder;
const isFolder = !folderStructureIsLoading && isNestedFolder;
const folderMetadatas = isFolder && findRecursiveFolderMetadatas(folderStructure[0], folder);
const { data, isLoading } = useFolderStructure();
const isNestedFolder = !!folder;
const folderMetadatas = !isLoading && findRecursiveFolderMetadatas(data[0], folder);
const backQuery = stringify(
folderMetadatas?.parentId
? { ...queryParamsWithoutFolder, folder: folderMetadatas.parentId }

View File

@ -79,6 +79,36 @@ describe('Header', () => {
expect(container).toMatchSnapshot();
});
test('truncates long folder lavels', () => {
useQueryParams.mockReturnValueOnce([{ rawQuery: '', query: { folder: 2 } }, jest.fn()]);
useFolderStructure.mockReturnValueOnce({
isLoading: false,
error: null,
data: [
{
value: null,
label: 'Media Library',
children: [
{
value: 1,
label: 'Cats',
children: [
{
value: 2,
label: 'The length of this label exceeds the maximum',
children: [],
},
],
},
],
},
],
});
const { queryByText } = setup();
expect(queryByText('Media Library - The length of this label excee...')).toBeInTheDocument();
});
test('does not render a back button at the root level of the media library', () => {
const { queryByText } = setup();