Skip to content

Commit

Permalink
EES-5558 - got "Data and files" link to close modal and navigate to t…
Browse files Browse the repository at this point in the history
…he Data Uploads tab
  • Loading branch information
duncan-at-hiveit committed Dec 2, 2024
1 parent 14e9289 commit 3fcdf91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import WarningMessage from '@common/components/WarningMessage';
import useToggle from '@common/hooks/useToggle';
import { useQuery } from '@tanstack/react-query';
import React, { ReactNode } from 'react';
import { generatePath } from 'react-router-dom';
import { generatePath, useHistory } from 'react-router-dom';
import releaseDataPageTabIds from '@admin/pages/release/data/utils/releaseDataPageTabIds';

interface Props {
buttonText?: ReactNode | string;
Expand Down Expand Up @@ -65,10 +66,11 @@ export default function ApiDataSetCreateModal({
No API data sets can be created as there are no candidate data
files available. New candidate data files can be uploaded in the{' '}
<Link
to={generatePath<ReleaseRouteParams>(releaseDataRoute.path, {
to={`${generatePath<ReleaseRouteParams>(releaseDataRoute.path, {
publicationId,
releaseId,
})}
})}#${releaseDataPageTabIds.dataUploads}`}
onClick={toggleOpen.off}
>
Data and files
</Link>{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('ApiDataSetCreateModal', () => {
];

test('renders warning message in modal when no candidates', async () => {
const history = createMemoryHistory();

apiDataSetCandidateService.listCandidates.mockResolvedValue([]);

const { user } = render(
Expand All @@ -37,19 +39,37 @@ describe('ApiDataSetCreateModal', () => {
releaseId="release-id"
onSubmit={noop}
/>,
{ history },
);

expect(await screen.findByText('Create API data set')).toBeInTheDocument();

await user.click(
await screen.findByRole('button', { name: 'Create API data set' }),
);

expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();

expect(
await screen.findByText(
screen.getByText(
/No API data sets can be created as there are no candidate data files available/,
),
).toBeInTheDocument();

expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
expect(
await screen.findByRole('link', { name: 'Data and files' }),
).toBeInTheDocument();

await user.click(screen.getByRole('link', { name: 'Data and files' }));

expect(
screen.queryByRole('link', { name: 'Data and files' }),
).not.toBeInTheDocument();

expect(history.location.pathname).toEqual(
'/publication/publication-id/release/release-id/data',
);
expect(history.location.hash).toEqual('#data-uploads');
});

test('renders form in modal when there are candidates', async () => {
Expand Down Expand Up @@ -98,7 +118,6 @@ describe('ApiDataSetCreateModal', () => {
previousReleaseIds: [],
});

const history = createMemoryHistory();
const handleSubmit = jest.fn();

const { user } = render(
Expand All @@ -107,7 +126,6 @@ describe('ApiDataSetCreateModal', () => {
releaseId="release-id"
onSubmit={handleSubmit}
/>,
{ history },
);

expect(await screen.findByText('Create API data set')).toBeInTheDocument();
Expand Down

0 comments on commit 3fcdf91

Please sign in to comment.