Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions core/src/client/ErrorHandler/ErrorHandler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/
import React from 'react';
import { userEvent } from '@testing-library/user-event';
import { renderWithAppContext } from '@labkey/components'
import { getServerContext } from '@labkey/api';
import { renderWithAppContext } from '@labkey/components';

import { ErrorHandlerImpl } from './ErrorHandler';
import { ErrorDetails, ErrorType } from './model';
Expand All @@ -19,28 +18,33 @@ describe('ErrorHandlerImpl', () => {
message: 'This is a not found exception',
};
renderWithAppContext(<ErrorHandlerImpl context={{ errorDetails }} />);
expect(document.querySelector('.labkey-error-heading').innerHTML.includes(errorDetails.message)).toBeTruthy();
expect(document.querySelector('.labkey-error-heading').textContent.includes(errorDetails.message)).toBeTruthy();
expect(document.querySelectorAll('.error-details-container')).toHaveLength(0);

await userEvent.click(document.querySelectorAll('.error-page-button')[2]);
const question = document.querySelector('.error-details-container');
expect(question.innerHTML.includes('What went wrong?')).toBeTruthy();
expect(question.innerHTML.includes('Incorrect URL:')).toBeTruthy();
expect(question.textContent.includes('What went wrong?')).toBeTruthy();
expect(question.textContent.includes('Incorrect URL:')).toBeTruthy();
});

test('Configuration exception', async () => {
const errorDetails: ErrorDetails = {
errorType: ErrorType.configuration,
message: 'This is a configuration exception',
};
const subheading = 'The requested page cannot be found.';
renderWithAppContext(<ErrorHandlerImpl context={{ errorDetails }} />);
expect(document.querySelector('.labkey-error-subheading').innerHTML.includes(subheading)).toBeTruthy();
expect(document.querySelector('.labkey-error-subheading').textContent).toEqual(
'This is a configuration exception.'
);
expect(document.querySelectorAll('.error-details-container')).toHaveLength(0);

await userEvent.click(document.querySelectorAll('.error-page-button')[2]);
expect(document.querySelector('.labkey-error-details-question').innerHTML.includes('What went wrong?')).toBeTruthy();
expect(document.querySelector('div.labkey-error-details').innerHTML.includes('Server Configuration Errors')).toBeTruthy();
expect(
document.querySelector('.labkey-error-details-question').textContent.includes('What went wrong?')
).toBeTruthy();
expect(
document.querySelector('div.labkey-error-details').textContent.includes('Server Configuration Errors')
).toBeTruthy();
});

test('Permission exception', async () => {
Expand All @@ -56,14 +60,19 @@ describe('ErrorHandlerImpl', () => {
serverContext: {
impersonatingUser: { displayName: impersonatedUser },
user: { displayName: realUser, isSignedIn: true } as any,
}
},
});
expect(document.querySelector('.labkey-error-subheading').innerHTML.includes(errorDetails.message)).toBeTruthy();
expect(
document.querySelector('.labkey-error-subheading').textContent.includes(errorDetails.message)
).toBeTruthy();
expect(document.querySelectorAll('.error-details-container')).toHaveLength(0);

await userEvent.click(document.querySelectorAll('.error-page-button')[2]);
const question = document.querySelector('.error-details-container');
expect(document.querySelector('.labkey-error-details-question').innerHTML.startsWith('What is a permission error?')).toBeTruthy();
expect(
document
.querySelector('.labkey-error-details-question')
.textContent.startsWith('What is a permission error?')
).toBeTruthy();

// FIXME: the following cases are commented out because nearly the entire ErrorHandler component uses
// non-component functions to render the contents, which prevents the code from being able to properly use the
Expand All @@ -79,7 +88,9 @@ describe('ErrorHandlerImpl', () => {
message: 'This is a execution exception',
};
renderWithAppContext(<ErrorHandlerImpl context={{ errorDetails }} />);
expect(document.querySelector('.labkey-error-subheading').innerHTML.includes(errorDetails.message)).toBeTruthy();
expect(
document.querySelector('.labkey-error-subheading').textContent.includes(errorDetails.message)
).toBeTruthy();
expect(document.querySelectorAll('.error-details-container')).toHaveLength(0);

await userEvent.click(document.querySelectorAll('.error-page-button')[2]);
Expand Down
1 change: 0 additions & 1 deletion core/src/client/ErrorHandler/ErrorType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ const PERMISSION_DETAILS = (errorDetails: ErrorDetails) => (
const CONFIGURATION_HEADING = () => 'Oops! A server configuration error has occurred.';
const CONFIGURATION_SUBHEADING = (errorMessage?: string) => (
<>
{'The requested page cannot be found. '}
{errorMessage !== undefined
? errorMessage.endsWith('.')
? errorMessage
Expand Down