Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fix: 'Backend is not available...' error …
Browse files Browse the repository at this point in the history
…message
  • Loading branch information
olexii4 committed Oct 6, 2023
1 parent c498f0f commit d106bbf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ErrorBoundary testBackends={mockTestBackends}>{componentToWrap}</ErrorBoundary>;
return <ErrorBoundary onError={mockOnError}>{componentToWrap}</ErrorBoundary>;
}

describe('Error boundary', () => {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -100,7 +100,7 @@ describe('Error boundary', () => {
const errorBoundary = wrapComponent(<NoResourceComponent />);
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,
Expand All @@ -114,7 +114,7 @@ describe('Error boundary', () => {
const errorBoundary = wrapComponent(<NoResourceComponent />);
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();
Expand All @@ -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();
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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.',
Expand Down Expand Up @@ -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();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-frontend/src/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class Layout extends React.PureComponent<Props, State> {
}
isManagedSidebar={IS_MANAGED_SIDEBAR}
>
<ErrorBoundary testBackends={error => this.testBackends(error)}>
<ErrorBoundary onError={error => this.testBackends(error)}>
<StoreErrorsAlert />
<BannerAlert />
{this.props.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit d106bbf

Please sign in to comment.