Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessa committed Sep 11, 2024
1 parent 5276ffb commit 6722838
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 55 deletions.
7 changes: 6 additions & 1 deletion client/src/components/asset/AssetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,9 @@ function AssetCardExecute({ asset }: AssetCardProps) {
);
}

export { AssetCardManage, AssetCardExecute, CardButtonsContainerManage, CardButtonsContainerExecute};
export {
AssetCardManage,
AssetCardExecute,
CardButtonsContainerManage,
CardButtonsContainerExecute,
};
3 changes: 1 addition & 2 deletions client/test/unit/components/asset/AssetBoard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { GitlabInstance } from 'util/gitlab';
import '@testing-library/jest-dom';
import { Provider } from 'react-redux';
import { createStore, combineReducers } from 'redux';
import assetsReducer from 'store/assets.slice';
import assetsReducer, { deleteAsset } from 'store/assets.slice';
import { Asset } from 'components/asset/Asset';
import { RootState } from 'store/store';
import { deleteAsset } from 'store/assets.slice';
import * as ReactRedux from 'react-redux';

jest.mock('react-redux', () => ({
Expand Down
117 changes: 83 additions & 34 deletions client/test/unit/components/asset/AssetCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,84 @@ import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Provider } from 'react-redux';
import { createStore, combineReducers } from 'redux';
import { AssetCardManage, AssetCardExecute, CardButtonsContainerManage, CardButtonsContainerExecute } from 'components/asset/AssetCard';
import {
AssetCardManage,
AssetCardExecute,
CardButtonsContainerManage,
CardButtonsContainerExecute,
} from 'components/asset/AssetCard';
import assetsReducer from 'store/assets.slice';
import { Asset } from 'components/asset/Asset';
import { RootState } from 'store/store';
import { setDigitalTwin } from 'store/digitalTwin.slice';
import DigitalTwin from 'util/gitlabDigitalTwin';

jest.mock('route/digitaltwins/Snackbar', () => () => <div>Snackbar</div>);

Check failure on line 18 in client/test/unit/components/asset/AssetCard.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Component definition is missing display name
jest.mock('route/digitaltwins/DetailsDialog', () => ({ showLog, setShowLog, name }: { showLog: boolean; setShowLog: (show: boolean) => void; name: string }) => (
<div>
DetailsDialog for {name}
{showLog && <button onClick={() => setShowLog(false)}>Close</button>}
</div>
));
jest.mock('route/digitaltwins/DeleteDialog', () => ({ showLog, setShowLog, name, onDelete }: { showLog: boolean; setShowLog: (show: boolean) => void; name: string; onDelete: () => void }) => (
<div>
DeleteDialog for {name}
{showLog && <button onClick={() => { setShowLog(false); onDelete(); }}>Delete</button>}
</div>
));
jest.mock('route/digitaltwins/LogDialog', () => ({ showLog, setShowLog, name }: { showLog: boolean; setShowLog: (show: boolean) => void; name: string }) => (
<div>
LogDialog for {name}
{showLog && <button onClick={() => setShowLog(false)}>Close</button>}
</div>
));
jest.mock(
'route/digitaltwins/DetailsDialog',
() =>
({

Check failure on line 22 in client/test/unit/components/asset/AssetCard.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Component definition is missing display name
showLog,
setShowLog,
name,
}: {
showLog: boolean;
setShowLog: (show: boolean) => void;
name: string;
}) => (
<div>
DetailsDialog for {name}
{showLog && <button onClick={() => setShowLog(false)}>Close</button>}
</div>
),
);
jest.mock(
'route/digitaltwins/DeleteDialog',
() =>
({

Check failure on line 40 in client/test/unit/components/asset/AssetCard.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Component definition is missing display name
showLog,
setShowLog,
name,
onDelete,
}: {
showLog: boolean;
setShowLog: (show: boolean) => void;
name: string;
onDelete: () => void;
}) => (
<div>
DeleteDialog for {name}
{showLog && (
<button
onClick={() => {
setShowLog(false);
onDelete();
}}
>
Delete
</button>
)}
</div>
),
);
jest.mock(
'route/digitaltwins/LogDialog',
() =>
({

Check failure on line 69 in client/test/unit/components/asset/AssetCard.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Component definition is missing display name
showLog,
setShowLog,
name,
}: {
showLog: boolean;
setShowLog: (show: boolean) => void;
name: string;
}) => (
<div>
LogDialog for {name}
{showLog && <button onClick={() => setShowLog(false)}>Close</button>}
</div>
),
);

const assetsMock: Asset[] = [
{ name: 'Asset1', path: 'path1', description: 'Description1' },
Expand All @@ -55,7 +107,10 @@ const mockStore = createStore(
digitalTwin: (state: DigitalTwinState = {}, action: DigitalTwinActions) => {

Check failure on line 107 in client/test/unit/components/asset/AssetCard.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Default parameters should be last
switch (action.type) {
case setDigitalTwin.type:
return { ...state, [action.payload.assetName]: action.payload.digitalTwin };
return {
...state,
[action.payload.assetName]: action.payload.digitalTwin,
};
default:
return state;
}
Expand All @@ -70,10 +125,7 @@ describe('AssetCard Components', () => {
it('renders AssetCard with asset and buttons', () => {
render(
<Provider store={mockStore}>
<AssetCardManage
asset={assetsMock[0]}
onDelete={() => {}}
/>
<AssetCardManage asset={assetsMock[0]} onDelete={() => {}} />
</Provider>,
);

Expand All @@ -89,7 +141,7 @@ describe('AssetCard Components', () => {
name="Asset1"
setShowDetailsLog={setShowDetailsLog}
setShowDeleteLog={setShowDeleteLog}
/>
/>,
);

expect(screen.getByText('DetailsButton')).toBeInTheDocument();
Expand All @@ -106,7 +158,7 @@ describe('AssetCard Components', () => {
name="Asset1"
setShowDetailsLog={setShowDetailsLog}
setShowDeleteLog={setShowDeleteLog}
/>
/>,
);

fireEvent.click(screen.getByText('DetailsButton'));
Expand All @@ -123,7 +175,7 @@ describe('AssetCard Components', () => {
<CardButtonsContainerExecute
assetName="Asset1"
setShowLog={setShowLog}
/>
/>,
);

expect(screen.getByText('StartStopButton')).toBeInTheDocument();
Expand All @@ -137,7 +189,7 @@ describe('AssetCard Components', () => {
<CardButtonsContainerExecute
assetName="Asset1"
setShowLog={setShowLog}
/>
/>,
);

fireEvent.click(screen.getByText('StartStopButton'));
Expand All @@ -151,11 +203,8 @@ describe('AssetCard Components', () => {

render(
<Provider store={mockStore}>
<AssetCardManage
asset={assetsMock[0]}
onDelete={handleDelete}
/>
</Provider>
<AssetCardManage asset={assetsMock[0]} onDelete={handleDelete} />
</Provider>,
);

expect(screen.getByText('Snackbar')).toBeInTheDocument();
Expand All @@ -171,7 +220,7 @@ describe('AssetCard Components', () => {
render(
<Provider store={mockStore}>
<AssetCardExecute asset={assetsMock[0]} />
</Provider>
</Provider>,
);

expect(screen.getByText('Snackbar')).toBeInTheDocument();
Expand Down
4 changes: 3 additions & 1 deletion client/test/unit/components/asset/DetailsButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe('DetailsButton', () => {

fireEvent.click(button);

await waitFor(() => expect(digitalTwinMock.getFullDescription).toHaveBeenCalled());
await waitFor(() =>
expect(digitalTwinMock.getFullDescription).toHaveBeenCalled(),
);

expect(setShowLogMock).toHaveBeenCalledWith(true);
});
Expand Down
2 changes: 1 addition & 1 deletion client/test/unit/routes/digitaltwins/DeleteDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ describe('DetailsDialog', () => {
expect(deleteMock).toHaveBeenCalled();
expect(setShowLogMock).toHaveBeenCalledWith(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
itHasCorrectExecuteTabNameInDTIframe,
} from 'test/unit/unit.testUtil';
import store from 'store/store';
import { Provider } from 'react-redux';
import { Provider, useDispatch } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import '@testing-library/jest-dom';
import { GitlabInstance } from 'util/gitlab';
import { setAssets } from 'store/assets.slice';
import { useDispatch } from 'react-redux';

jest.mock('util/gitlab', () => ({
GitlabInstance: jest.fn().mockImplementation(() => ({
Expand Down Expand Up @@ -66,7 +65,7 @@ describe('Digital Twins Preview', () => {

expect(mockGitlabInstance.init).toHaveBeenCalled();
expect(mockGitlabInstance.getDTSubfolders).toHaveBeenCalledWith(
'mockedProjectId'
'mockedProjectId',
);
expect(mockDispatch).toHaveBeenCalledWith(setAssets([]));
});
Expand Down Expand Up @@ -100,7 +99,9 @@ describe('Digital Twins Preview', () => {
'access_token',
);

jest.spyOn(mockGitlabInstance, 'init').mockRejectedValue(new Error('Initialization failed'));
jest
.spyOn(mockGitlabInstance, 'init')
.mockRejectedValue(new Error('Initialization failed'));

const mockDispatch = jest.fn();
(useDispatch as jest.Mock).mockReturnValue(mockDispatch);
Expand Down
20 changes: 9 additions & 11 deletions client/test/unit/routes/digitaltwins/Snackbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import CustomSnackbar from 'route/digitaltwins/Snackbar';
import { Provider } from 'react-redux';
import { hideSnackbar } from 'store/snackbar.slice';

const mockStore = (initialState: any) => {
return {
getState: () => initialState,
dispatch: jest.fn(),
subscribe: jest.fn(),
};
};
const mockStore = (initialState: any) => ({

Check failure on line 8 in client/test/unit/routes/digitaltwins/Snackbar.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Unexpected any. Specify a different type
getState: () => initialState,
dispatch: jest.fn(),
subscribe: jest.fn(),
});

describe('CustomSnackbar', () => {
it('renders the snackbar with the correct message and severity', () => {
Expand All @@ -26,7 +24,7 @@ describe('CustomSnackbar', () => {
render(
<Provider store={store as any}>

Check failure on line 25 in client/test/unit/routes/digitaltwins/Snackbar.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Unexpected any. Specify a different type
<CustomSnackbar />
</Provider>
</Provider>,
);

expect(screen.getByText('Test Message')).toBeInTheDocument();
Expand All @@ -45,7 +43,7 @@ describe('CustomSnackbar', () => {
render(
<Provider store={store as any}>

Check failure on line 44 in client/test/unit/routes/digitaltwins/Snackbar.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Unexpected any. Specify a different type
<CustomSnackbar />
</Provider>
</Provider>,
);

expect(screen.queryByText('Test Message')).toBeNull();
Expand All @@ -66,7 +64,7 @@ describe('CustomSnackbar', () => {
render(
<Provider store={store as any}>

Check failure on line 65 in client/test/unit/routes/digitaltwins/Snackbar.test.tsx

View workflow job for this annotation

GitHub Actions / Test react website

Unexpected any. Specify a different type
<CustomSnackbar />
</Provider>
</Provider>,
);

fireEvent.click(screen.getByRole('button'));
Expand All @@ -90,7 +88,7 @@ describe('CustomSnackbar', () => {
render(
<Provider store={store as any}>
<CustomSnackbar />
</Provider>
</Provider>,
);

act(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/test/unitTests/Util/gitlabDigitalTwin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ describe('DigitalTwin', () => {
expect(formatName(input)).toBe(expected);
});
});
});
});

0 comments on commit 6722838

Please sign in to comment.