From d106bbf93a3b58e3fe3b4ca2bae57eb9a322770e Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Fri, 6 Oct 2023 10:21:20 +0300 Subject: [PATCH] fixup! fixup! fixup! fixup! fix: 'Backend is not available...' error message --- .../ErrorBoundary/__tests__/index.spec.tsx | 20 +++++++++---------- .../src/Layout/ErrorBoundary/index.tsx | 2 +- .../dashboard-frontend/src/Layout/index.tsx | 2 +- .../__tests__/helpers.spec.ts | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/dashboard-frontend/src/Layout/ErrorBoundary/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/Layout/ErrorBoundary/__tests__/index.spec.tsx index 58caff090..152ec004f 100644 --- a/packages/dashboard-frontend/src/Layout/ErrorBoundary/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/Layout/ErrorBoundary/__tests__/index.spec.tsx @@ -37,9 +37,9 @@ export class NoResourceComponent extends React.Component { // mute the outputs console.error = jest.fn(); -const mockTestBackends = jest.fn(); +const mockOnError = jest.fn(); function wrapComponent(componentToWrap: React.ReactNode) { - return {componentToWrap}; + return {componentToWrap}; } describe('Error boundary', () => { @@ -67,7 +67,7 @@ describe('Error boundary', () => { const showDetailsAction = screen.getByRole('button', { name: 'View stack' }); userEvent.click(showDetailsAction); - expect(mockTestBackends).not.toHaveBeenCalled(); + expect(mockOnError).not.toHaveBeenCalled(); expect(screen.queryByText('in BadComponent', { exact: false })).toBeTruthy(); expect(screen.queryByText('in ErrorBoundary', { exact: false })).toBeTruthy(); @@ -100,7 +100,7 @@ describe('Error boundary', () => { const errorBoundary = wrapComponent(); render(errorBoundary); - expect(mockTestBackends).toHaveBeenCalledWith('Loading chunk 23 failed.'); + expect(mockOnError).toHaveBeenCalledWith('Loading chunk 23 failed.'); expect( screen.queryByText('The application has been likely updated on the server.', { exact: false, @@ -114,7 +114,7 @@ describe('Error boundary', () => { const errorBoundary = wrapComponent(); render(errorBoundary); - expect(mockTestBackends).toHaveBeenCalledWith('Loading chunk 23 failed.'); + expect(mockOnError).toHaveBeenCalledWith('Loading chunk 23 failed.'); expect( screen.queryByText('Refreshing a page to get newer resources in', { exact: false }), ).toBeTruthy(); @@ -131,7 +131,7 @@ describe('Error boundary', () => { const stopCountdownAction = screen.getByRole('button', { name: 'Stop countdown' }); userEvent.click(stopCountdownAction); - expect(mockTestBackends).toHaveBeenCalledWith('Loading chunk 23 failed.'); + expect(mockOnError).toHaveBeenCalledWith('Loading chunk 23 failed.'); expect( screen.queryByText('Refreshing a page to get newer resources in', { exact: false }), ).toBeFalsy(); @@ -153,7 +153,7 @@ describe('Error boundary', () => { jest.advanceTimersByTime(35000); - expect(mockTestBackends).toHaveBeenCalledWith('Loading chunk 23 failed.'); + expect(mockOnError).toHaveBeenCalledWith('Loading chunk 23 failed.'); expect(window.location.reload).toHaveBeenCalled(); expect(window.location.reload).toHaveBeenCalledTimes(1); }); @@ -167,7 +167,7 @@ describe('Error boundary', () => { userEvent.click(reloadNowAction); userEvent.click(reloadNowAction); - expect(mockTestBackends).toHaveBeenCalledWith('Loading chunk 23 failed.'); + expect(mockOnError).toHaveBeenCalledWith('Loading chunk 23 failed.'); expect(window.location.reload).toHaveBeenCalled(); expect(window.location.reload).toHaveBeenCalledTimes(3); }); @@ -192,7 +192,7 @@ describe('Error boundary', () => { window.dispatchEvent(new Event('beforeunload')); render(errorBoundary); - expect(mockTestBackends).toHaveBeenCalledWith('Loading chunk 23 failed.'); + expect(mockOnError).toHaveBeenCalledWith('Loading chunk 23 failed.'); expect( screen.queryByText( 'Contact an administrator if refreshing continues after the next load.', @@ -233,7 +233,7 @@ describe('Error boundary', () => { window.dispatchEvent(new Event('beforeunload')); render(goodComponent); - expect(mockTestBackends).toHaveBeenCalledWith('Loading chunk 23 failed.'); + expect(mockOnError).toHaveBeenCalledWith('Loading chunk 23 failed.'); expect(sessionStorage.getItem(STORAGE_KEY_RELOAD_NUMBER)).toBeNull(); }); }); diff --git a/packages/dashboard-frontend/src/Layout/ErrorBoundary/index.tsx b/packages/dashboard-frontend/src/Layout/ErrorBoundary/index.tsx index faeccf21c..e871aa859 100644 --- a/packages/dashboard-frontend/src/Layout/ErrorBoundary/index.tsx +++ b/packages/dashboard-frontend/src/Layout/ErrorBoundary/index.tsx @@ -29,7 +29,7 @@ const RELOAD_TIMEOUT_SEC = 30; const RELOADS_FOR_EXTENDED_MESSAGE = 2; type Props = PropsWithChildren & { - testBackends: (error?: string) => void; + onError: (error?: string) => void; }; type State = { hasError: boolean; diff --git a/packages/dashboard-frontend/src/Layout/index.tsx b/packages/dashboard-frontend/src/Layout/index.tsx index 17d6e9e4b..ce38ab714 100644 --- a/packages/dashboard-frontend/src/Layout/index.tsx +++ b/packages/dashboard-frontend/src/Layout/index.tsx @@ -145,7 +145,7 @@ export class Layout extends React.PureComponent { } isManagedSidebar={IS_MANAGED_SIDEBAR} > - this.testBackends(error)}> + this.testBackends(error)}> {this.props.children} diff --git a/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts b/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts index 527384f0a..12dd9fd50 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts @@ -32,7 +32,7 @@ describe('Workspace-client helpers', () => { it('should return the unknown error message', () => { expect(getErrorMessage({})).toEqual('Unexpected error type. Please report a bug.'); }); - it('should return unknown an error message', () => { + it('should return the error message', () => { expect( getErrorMessage({ response: {