Skip to content

Commit

Permalink
Updated tests, react-query, patternfly standards
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewgdewar committed Dec 8, 2023
1 parent 2d82261 commit c875447
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 198 deletions.
22 changes: 18 additions & 4 deletions src/Pages/ContentListTable/ContentListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const ContentListTable = () => {

// Other update actions will be added to this later.
const actionTakingPlace =
isFetching || repositoryParamsLoading || isIntrospecting || isDeletingItems;
isFetching || repositoryParamsLoading || isIntrospecting || isDeletingItems;

const onSetPage = (_, newPage) => setPage(newPage);

Expand Down Expand Up @@ -283,7 +283,7 @@ const ContentListTable = () => {
{ isSeparator: true },
{
title: 'Delete',
onClick: () => navigate(`delete-repository?repoUUIDS=${rowData.uuid}?page=${page}?perPage=${perPage}?filterData=${filterData}`),
onClick: () => navigate(`delete-repository?repoUUIDS=${rowData.uuid}`),
},
],
[actionTakingPlace, checkedRepositories, isRedHatRepository],
Expand Down Expand Up @@ -362,7 +362,12 @@ const ContentListTable = () => {

return (
<>
<Outlet context={{ clearCheckedRepositories }} />
<Outlet
context={{
clearCheckedRepositories,
deletionContext: { page, perPage, filterData, contentOrigin, sortString: sortString() },
}}
/>
<Grid
data-ouia-safe={!actionTakingPlace}
data-ouia-component-id='content_list_page'
Expand Down Expand Up @@ -598,6 +603,15 @@ const ContentListTable = () => {
};

export const useContentListOutletContext = () =>
useOutletContext<{ clearCheckedRepositories: () => void }>();
useOutletContext<{
clearCheckedRepositories: () => void;
deletionContext: {
page: number;
perPage: number;
filterData: FilterData;
contentOrigin: ContentOrigin;
sortString: string;
};
}>();

export default ContentListTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { render } from '@testing-library/react';
import { ReactQueryTestWrapper, defaultContentItem } from '../../../../testingHelpers';
import { useFetchContent } from '../../../../services/Content/ContentQueries';
import DeleteContentModal from './DeleteContentModal';
import { ContentOrigin } from '../../../../services/Content/ContentApi';

jest.mock('react-query', () => ({
...jest.requireActual('react-query'),
useQueryClient: jest.fn(),
}));

jest.mock('react-router-dom', () => ({
useNavigate: jest.fn(),
useLocation: () => ({
search: `delete-repository?${defaultContentItem.uuid}`,
}),
}));

jest.mock('../../ContentListTable', () => ({
useContentListOutletContext: () => ({
clearCheckedRepositories: () => undefined,
deletionContext: {
page: 1,
perPage: 21,
filterData: undefined,
contentOrigin: ContentOrigin.EXTERNAL,
sortString: '',
},
}),
}));

jest.mock('../../../../Hooks/useRootPath', () => () => 'someUrl');

jest.mock('../../../../services/Content/ContentQueries', () => ({
useDeleteContentItemMutate: () => ({ mutate: () => undefined, isLoading: false }),
useFetchContent: jest.fn(),
}));

jest.mock('../../../../middleware/AppContext', () => ({ useAppContext: () => ({}) }));

it('Render Delete Modal', () => {
const data = defaultContentItem;
(useFetchContent as jest.Mock).mockImplementation(() => ({
isLoading: false,
data: data,
}));

const { queryByText } = render(
<ReactQueryTestWrapper>
<DeleteContentModal />
</ReactQueryTestWrapper>,
);

expect(queryByText(defaultContentItem.name)).toBeInTheDocument();
expect(queryByText(defaultContentItem.url)).toBeInTheDocument();
expect(queryByText(defaultContentItem.distribution_arch)).toBeInTheDocument();
expect(queryByText(defaultContentItem.distribution_versions[0])).toBeInTheDocument();
expect(queryByText('None')).not.toBeInTheDocument();
});

it('Render Delete Modal with no gpg key', () => {
const data = defaultContentItem;
data.gpg_key = '';
(useFetchContent as jest.Mock).mockImplementation(() => ({
isLoading: false,
data: data,
}));

const { queryByText } = render(
<ReactQueryTestWrapper>
<DeleteContentModal />
</ReactQueryTestWrapper>,
);

expect(queryByText(defaultContentItem.name)).toBeInTheDocument();
expect(queryByText(defaultContentItem.url)).toBeInTheDocument();
expect(queryByText(defaultContentItem.distribution_arch)).toBeInTheDocument();
expect(queryByText(defaultContentItem.distribution_versions[0])).toBeInTheDocument();
expect(queryByText('None')).toBeInTheDocument();
});

This file was deleted.

Loading

0 comments on commit c875447

Please sign in to comment.