2023-02-27 09:16:19 +00:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import { NodeHealth, NodeUrl, HealthIndicator } from './footer';
|
|
|
|
|
|
|
|
describe('NodeHealth', () => {
|
|
|
|
it('controls the node switcher dialog', async () => {
|
|
|
|
const mockOnClick = jest.fn();
|
|
|
|
render(
|
|
|
|
<NodeHealth
|
|
|
|
onClick={mockOnClick}
|
|
|
|
url={'https://api.n99.somenetwork.vega.xyz'}
|
|
|
|
blockHeight={100}
|
|
|
|
blockDiff={0}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
await userEvent.click(screen.getByRole('button'));
|
|
|
|
expect(mockOnClick).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
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-02-14 15:43:52 +00:00
|
|
|
{ diff: 0, classname: 'bg-vega-green-550', text: 'Operational' },
|
2023-01-27 10:31:23 +00:00
|
|
|
{ diff: 5, classname: 'bg-warning', text: '5 Blocks behind' },
|
2023-02-16 03:52:54 +00:00
|
|
|
{ diff: null, classname: 'bg-danger', text: 'Non operational' },
|
2023-01-27 10:31:23 +00:00
|
|
|
];
|
|
|
|
it.each(cases)(
|
|
|
|
'renders correct text and indicator color for $diff block difference',
|
|
|
|
(elem) => {
|
2023-02-27 09:16:19 +00:00
|
|
|
render(<HealthIndicator blockDiff={elem.diff} />);
|
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
|
|
|
});
|