Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,68 @@ import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ErrorBoundary } from 'react-error-boundary';
import { renderWrapper } from '@src/setupTest';
import LibrariesErrorFallback from './index';
import ErrorFallback from './index';

const ThrowError = ({ error }: { error:Error }) => {
throw error;
return null;
};

describe('LibrariesErrorFallback', () => {
describe('ErrorFallback', () => {
it('renders Access Denied for 401', () => {
const error = { name: '', message: 'NO_ACCESS', customAttributes: { httpErrorStatus: 401 } };
renderWrapper(
<ErrorBoundary FallbackComponent={LibrariesErrorFallback}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<ThrowError error={error} />
</ErrorBoundary>,
);
expect(screen.getByText(/Access Denied/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Libraries/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Studio/i)).toBeInTheDocument();
});

it('renders Not Found for 400 error', () => {
const error = { name: '', message: 'Axios Error (Response): 400', customAttributes: { httpErrorStatus: 400 } };
renderWrapper(
<ErrorBoundary FallbackComponent={LibrariesErrorFallback}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<ThrowError error={error} />
</ErrorBoundary>,
);
expect(screen.getByText(/Page Not Found/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Libraries/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Studio/i)).toBeInTheDocument();
});

it('renders Not Found for 404', () => {
const error = { name: '', message: 'NOT_FOUND', customAttributes: { httpErrorStatus: 404 } };
renderWrapper(
<ErrorBoundary FallbackComponent={LibrariesErrorFallback}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<ThrowError error={error} />
</ErrorBoundary>,
);
expect(screen.getByText(/Page Not Found/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Libraries/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Studio/i)).toBeInTheDocument();
});

it('renders Server Error for 500 and shows reload', async () => {
const error = { name: '', message: 'SERVER_ERROR', customAttributes: { httpErrorStatus: 500 } };
renderWrapper(
<ErrorBoundary FallbackComponent={LibrariesErrorFallback}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<ThrowError error={error} />
</ErrorBoundary>,
);
expect(screen.getByText(/Something went wrong/i)).toBeInTheDocument();
expect(screen.getByText(/Reload Page/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Libraries/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Studio/i)).toBeInTheDocument();
});

it('renders generic error for other error error', () => {
const error = { name: '', message: 'SOMETHING_ELSE', customAttributes: { httpErrorStatus: 418 } };
renderWrapper(
<ErrorBoundary FallbackComponent={LibrariesErrorFallback}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<ThrowError error={error} />
</ErrorBoundary>,
);
expect(screen.getByText(/Error/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Libraries/i)).toBeInTheDocument();
expect(screen.getByText(/Back to Studio/i)).toBeInTheDocument();
});

it('calls reload action if present', async () => {
Expand All @@ -73,7 +73,7 @@ describe('LibrariesErrorFallback', () => {
name: '', message: 'SERVER_ERROR', customAttributes: { httpErrorStatus: 500 }, refetch,
};
renderWrapper(
<ErrorBoundary FallbackComponent={LibrariesErrorFallback} onReset={refetch}>
<ErrorBoundary FallbackComponent={ErrorFallback} onReset={refetch}>
<ThrowError error={error} />
</ErrorBoundary>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
{showBackButton && (
<Button
as={Hyperlink}
destination={`${getConfig().COURSE_AUTHORING_MICROFRONTEND_URL}/libraries`}
destination={`${getConfig().COURSE_AUTHORING_MICROFRONTEND_URL}`}
className="m-2"
variant={showReloadButton ? 'outline-primary' : 'primary'}
>
Expand All @@ -93,5 +93,5 @@ const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
);
};

const LibrariesErrorFallback = (props: FallbackProps) => <ErrorPage {...props} />;
export default LibrariesErrorFallback;
const ErrorFallback = (props: FallbackProps) => <ErrorPage {...props} />;
export default ErrorFallback;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const messages = defineMessages({
},
'error.page.message.notFound': {
id: 'error.page.message.notFound',
defaultMessage: 'The library you are looking for could not be found.',
defaultMessage: 'The resource you are looking for could not be found.',
description: 'Error message when the resource is not found',
},
'error.page.title.server': {
Expand Down Expand Up @@ -48,8 +48,8 @@ const messages = defineMessages({
},
'error.page.action.back': {
id: 'error.page.action.back',
defaultMessage: 'Back to Libraries',
description: 'Label for return to libraries action',
defaultMessage: 'Back to Studio',
description: 'Label for return to Studio action',
},
});

Expand Down
2 changes: 0 additions & 2 deletions src/authz-module/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,6 @@ export const SKELETON_ROWS = Array.from({ length: 10 }).map(() => ({

export const ROUTES = {
HOME_PATH: '/authz',
LIBRARIES_TEAM_PATH: '/libraries/:libraryId',
LIBRARIES_USER_PATH: '/libraries/:libraryId/:username',
AUDIT_USER_PATH: '/user/:username',
ASSIGN_ROLE_WIZARD_PATH: '/assign-role',
};
Expand Down
51 changes: 1 addition & 50 deletions src/authz-module/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { ComponentType, lazy } from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { MemoryRouter, Outlet } from 'react-router-dom';
import { MemoryRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { initializeMockApp } from '@edx/frontend-platform/testing';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { CustomErrors } from '@src/constants';
import AuthZModule from './index';

jest.mock('./libraries-manager', () => ({
// eslint-disable-next-line no-promise-executor-return
LibrariesLayout: lazy(() => new Promise<{ default: ComponentType<any> }>(resolve => setTimeout(
() => resolve({ default: () => <div><Outlet /></div> }),
100,
))),
LibrariesTeamManager: () => <div>Libraries Team Page</div>,
LibrariesUserManager: () => <div>Libraries User Page</div>,
}));

const createTestQueryClient = () => new QueryClient({
defaultOptions: {
queries: {
Expand All @@ -32,44 +21,6 @@ describe('AuthZModule', () => {
authenticatedUser: { username: 'testuser' },
});
});
it('renders LoadingPage then LibrariesTeamManager when route matches', async () => {
const queryClient = createTestQueryClient();
const path = '/libraries/lib:123';

render(
<IntlProvider locale="en">
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={[path]}>
<AuthZModule />
</MemoryRouter>
</QueryClientProvider>
</IntlProvider>,
);

expect(document.querySelector('.spinner-border')).toBeInTheDocument();

await waitFor(() => {
expect(screen.getByText('Libraries Team Page')).toBeInTheDocument();
});
});

it('renders LoadingPage then LibrariesUserManager when user route matches', async () => {
const queryClient = createTestQueryClient();
const path = '/libraries/lib:123/testuser';

render(
<IntlProvider locale="en">
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={[path]}>
<AuthZModule />
</MemoryRouter>
</QueryClientProvider>
</IntlProvider>,
);
await waitFor(() => {
expect(screen.getByText('Libraries User Page')).toBeInTheDocument();
});
});

it('renders error boundary fallback when accessing unknown route', async () => {
const queryClient = createTestQueryClient();
Expand Down
14 changes: 3 additions & 11 deletions src/authz-module/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { Routes, Route } from 'react-router-dom';
import { ErrorBoundary } from 'react-error-boundary';
import { QueryErrorResetBoundary } from '@tanstack/react-query';
import LoadingPage from '@src/components/LoadingPage';
import LibrariesErrorFallback from '@src/authz-module/libraries-manager/ErrorPage';
import ErrorFallback from '@src/authz-module/components/ErrorPage';
import { CustomErrors } from '@src/constants';
import { ToastManagerProvider } from '@src/components/ToastManager/ToastManagerContext';
import { LibrariesUserManager, LibrariesLayout, LibrariesTeamManager } from './libraries-manager';
import AuthzHome from './authz-home';
import AuditUserPage from './audit-user';
import AssignRoleWizardPage from './role-assignation-wizard/AssignRoleWizardPage';
Expand All @@ -22,19 +21,12 @@ const NotFoundError = () => {
const AuthZModule = () => (
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary fallbackRender={LibrariesErrorFallback} onReset={reset}>
<ErrorBoundary fallbackRender={ErrorFallback} onReset={reset}>
<ToastManagerProvider>
<Suspense fallback={<LoadingPage />}>
<Routes>
<Route element={<LibrariesLayout />}>
<Route path={ROUTES.LIBRARIES_USER_PATH} element={<LibrariesUserManager />} />
<Route path={ROUTES.LIBRARIES_TEAM_PATH} element={<LibrariesTeamManager />} />
</Route>
<Route index element={<AuthzHome />} />
<Route
path={ROUTES.AUDIT_USER_PATH}
element={<AuditUserPage />}
/>
<Route path={ROUTES.AUDIT_USER_PATH} element={<AuditUserPage />} />
<Route path={ROUTES.ASSIGN_ROLE_WIZARD_PATH} element={<AssignRoleWizardPage />} />
<Route path="*" element={<NotFoundError />} />
</Routes>
Expand Down
149 changes: 0 additions & 149 deletions src/authz-module/libraries-manager/LibrariesTeamManager.test.tsx

This file was deleted.

Loading