2023-03-15 11:49:31 +00:00
|
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
2023-02-27 09:16:19 +00:00
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import { NodeHealth, NodeUrl, HealthIndicator } from './footer';
|
2023-03-15 11:49:31 +00:00
|
|
|
import { MockedProvider } from '@apollo/client/testing';
|
|
|
|
import { Intent } from '@vegaprotocol/ui-toolkit';
|
|
|
|
|
|
|
|
jest.mock('@vegaprotocol/environment', () => ({
|
|
|
|
...jest.requireActual('@vegaprotocol/environment'),
|
2023-03-21 15:19:54 +00:00
|
|
|
useEnvironment: jest.fn().mockImplementation(() => ({
|
|
|
|
VEGA_URL: 'https://vega-url.wtf',
|
|
|
|
VEGA_INCIDENT_URL: 'https://blog.vega.community',
|
|
|
|
})),
|
2023-03-15 11:49:31 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
const mockSetNodeSwitcher = jest.fn();
|
|
|
|
jest.mock('../../stores', () => ({
|
|
|
|
...jest.requireActual('../../stores'),
|
|
|
|
useGlobalStore: () => mockSetNodeSwitcher,
|
|
|
|
}));
|
2023-02-27 09:16:19 +00:00
|
|
|
|
|
|
|
describe('NodeHealth', () => {
|
|
|
|
it('controls the node switcher dialog', async () => {
|
2023-03-15 11:49:31 +00:00
|
|
|
render(<NodeHealth />, { wrapper: MockedProvider });
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
|
|
});
|
2023-02-27 09:16:19 +00:00
|
|
|
await userEvent.click(screen.getByRole('button'));
|
2023-03-15 11:49:31 +00:00
|
|
|
expect(mockSetNodeSwitcher).toHaveBeenCalled();
|
2023-02-27 09:16:19 +00:00
|
|
|
});
|
2023-03-21 15:19:54 +00:00
|
|
|
|
|
|
|
it('External link to blog should be present', () => {
|
|
|
|
render(<NodeHealth />, { wrapper: MockedProvider });
|
|
|
|
expect(
|
|
|
|
screen.getByRole('link', { name: /^Mainnet status & incidents/ })
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
2023-02-27 09:16:19 +00:00
|
|
|
});
|
2022-11-08 00:53:43 +00:00
|
|
|
|
2023-02-16 03:52:54 +00:00
|
|
|
describe('NodeUrl', () => {
|
2023-02-27 09:16:19 +00:00
|
|
|
it('renders correct part of node url', () => {
|
2023-02-16 03:52:54 +00:00
|
|
|
const node = 'https://api.n99.somenetwork.vega.xyz';
|
2023-02-27 09:16:19 +00:00
|
|
|
const expectedText = node.split('.').slice(1).join('.');
|
2023-01-27 10:31:23 +00:00
|
|
|
|
2023-02-27 09:16:19 +00:00
|
|
|
render(<NodeUrl url={node} />);
|
2023-01-27 10:31:23 +00:00
|
|
|
|
2023-02-27 09:16:19 +00:00
|
|
|
expect(screen.getByText(expectedText)).toBeInTheDocument();
|
2023-01-27 10:31:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-27 09:16:19 +00:00
|
|
|
describe('HealthIndicator', () => {
|
2023-01-27 10:31:23 +00:00
|
|
|
const cases = [
|
2023-03-15 11:49:31 +00:00
|
|
|
{
|
|
|
|
intent: Intent.Success,
|
|
|
|
text: 'Operational',
|
|
|
|
classname: 'bg-vega-green-550',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
intent: Intent.Warning,
|
|
|
|
text: '5 Blocks behind',
|
|
|
|
classname: 'bg-warning',
|
|
|
|
},
|
|
|
|
{ intent: Intent.Danger, text: 'Non operational', classname: 'bg-danger' },
|
2023-01-27 10:31:23 +00:00
|
|
|
];
|
|
|
|
it.each(cases)(
|
|
|
|
'renders correct text and indicator color for $diff block difference',
|
|
|
|
(elem) => {
|
2023-03-15 11:49:31 +00:00
|
|
|
render(<HealthIndicator text={elem.text} intent={elem.intent} />);
|
2023-01-27 10:31:23 +00:00
|
|
|
expect(screen.getByTestId('indicator')).toHaveClass(elem.classname);
|
|
|
|
expect(screen.getByText(elem.text)).toBeInTheDocument();
|
|
|
|
}
|
|
|
|
);
|
2022-11-08 00:53:43 +00:00
|
|
|
});
|