From 9408632e6e7b69bd61adc4cbe1ab8fc9e936384f Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Thu, 18 Jul 2024 09:45:36 +0000 Subject: [PATCH] dashboard, make test async Signed-off-by: Aaron Chong --- packages/dashboard/package.json | 4 ++-- packages/dashboard/src/components/tests/appbar.test.tsx | 5 +++-- packages/dashboard/src/setupTests.ts | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/dashboard/package.json b/packages/dashboard/package.json index 234f584a7..a26166a64 100644 --- a/packages/dashboard/package.json +++ b/packages/dashboard/package.json @@ -16,8 +16,8 @@ "start:rmf-server:psql": "RMF_SERVER_USE_SIM_TIME=true npm run --prefix ../api-server start:psql", "start:sim": "concurrently npm:start:rmf-server npm:start:rmf npm:start:react", "storybook": "storybook dev -p 6006", - "test": "DOTENV_CONFIG_PATH=./.env jest --watch", - "test:coverage": "DOTENV_CONFIG_PATH=./.env jest --coverage", + "test": "jest --watch", + "test:coverage": "jest --coverage", "test:e2e": "cd e2e && npm test", "test:e2e:dev": "cd e2e && pnpm run test:dev" }, diff --git a/packages/dashboard/src/components/tests/appbar.test.tsx b/packages/dashboard/src/components/tests/appbar.test.tsx index 1ef132b63..64864a489 100644 --- a/packages/dashboard/src/components/tests/appbar.test.tsx +++ b/packages/dashboard/src/components/tests/appbar.test.tsx @@ -55,7 +55,7 @@ describe('AppBar', () => { expect(root.getByLabelText('user-btn')).toBeTruthy(); }); - test('logout is triggered when logout button is clicked', () => { + test('logout is triggered when logout button is clicked', async () => { const authenticator = new StubAuthenticator('test'); const appConfig: AppConfig = { authenticator, @@ -78,8 +78,9 @@ describe('AppBar', () => { , ); userEvent.click(root.getByLabelText('user-btn')); + await expect(waitFor(() => root.getByText('Logout'))).resolves.not.toThrow(); userEvent.click(root.getByText('Logout')); - expect(spy).toHaveBeenCalledTimes(1); + await expect(waitFor(() => expect(spy).toHaveBeenCalledTimes(1))).resolves.not.toThrow(); }); test('uses headerLogo from logo resources manager', async () => { diff --git a/packages/dashboard/src/setupTests.ts b/packages/dashboard/src/setupTests.ts index 7b0828bfa..57ed700b3 100644 --- a/packages/dashboard/src/setupTests.ts +++ b/packages/dashboard/src/setupTests.ts @@ -1 +1,8 @@ import '@testing-library/jest-dom'; + +const env = process.env as any; +env.REACT_APP_TRAJECTORY_SERVER = 'http://localhost'; +env.REACT_APP_AUTH_PROVIDER = ''; +env.REACT_APP_KEYCLOAK_CONFIG = ''; +env.REACT_APP_RMF_SERVER = 'http://localhost'; +env.PUBLIC_URL = 'http://localhost';