chore(trading): add missing mock for node health (#6008)
This commit is contained in:
parent
0636d19b0d
commit
8e2ec8ab67
@ -1,7 +1,11 @@
|
||||
import { render, screen, waitFor, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { NodeHealthContainer, NodeUrl } from './node-health';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { MockedProvider, type MockedResponse } from '@apollo/client/testing';
|
||||
import {
|
||||
NodeCheckDocument,
|
||||
type NodeCheckQuery,
|
||||
} from '@vegaprotocol/environment';
|
||||
|
||||
const mockSetNodeSwitcher = jest.fn();
|
||||
|
||||
@ -15,20 +19,50 @@ jest.mock('@vegaprotocol/environment', () => ({
|
||||
}));
|
||||
|
||||
describe('NodeHealthContainer', () => {
|
||||
const blockHeight = '1';
|
||||
const nodeCheckMock: MockedResponse<NodeCheckQuery, never> = {
|
||||
request: {
|
||||
query: NodeCheckDocument,
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
statistics: {
|
||||
chainId: 'chain-id',
|
||||
blockHeight: blockHeight,
|
||||
vegaTime: '12345',
|
||||
},
|
||||
networkParametersConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
key: 'a',
|
||||
value: '1',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const renderComponent = (mocks: MockedResponse[] = []) => {
|
||||
return render(
|
||||
<MockedProvider mocks={mocks}>
|
||||
<NodeHealthContainer />
|
||||
</MockedProvider>
|
||||
);
|
||||
};
|
||||
|
||||
it('controls the node switcher dialog', async () => {
|
||||
render(<NodeHealthContainer />, { wrapper: MockedProvider });
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('button')).toBeInTheDocument();
|
||||
});
|
||||
renderComponent([nodeCheckMock]);
|
||||
expect(await screen.findByRole('button')).toBeInTheDocument();
|
||||
await userEvent.click(screen.getByRole('button'));
|
||||
expect(mockSetNodeSwitcher).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('Shows node health data on hover', async () => {
|
||||
render(<NodeHealthContainer />, { wrapper: MockedProvider });
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('button')).toBeInTheDocument();
|
||||
});
|
||||
renderComponent([nodeCheckMock]);
|
||||
expect(await screen.findByRole('button')).toBeInTheDocument();
|
||||
await userEvent.hover(screen.getByRole('button'));
|
||||
await waitFor(() => {
|
||||
const portal = within(
|
||||
@ -36,12 +70,13 @@ describe('NodeHealthContainer', () => {
|
||||
'[data-radix-popper-content-wrapper]'
|
||||
) as HTMLElement
|
||||
);
|
||||
|
||||
// two tooltips get rendered, I believe for animation purposes
|
||||
const tooltip = within(portal.getAllByTestId('tooltip-content')[0]);
|
||||
expect(
|
||||
tooltip.getByRole('link', { name: /^Mainnet status & incidents/ })
|
||||
).toBeInTheDocument();
|
||||
expect(tooltip.getByText('Non operational')).toBeInTheDocument();
|
||||
expect(tooltip.getByText('Operational')).toBeInTheDocument();
|
||||
expect(tooltip.getByTitle('Connected node')).toHaveTextContent(
|
||||
'vega-url.wtf'
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user