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

Conversation

duncan-at-hiveit
Copy link
Collaborator

This PR:

  • Corrects the link location for the "Data and files" link in the "Create a data set" modal by adding the "Data uploads" tab hash to the target URL.
  • Closes the modal upon click.

@duncan-at-hiveit duncan-at-hiveit marked this pull request as ready for review November 25, 2024 14:05
Comment on lines 51 to 72
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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to click the link and navigate - just assert that the link has the correct href. Additionally, we can tighten up the checks to be within the modal.

We can replace these lines with the following:

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

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

expect(modal.getByRole('link', { name: 'Data and files' })).toHaveAttribute(
  'href',
  '/publication/publication-id/release/release-id/data#data-uploads',
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ntsim thanks for that. I'd seen that approach elsewhere as well.

The only thing that the clicking and navigation does show in and above this is that the modal is successfully closed with the navigation:

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

Without the navigation step, we don't know that the modal has been automatically closed. This being the case, would you still prefer the changes you requested, or is there maybe some other way to check for the modal closing without needing to do a full navigation perhaps?

Copy link
Collaborator

@ntsim ntsim Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the benefit is of checking that the modal has closed?

Routing is well understood to work correctly, so if a user clicks a link, the current page unmounts and is replaced by the next route's page component.

The direct implication of this is that the modal is unmounted as well because it's only mounted via the current page (which is unmounted after navigating). Clicking the link would just redundantly test that routing works, so I'm not sure why we'd want to do this given we don't typically test that links can navigate.

Additionally, to actually make an 'end-to-end' navigation, you'd need to set additional stuff up for this test, which is just out of scope tbh.

Would suggest we proceed with the changes I've outlined above!

@@ -29,6 +29,8 @@ describe('ApiDataSetCreateModal', () => {
];

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't navigate into the link, we don't need to check the history and can remove this (and it's usage below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous reply above, ta!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

@duncan-at-hiveit duncan-at-hiveit force-pushed the EES-5558-data-and-file-link-in-api-data-set-modal branch from 5ee45b4 to 029fc49 Compare December 2, 2024 17:19
@duncan-at-hiveit duncan-at-hiveit merged commit 48ee898 into dev Dec 2, 2024
2 checks passed
@duncan-at-hiveit duncan-at-hiveit deleted the EES-5558-data-and-file-link-in-api-data-set-modal branch December 2, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants