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
54 changes: 54 additions & 0 deletions frontend/public/components/factory/__tests__/list-page.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,58 @@ describe('MultiListPage component', () => {
expect(watchConfig?.Pod?.kind).toBe('Pod');
expect(watchConfig?.Pod?.name).toBe('example-pod');
});

it('does not treat errors from optional resources as fatal page errors', () => {
let receivedLoadError: unknown;
const ListComponent = (props: { loadError?: unknown }) => {
receivedLoadError = props.loadError;
return <div>List Content</div>;
};

mockUseK8sWatchResources.mockReturnValue({
Pod: { data: [{ kind: 'Pod' }], loaded: true, loadError: undefined },
CatalogSource: {
data: [],
loaded: true,
loadError: 'catalogsources.operators.coreos.com is forbidden',
},
});

renderWithProviders(
<MultiListPage
ListComponent={ListComponent}
resources={[
{ kind: 'Pod', prop: 'Pod' },
{ kind: 'CatalogSource', prop: 'CatalogSource', optional: true },
]}
filterLabel="by name"
/>,
);

expect(screen.getByText('List Content')).toBeVisible();
expect(receivedLoadError).toBeUndefined();
});

it('treats errors from non-optional resources as fatal page errors', () => {
let receivedLoadError: unknown;
const ListComponent = (props: { loadError?: unknown }) => {
receivedLoadError = props.loadError;
return <div>List Content</div>;
};

const forbiddenError = 'pods is forbidden';
mockUseK8sWatchResources.mockReturnValue({
Pod: { data: [], loaded: true, loadError: forbiddenError },
});

renderWithProviders(
<MultiListPage
ListComponent={ListComponent}
resources={[{ kind: 'Pod', prop: 'Pod' }]}
filterLabel="by name"
/>,
);

expect(receivedLoadError).toBe(forbiddenError);
});
});
11 changes: 7 additions & 4 deletions frontend/public/components/factory/list-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,13 @@ export const MultiListPage: FC<MultiListPageProps> = (props) => {

const loadError = useMemo(
() =>
Object.values(watchedResources).find(
(r) => r.loadError && !(r.loadError instanceof NoModelError),
)?.loadError,
[watchedResources],
Object.entries(watchedResources).find(
([key, r]) =>
r.loadError &&
!(r.loadError instanceof NoModelError) &&
!watchResources[key]?.optional,
)?.[1]?.loadError,
[watchedResources, watchResources],
);

const reduxIDs = useMemo(
Expand Down