From 73571c087432b7818343342b292f22dab6b9c261 Mon Sep 17 00:00:00 2001 From: Crash-- Date: Wed, 3 Jan 2024 10:51:42 +0100 Subject: [PATCH] test: Fix tests after the removal of useHomeShortcuts Also changed MuiCozyTheme to CozyTheme since this is the way to go (it removes a lot of warnings) --- src/components/Applications.spec.jsx | 56 ++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/components/Applications.spec.jsx b/src/components/Applications.spec.jsx index 54d11bf2ea..bc6d70b965 100644 --- a/src/components/Applications.spec.jsx +++ b/src/components/Applications.spec.jsx @@ -1,27 +1,39 @@ import React from 'react' import { render, act } from '@testing-library/react' import flag from 'cozy-flags' +import { createMockClient } from 'cozy-client/dist/mock' import AppLike from 'test/AppLike' import { Applications } from './Applications' -import useHomeShortcuts from '../hooks/useHomeShortcuts' -import MuiCozyTheme from 'cozy-ui/transpiled/react/MuiCozyTheme' +import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme' jest.mock('cozy-flags', () => { return jest.fn().mockReturnValue(null) }) -jest.mock('hooks/useHomeShortcuts', () => jest.fn().mockReturnValue([])) - -const setup = () => { - const root = render( - - - - - - ) - return { root } +const setup = ({ queries } = {}) => { + if (!queries) { + const root = render( + + + + + + ) + return { root } + } else { + const client = createMockClient({ + queries + }) + const root = render( + + + + + + ) + return { root } + } } describe('Applications', () => { @@ -44,8 +56,22 @@ describe('Applications', () => { { id: '1', name: 'toto.txt' }, { id: '2', name: 'tata.txt' } ] - useHomeShortcuts.mockImplementation(() => shortcuts) - const { root } = setup() + const { root } = setup({ + queries: { + 'home/io.cozy.files/path=magic-folder': { + lastUpdate: new Date(), + data: [{ id: 'folderId' }], + doctype: 'io.cozy.files', + hasMore: false + }, + 'home/io.cozy.files/dir_id=folderId,class=shortcut': { + lastUpdate: new Date(), + data: shortcuts, + doctype: 'io.cozy.files', + hasMore: false + } + } + }) // This is necessary since there are asynchronous effects in the // shortcut tile