test: fix test warning regarding async suspension rendering

This commit is contained in:
鲁树人 2023-05-21 18:08:42 +01:00
parent 4cfc672646
commit 1fb7a81c63
2 changed files with 17 additions and 5 deletions

View File

@ -1,7 +1,7 @@
import { InfoOutlineIcon } from '@chakra-ui/icons';
import { Tooltip, VStack, Text, Flex } from '@chakra-ui/react';
import { workerClientBus } from './decrypt-worker/client.ts';
import { DECRYPTION_WORKER_ACTION_NAME } from './decrypt-worker/constants';
import { workerClientBus } from '~/decrypt-worker/client';
import { DECRYPTION_WORKER_ACTION_NAME } from '~/decrypt-worker/constants';
import usePromise from 'react-promise-suspense';
@ -11,8 +11,9 @@ const getSDKVersion = async (): Promise<string> => {
export function SDKVersion() {
const sdkVersion = usePromise(getSDKVersion, []);
return (
<Flex as="span" pl="1" alignItems="center">
<Flex as="span" pl="1" alignItems="center" data-testid="sdk-version">
<Tooltip
hasArrow
placement="top"

View File

@ -1,9 +1,20 @@
import { renderWithProviders, screen, waitFor } from '~/test-utils/test-helper';
import App from '~/App';
import { renderWithProviders, screen } from '~/test-utils/test-helper';
test('should be able to render App', () => {
vi.mock('../decrypt-worker/client', () => {
return {
workerClientBus: {
request: vi.fn().mockResolvedValue('dummy'),
},
};
});
test('should be able to render App', async () => {
renderWithProviders(<App />);
// Should eventually load sdk version
await waitFor(() => screen.getByTestId('sdk-version'));
// Quick sanity check of known strings.
expect(screen.getByText(/仅在浏览器内对文件进行解锁/i)).toBeInTheDocument();
expect(screen.getByText(/UnlockMusic 团队/i)).toBeInTheDocument();