diff --git a/apps/trading/components/node-health/node-health.spec.tsx b/apps/trading/components/node-health/node-health.spec.tsx index 65aed97e5..dc87a62e6 100644 --- a/apps/trading/components/node-health/node-health.spec.tsx +++ b/apps/trading/components/node-health/node-health.spec.tsx @@ -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 = { + 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( + + + + ); + }; + it('controls the node switcher dialog', async () => { - render(, { 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(, { 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' );