From c433a391436e07db52a6c38aaabddbd8ff0aa45d Mon Sep 17 00:00:00 2001 From: Vanessa Scherma Date: Thu, 14 Nov 2024 16:05:20 +0100 Subject: [PATCH] PR review changes --- .github/workflows/client.yml | 1 + client/config/test.js | 5 +- .../digitaltwins/DigitalTwinsPreview.test.tsx | 53 ------------------- .../create/ChangeFileNameDialog.test.tsx | 3 +- .../create/ConfirmDeleteDialog.test.tsx | 3 +- .../digitaltwins/create/CreatePage.test.tsx | 6 --- .../digitaltwins/manage/ConfigDialog.test.tsx | 26 ++++----- .../preview/unit/{util => }/Store.test.ts | 0 ...nfig.test.ts => digitalTwinConfig.test.ts} | 0 client/test/preview/unit/util/init.test.ts | 10 ---- 10 files changed, 18 insertions(+), 89 deletions(-) rename client/test/preview/unit/{util => }/Store.test.ts (100%) rename client/test/preview/unit/util/{gitlabDigitalTwinConfig.test.ts => digitalTwinConfig.test.ts} (100%) diff --git a/.github/workflows/client.yml b/.github/workflows/client.yml index 3f9ce5d32..3d78aa1fb 100644 --- a/.github/workflows/client.yml +++ b/.github/workflows/client.yml @@ -50,6 +50,7 @@ jobs: yarn test:unit yarn test:preview:unit yarn test:preview:int + yarn test:coverage:int-unit - name: Upload unit and integration test coverage to Codecov uses: codecov/codecov-action@v3 diff --git a/client/config/test.js b/client/config/test.js index 2c6ab3b2e..5d4dfbd71 100644 --- a/client/config/test.js +++ b/client/config/test.js @@ -9,10 +9,9 @@ if (typeof window !== 'undefined') { REACT_APP_WORKBENCHLINK_VSCODE: '/tools/vscode/', REACT_APP_WORKBENCHLINK_JUPYTERLAB: '/lab', REACT_APP_WORKBENCHLINK_JUPYTERNOTEBOOK: '', - REACT_APP_WORKBENCHLINK_DT_PREVIEW: '/preview/digitaltwins', - REACT_APP_CLIENT_ID: '38bf4764fad5ebb2ebbf49b4f57c7720145b61266f13bf4891ff7851dd5c6563', - REACT_APP_AUTH_AUTHORITY: 'https://maestro.cps.digit.au.dk/gitlab', + REACT_APP_CLIENT_ID: '1be55736756190b3ace4c2c4fb19bde386d1dcc748d20b47ea8cfb5935b8446c', + REACT_APP_AUTH_AUTHORITY: 'https://gitlab.com/', REACT_APP_REDIRECT_URI: 'http://localhost:4000/Library', REACT_APP_LOGOUT_REDIRECT_URI: 'http://localhost:4000/', REACT_APP_GITLAB_SCOPES: 'openid profile read_user read_repository api', diff --git a/client/test/preview/integration/route/digitaltwins/DigitalTwinsPreview.test.tsx b/client/test/preview/integration/route/digitaltwins/DigitalTwinsPreview.test.tsx index 94f307f2f..cb819bf86 100644 --- a/client/test/preview/integration/route/digitaltwins/DigitalTwinsPreview.test.tsx +++ b/client/test/preview/integration/route/digitaltwins/DigitalTwinsPreview.test.tsx @@ -34,57 +34,4 @@ describe('Digital Twins', () => { screen.getByText('The Digital Twin as a Service'), ).toBeInTheDocument(); }); - - /* - it('fetches subfolders with project id', async () => { - const gitlabInstance = mockGitlabInstance; - const dispatch = jest.fn(); - const setError = jest.fn(); - - const init = jest.spyOn(mockGitlabInstance, 'init'); - gitlabInstance.projectId = 1; - const getDTSubfolders = jest.spyOn(mockGitlabInstance, 'getDTSubfolders'); - - await functions.fetchSubfolders(gitlabInstance, dispatch, setError); - - expect(init).toHaveBeenCalled(); - expect(getDTSubfolders).toHaveBeenCalledWith(1); - expect(dispatch).toHaveBeenCalled(); - }); - - it('fetches subfolders without project id', async () => { - const gitlabInstance = mockGitlabInstance; - const dispatch = jest.fn(); - const setError = jest.fn(); - - const init = jest.spyOn(mockGitlabInstance, 'init'); - gitlabInstance.projectId = null; - const getDTSubfolders = jest.spyOn(mockGitlabInstance, 'getDTSubfolders'); - - await functions.fetchSubfolders(gitlabInstance, dispatch, setError); - - expect(init).toHaveBeenCalled(); - expect(getDTSubfolders).not.toHaveBeenCalled(); - expect(dispatch).toHaveBeenCalled(); - }); - - it('fetches subfolders with error', async () => { - const gitlabInstance = mockGitlabInstance; - const dispatch = jest.fn(); - const setError = jest.fn(); - - const init = jest.spyOn(mockGitlabInstance, 'init'); - gitlabInstance.projectId = 1; - const getDTSubfolders = jest - .spyOn(mockGitlabInstance, 'getDTSubfolders') - .mockRejectedValue(new Error('error')); - - await functions.fetchSubfolders(gitlabInstance, dispatch, setError); - - expect(init).toHaveBeenCalled(); - expect(getDTSubfolders).toHaveBeenCalledWith(1); - expect(dispatch).not.toHaveBeenCalled(); - expect(setError).toHaveBeenCalledWith('An error occurred'); - }); - */ }); diff --git a/client/test/preview/integration/route/digitaltwins/create/ChangeFileNameDialog.test.tsx b/client/test/preview/integration/route/digitaltwins/create/ChangeFileNameDialog.test.tsx index bebee8b4e..29e1f4de5 100644 --- a/client/test/preview/integration/route/digitaltwins/create/ChangeFileNameDialog.test.tsx +++ b/client/test/preview/integration/route/digitaltwins/create/ChangeFileNameDialog.test.tsx @@ -1,10 +1,9 @@ import * as React from 'react'; import ChangeFileNameDialog from 'preview/route/digitaltwins/create/ChangeFileNameDialog'; import { Provider } from 'react-redux'; -import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; import { combineReducers, configureStore } from '@reduxjs/toolkit'; import fileSlice from 'preview/store/file.slice'; -import { act } from 'react'; const store = configureStore({ reducer: combineReducers({ diff --git a/client/test/preview/integration/route/digitaltwins/create/ConfirmDeleteDialog.test.tsx b/client/test/preview/integration/route/digitaltwins/create/ConfirmDeleteDialog.test.tsx index 7256f33bf..979d927d1 100644 --- a/client/test/preview/integration/route/digitaltwins/create/ConfirmDeleteDialog.test.tsx +++ b/client/test/preview/integration/route/digitaltwins/create/ConfirmDeleteDialog.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import ConfirmDeleteDialog from 'preview/route/digitaltwins/create/ConfirmDeleteDialog'; -import { act } from 'react'; -import { render, screen } from '@testing-library/react'; +import { act, render, screen } from '@testing-library/react'; import { combineReducers, configureStore } from '@reduxjs/toolkit'; import { Provider } from 'react-redux'; import fileSlice, { addOrUpdateFile } from 'preview/store/file.slice'; diff --git a/client/test/preview/integration/route/digitaltwins/create/CreatePage.test.tsx b/client/test/preview/integration/route/digitaltwins/create/CreatePage.test.tsx index 9dddd4a1a..94cf56e9f 100644 --- a/client/test/preview/integration/route/digitaltwins/create/CreatePage.test.tsx +++ b/client/test/preview/integration/route/digitaltwins/create/CreatePage.test.tsx @@ -45,12 +45,6 @@ describe('CreatePage', () => { jest.clearAllMocks(); }); - /* - it('renders CreatePage', () => { - expect(screen.getByText('Please select a file to edit')).toBeInTheDocument(); - }); - */ - it('handles cancel when clicking on cancel button and confirm', () => { act(() => { screen.getByText('Cancel').click(); diff --git a/client/test/preview/integration/route/digitaltwins/manage/ConfigDialog.test.tsx b/client/test/preview/integration/route/digitaltwins/manage/ConfigDialog.test.tsx index 374646940..03bab4b94 100644 --- a/client/test/preview/integration/route/digitaltwins/manage/ConfigDialog.test.tsx +++ b/client/test/preview/integration/route/digitaltwins/manage/ConfigDialog.test.tsx @@ -1,5 +1,5 @@ import AssetBoard from 'preview/components/asset/AssetBoard'; -import { render, screen, waitFor } from '@testing-library/react'; +import { act, render, screen, waitFor } from '@testing-library/react'; import { Provider } from 'react-redux'; import * as React from 'react'; import DigitalTwin from 'preview/util/digitalTwin'; @@ -28,7 +28,7 @@ describe('ReconfigureDialog', () => { dispatchSpy = jest.spyOn(storeConfig, 'dispatch'); - React.act(() => { + act(() => { render( @@ -46,17 +46,17 @@ describe('ReconfigureDialog', () => { const reconfigureButton = screen.getByRole('button', { name: /Reconfigure/i, }); - await React.act(async () => { + await act(async () => { reconfigureButton.click(); }); const cancelButton = await screen.findByRole('button', { name: /Cancel/i }); - await React.act(async () => { + await act(async () => { cancelButton.click(); }); const noButton = await screen.findByRole('button', { name: /No/i }); - await React.act(async () => { + await act(async () => { noButton.click(); }); @@ -70,17 +70,17 @@ describe('ReconfigureDialog', () => { const reconfigureButton = screen.getByRole('button', { name: /Reconfigure/i, }); - await React.act(async () => { + await act(async () => { reconfigureButton.click(); }); const cancelButton = await screen.findByRole('button', { name: /Cancel/i }); - await React.act(async () => { + await act(async () => { cancelButton.click(); }); const yesButton = await screen.findByRole('button', { name: /Yes/i }); - await React.act(async () => { + await act(async () => { yesButton.click(); }); @@ -102,24 +102,24 @@ describe('ReconfigureDialog', () => { isModified: true, }; - React.act(() => { + act(() => { storeConfig.dispatch(addOrUpdateFile(modifiedFile)); }); const reconfigureButton = screen.getByRole('button', { name: /Reconfigure/i, }); - await React.act(async () => { + await act(async () => { reconfigureButton.click(); }); const saveButton = await screen.findByRole('button', { name: /Save/i }); - await React.act(async () => { + await act(async () => { saveButton.click(); }); const yesButton = await screen.findByRole('button', { name: /Yes/i }); - await React.act(async () => { + await act(async () => { yesButton.click(); }); @@ -150,7 +150,7 @@ describe('ReconfigureDialog', () => { .spyOn(digitalTwin.DTAssets, 'updateFileContent') .mockRejectedValue(new Error('Mocked error')); - await React.act(async () => { + await act(async () => { await ReconfigureDialog.handleFileUpdate(file, digitalTwin, dispatch); }); diff --git a/client/test/preview/unit/util/Store.test.ts b/client/test/preview/unit/Store.test.ts similarity index 100% rename from client/test/preview/unit/util/Store.test.ts rename to client/test/preview/unit/Store.test.ts diff --git a/client/test/preview/unit/util/gitlabDigitalTwinConfig.test.ts b/client/test/preview/unit/util/digitalTwinConfig.test.ts similarity index 100% rename from client/test/preview/unit/util/gitlabDigitalTwinConfig.test.ts rename to client/test/preview/unit/util/digitalTwinConfig.test.ts diff --git a/client/test/preview/unit/util/init.test.ts b/client/test/preview/unit/util/init.test.ts index be2ee64cf..02acb61c4 100644 --- a/client/test/preview/unit/util/init.test.ts +++ b/client/test/preview/unit/util/init.test.ts @@ -72,14 +72,4 @@ describe('fetchAssets', () => { expect(dispatch).toHaveBeenCalledWith(setAssets([])); }); - - /* - it('should init gitlabinstance and return digital twin', async () => { - (mockGitlabInstance.init as jest.Mock).mockResolvedValue({}); - - const digitalTwin = await initDigitalTwin('testName'); - - expect(digitalTwin).toBe(mockDigitalTwin); -}); - */ });