Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"electron-window-state": "5.0.3",
"fs-extra": "11.1.0",
"lodash": "4.17.21",
"react-json-view": "^1.21.3",
"semver": "7.7.2",
"shell-env": "3.0.1",
"unzipper": "0.12.3",
Expand Down
9 changes: 9 additions & 0 deletions src/__mocks__/fileService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// __mocks__/fileService.js

module.exports = {
fileService: {
existsSync: jest.fn(() => false),
readFileSync: jest.fn(() => '{}'),
copyFileSync: jest.fn(),
},
};
47 changes: 47 additions & 0 deletions src/components/common/NetworkMonitoringButton.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { Status } from 'shared/types';
import { getNetwork, renderWithProviders } from 'utils/tests';
import NetworkMonitoringButton from './NetworkMonitoringButton';
import { fireEvent } from '@testing-library/react';
import { initChartFromNetwork } from 'utils/chart';

describe('NetworkMonitoringButton', () => {
let unmount: () => void;

const renderComponent = () => {
const network = getNetwork(1, 'test network', Status.Started);
const initialState = {
network: {
networks: [network],
},
designer: {
activeId: 1,
allCharts: {
1: initChartFromNetwork(network),
},
},
modals: {
networkMonitoring: { visible: false },
},
};
const cmp = <NetworkMonitoringButton networkId={network.id} />;
const result = renderWithProviders(cmp, { initialState });
unmount = result.unmount;
return result;
};

afterEach(() => unmount());

it('should render the button', () => {
const { getByRole } = renderComponent();
const btn = getByRole('monitor-network');
expect(btn).toBeInTheDocument();
});

it('should open the modal on click', () => {
const { getByRole, store } = renderComponent();
const btn = getByRole('monitor-network');
fireEvent.click(btn);
expect(store.getState().modals.networkMonitoring.visible).toBe(true);
});
});
35 changes: 35 additions & 0 deletions src/components/common/NetworkMonitoringButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { EyeOutlined } from '@ant-design/icons';
import styled from '@emotion/styled';
import { Button, Tooltip } from 'antd';
import { usePrefixedTranslation } from 'hooks';
import { useStoreActions } from 'store';

const Styled = {
Button: styled(Button)`
margin-left: 8px;
`,
};

interface Props {
networkId: number;
}

const NetworkMonitoringButton: React.FC<Props> = ({ networkId }) => {
const { l } = usePrefixedTranslation('cmps.network.NetworkActions');
const { showNetworkMonitoring } = useStoreActions(s => s.modals);

const showModal = async () => {
await showNetworkMonitoring({ networkId });
};

return (
<Tooltip title={l('monitorBtn') || 'Monitor Network'}>
<Styled.Button onClick={showModal} role="monitor-network">
<EyeOutlined />
</Styled.Button>
</Tooltip>
);
};

export default NetworkMonitoringButton;
Loading