Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Manage' tab to Digital Twins page preview #957

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix codeclimate issues
  • Loading branch information
vanessa committed Oct 20, 2024
commit 5ee7d39ad2f271ae6670e8e6b1c1018bfe3262ee
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import setupStore from './utils';
jest.useFakeTimers();

describe('ReconfigureDialog', () => {
let store: ReturnType<typeof setupStore>;
let storeConfig: ReturnType<typeof setupStore>;

beforeEach(() => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

store = setupStore();
storeConfig = setupStore();

React.act(() => {
render(
<Provider store={store}>
<Provider store={storeConfig}>
<AssetBoard tab="Manage" error={null} />
</Provider>,
);
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('ReconfigureDialog', () => {
};

React.act(() => {
store.dispatch(addOrUpdateFile(modifiedFile));
storeConfig.dispatch(addOrUpdateFile(modifiedFile));
});

const reconfigureButton = screen.getByRole('button', {
Expand All @@ -112,7 +112,7 @@ describe('ReconfigureDialog', () => {
'description.md',
'New content',
);
const state = store.getState();
const state = storeConfig.getState();
expect(state.digitalTwin['Asset 1'].description).toBe('New content');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import setupStore from './utils';
jest.useFakeTimers();

describe('DeleteDialog', () => {
let store: ReturnType<typeof setupStore>;
let storeDelete: ReturnType<typeof setupStore>;

beforeEach(() => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

store = setupStore();
storeDelete = setupStore();

React.act(() => {
render(
<Provider store={store}>
<Provider store={storeDelete}>
<AssetBoard tab="Manage" error={null} />
</Provider>,
);
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('DeleteDialog', () => {
});

await waitFor(() => {
const state = store.getState();
const state = storeDelete.getState();
expect(state.snackbar.open).toBe(true);
expect(state.snackbar.message).toBe('Asset 1 deleted successfully');
expect(state.snackbar.severity).toBe('success');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jest.mock('react-redux', () => ({
jest.useFakeTimers();

describe('DetailsDialog', () => {
let store: ReturnType<typeof setupStore>;
let storeDetails: ReturnType<typeof setupStore>;

beforeEach(() => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

store = setupStore();
storeDetails = setupStore();

React.act(() => {
render(
<Provider store={store}>
<Provider store={storeDetails}>
<AssetBoard tab="Manage" error={null} />
</Provider>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ describe('Sidebar', () => {
const setFileContent = jest.fn();
const setFileType = jest.fn();

const clickFile = async (fileType: string, expectedFileName: string) => {
const fileNode = screen.getByText(fileType);
fireEvent.click(fileNode);

await waitFor(() => {
expect(screen.getByText(expectedFileName)).toBeInTheDocument();
});

const file = screen.getByText(expectedFileName);
fireEvent.click(file);
};

beforeEach(async () => {
(useSelector as jest.Mock).mockImplementation(
(selector: (state: RootState) => unknown) => {
Expand Down Expand Up @@ -131,39 +143,15 @@ describe('Sidebar', () => {
});

it('calls handleFileClick when a description file is clicked', async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

const descriptionNode = screen.getByText('Description');
fireEvent.click(descriptionNode);

await waitFor(() => {
expect(screen.getByText('descriptionFile')).toBeInTheDocument();
});

const file = screen.getByText('descriptionFile');
fireEvent.click(file);
await clickFile('Description', 'descriptionFile');
});

it('calls handleFileClick when a config file is clicked', async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

const configurationNode = screen.getByText('Configuration');
fireEvent.click(configurationNode);

await waitFor(() => {
expect(screen.getByText('configFile')).toBeInTheDocument();
});

const file = screen.getByText('configFile');
fireEvent.click(file);
await clickFile('Configuration', 'configFile');
});

it('calls handleFileClick when a lifecycle file is clicked', async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

const lifecycleNode = screen.getByText('Lifecycle');
fireEvent.click(lifecycleNode);

await waitFor(() => {
expect(screen.getByText('lifecycleFile')).toBeInTheDocument();
});

const file = screen.getByText('lifecycleFile');
fireEvent.click(file);
await clickFile('Lifecycle', 'lifecycleFile');
});

it('call setFileContent with error message if file content is null', async () => {
Expand Down
Loading