From e44cf1ff535d20fa2e26af13b9174d5f8f1ccd2e Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Tue, 9 May 2023 13:39:17 -0700 Subject: [PATCH] chore(environment,trading): fix unit tests for footer and node switcher (#3682) --- .../trading/components/footer/footer.spec.tsx | 9 +++----- .../node-switcher/row-data.spec.tsx | 23 ++++--------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/apps/trading/components/footer/footer.spec.tsx b/apps/trading/components/footer/footer.spec.tsx index 4ddfbbd0c..9e8a77c31 100644 --- a/apps/trading/components/footer/footer.spec.tsx +++ b/apps/trading/components/footer/footer.spec.tsx @@ -4,18 +4,15 @@ import { NodeHealth, NodeUrl, HealthIndicator } from './footer'; import { MockedProvider } from '@apollo/client/testing'; import { Intent } from '@vegaprotocol/ui-toolkit'; +const mockSetNodeSwitcher = jest.fn(); + jest.mock('@vegaprotocol/environment', () => ({ ...jest.requireActual('@vegaprotocol/environment'), useEnvironment: jest.fn().mockImplementation(() => ({ VEGA_URL: 'https://vega-url.wtf', VEGA_INCIDENT_URL: 'https://blog.vega.community', })), -})); - -const mockSetNodeSwitcher = jest.fn(); -jest.mock('../../stores', () => ({ - ...jest.requireActual('../../stores'), - useGlobalStore: () => mockSetNodeSwitcher, + useNodeSwitcherStore: jest.fn(() => mockSetNodeSwitcher), })); describe('NodeHealth', () => { diff --git a/libs/environment/src/components/node-switcher/row-data.spec.tsx b/libs/environment/src/components/node-switcher/row-data.spec.tsx index b24dee869..29f805e30 100644 --- a/libs/environment/src/components/node-switcher/row-data.spec.tsx +++ b/libs/environment/src/components/node-switcher/row-data.spec.tsx @@ -96,13 +96,13 @@ describe('RowData', () => { mockHeaders(props.url); render(renderComponent(props, statsQueryMock, subMock)); - // radio should be disabled until query resolves + // radio should be enabled until query resolves expect( screen.getByRole('radio', { checked: false, name: props.url, }) - ).toBeDisabled(); + ).toBeEnabled(); expect(screen.getByTestId('response-time-cell')).toHaveTextContent( 'Checking' ); @@ -124,7 +124,7 @@ describe('RowData', () => { }); }); - it('radio button disabled if query fails', async () => { + it('radio button still enabled if query fails', async () => { mockHeaders(props.url, {}); const failedQueryMock: MockedResponse = { @@ -149,7 +149,7 @@ describe('RowData', () => { checked: false, name: props.url, }) - ).toBeDisabled(); + ).toBeEnabled(); expect(screen.getByTestId('response-time-cell')).toHaveTextContent( 'Checking' ); @@ -170,7 +170,7 @@ describe('RowData', () => { checked: false, name: props.url, }) - ).toBeDisabled(); + ).toBeEnabled(); }); }); @@ -207,19 +207,6 @@ describe('RowData', () => { expect(screen.getByTestId('block-height-cell')).toHaveClass('text-danger'); }); - it('disables radio button if url is invalid', () => { - mockHeaders(props.url, { blockHeight: 100 }); - - render(renderComponent(props, statsQueryMock, subMock)); - - expect( - screen.getByRole('radio', { - checked: false, - name: props.url, - }) - ).toBeDisabled(); - }); - it('doesnt render the radio if its the custom row', () => { render( renderComponent(