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 { render, screen, waitFor, within } from '@testing-library/react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import { NodeHealthContainer, NodeUrl } from './node-health';
|
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();
|
const mockSetNodeSwitcher = jest.fn();
|
||||||
|
|
||||||
@ -15,20 +19,50 @@ jest.mock('@vegaprotocol/environment', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('NodeHealthContainer', () => {
|
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 () => {
|
it('controls the node switcher dialog', async () => {
|
||||||
render(<NodeHealthContainer />, { wrapper: MockedProvider });
|
renderComponent([nodeCheckMock]);
|
||||||
await waitFor(() => {
|
expect(await screen.findByRole('button')).toBeInTheDocument();
|
||||||
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
await userEvent.click(screen.getByRole('button'));
|
await userEvent.click(screen.getByRole('button'));
|
||||||
expect(mockSetNodeSwitcher).toHaveBeenCalled();
|
expect(mockSetNodeSwitcher).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Shows node health data on hover', async () => {
|
it('Shows node health data on hover', async () => {
|
||||||
render(<NodeHealthContainer />, { wrapper: MockedProvider });
|
renderComponent([nodeCheckMock]);
|
||||||
await waitFor(() => {
|
expect(await screen.findByRole('button')).toBeInTheDocument();
|
||||||
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
await userEvent.hover(screen.getByRole('button'));
|
await userEvent.hover(screen.getByRole('button'));
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
const portal = within(
|
const portal = within(
|
||||||
@ -36,12 +70,13 @@ describe('NodeHealthContainer', () => {
|
|||||||
'[data-radix-popper-content-wrapper]'
|
'[data-radix-popper-content-wrapper]'
|
||||||
) as HTMLElement
|
) as HTMLElement
|
||||||
);
|
);
|
||||||
|
|
||||||
// two tooltips get rendered, I believe for animation purposes
|
// two tooltips get rendered, I believe for animation purposes
|
||||||
const tooltip = within(portal.getAllByTestId('tooltip-content')[0]);
|
const tooltip = within(portal.getAllByTestId('tooltip-content')[0]);
|
||||||
expect(
|
expect(
|
||||||
tooltip.getByRole('link', { name: /^Mainnet status & incidents/ })
|
tooltip.getByRole('link', { name: /^Mainnet status & incidents/ })
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
expect(tooltip.getByText('Non operational')).toBeInTheDocument();
|
expect(tooltip.getByText('Operational')).toBeInTheDocument();
|
||||||
expect(tooltip.getByTitle('Connected node')).toHaveTextContent(
|
expect(tooltip.getByTitle('Connected node')).toHaveTextContent(
|
||||||
'vega-url.wtf'
|
'vega-url.wtf'
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user