Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EES-5558 - got "Data and files" link to close modal and navigate to t… #5411

Merged
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 @@ -15,6 +15,7 @@ import useToggle from '@common/hooks/useToggle';
import { useQuery } from '@tanstack/react-query';
import React, { ReactNode } from 'react';
import { generatePath } 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 @@ -4,7 +4,7 @@ import _apiDataSetCandidateService, {
} from '@admin/services/apiDataSetCandidateService';
import _apiDataSetService from '@admin/services/apiDataSetService';
import baseRender from '@common-test/render';
import { screen, waitFor } from '@testing-library/react';
import { screen, waitFor, within } from '@testing-library/react';
import { createMemoryHistory, History } from 'history';
import noop from 'lodash/noop';
import { ReactElement } from 'react';
Expand Down Expand Up @@ -39,17 +39,30 @@ describe('ApiDataSetCreateModal', () => {
/>,
);

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();

const modal = within(screen.getByRole('dialog'));

expect(
await screen.findByText(
modal.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(modal.getByRole('link', { name: 'Data and files' })).toHaveAttribute(
'href',
'/publication/publication-id/release/release-id/data#data-uploads',
);

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

expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});

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

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

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

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