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

Make listing details modal close on internally-triggered navigation #14504

Merged
merged 4 commits into from
Aug 18, 2021
Merged

Make listing details modal close on internally-triggered navigation #14504

merged 4 commits into from
Aug 18, 2021

Conversation

fyodorio
Copy link
Contributor

@fyodorio fyodorio commented Aug 16, 2021

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

The detailed description is here but in general, when you (1) go to the listings page and (2) open one of the listings by clicking its title, and then (3) try to navigate from it to the specific category this listing belongs to (by clicking category name in the listing modal footer), (4) navigation happens on the background but (5) modal window doesn't close (though it should).

The solution is simple - we can check if a modal is open in selectCategory() handler in listings.jsx and if it is - close the modal.

Ideally it would probably be better to hook up on navigation event inside the Modal component itself, but that's not how it works now everywhere else in the code so I would suggest to stick with this (more specific) solution.

Related Tickets & Documents

CLOSES #14459

QA Instructions, Screenshots, Recordings

Steps to reproduce are described in the issue details 👆

Added/updated tests?

  • Yes
  • No, and this is why
  • I need help with writing tests

[Forem core team only] How will this change be communicated?

Will this PR introduce a change that impacts Forem members or creators, the
development process, or any of our internal teams? If so, please note how you
will share this change with the people who need to know about it.

  • I've updated the Developer Docs and/or
    Admin Guide, or
    Storybook (for Crayons components)
  • I've updated the README or added inline documentation
  • I've added an entry to
    CHANGELOG.md
  • I will share this change in a Changelog
    or in a forem.dev post
  • I will share this change internally with the appropriate teams
  • I'm not sure how best to communicate this change and need help
  • This change does not need to be communicated, and this is why not: please
    replace this line with details on why this change doesn't need to be
    shared

[optional] What gif best describes this PR or how it makes you feel?

alt_text

* Provide a way to close modal if it's open
@fyodorio fyodorio requested a review from a team August 16, 2021 04:12
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Aug 16, 2021
@fyodorio fyodorio requested review from Ridhwana and msarit and removed request for a team August 16, 2021 04:12
@CLAassistant
Copy link

CLAassistant commented Aug 16, 2021

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link
Contributor

Thank you for opening this PR! We appreciate you!

For all pull requests coming from third-party forks we will need to
review the PR before we can process it through our CI pipelines.

A Forem Team member will review this contribution and get back to
you as soon as possible!

Copy link
Contributor

@rhymes rhymes left a comment

Choose a reason for hiding this comment

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

Works perfectly, thank you @fyodorio!

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Aug 16, 2021
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Aug 16, 2021
@rhymes
Copy link
Contributor

rhymes commented Aug 16, 2021

@fyodorio for some reason Travis was stuck, so I added an empty commit to unstuck it :D

@msarit
Copy link
Contributor

msarit commented Aug 16, 2021

@nickytonline @aitchiss Hey Nick and Suzanne, could you weigh in on the addition of a test for this PR? The contributor had this to say:

I'd tried to create a test file using app/javascript/listings/__tests__/ListingDashboard.test.jsx as an example to write some kind of an integration test for the scenario, but wasn't able to compile the container correctly. I suppose I'm doing something wrong with regards to the component being server-rendered (as far as I understand). I would be happy to add the test (if necessary) if someone would be able to help me with scaffolding the suite for it.

@aitchiss
Copy link
Contributor

I think this change would be a great fit for a Cypress integration test - you can check this section in our docs for full details of how we use Cypress & some best practice tips.

This could be a new file in the directory cypress/integration/seededFlows/listingFlows/, and you can see an example of a Cypress test opening up a mocked listing in cypress/integration/seededFlows/listingFlows/viewListing.spec.js:

it('opens a listing from the listings page', () => {
cy.intercept(
'/search/listings?category=&listing_search=&page=0&per_page=75&tag_boolean_mode=all',
{ fixture: 'search/listings.json' },
);
cy.visit('/listings');
cy.findByRole('link', { name: 'Listing title' }).as('listingTitle');
cy.get('@listingTitle').click();
cy.findByTestId('listings-modal').as('listingsModal');
cy.get('@listingsModal').findByText('Listing').should('exist');
cy.get('@listingsModal').findByText('Listing title').should('exist');
cy.get('@listingsModal')
.findAllByRole('button')
.first()
.should('have.focus');
cy.get('@listingsModal').findByRole('button', { name: /Close/ }).click();
cy.get('@listingTitle').should('have.focus');
});

I'm thinking your test could be very similar the one above, but instead of closing the open modal, selecting a link from inside it and then checking the modal is no longer visible.

Let me know how you get on and if you have any difficulties 👍

@fyodorio
Copy link
Contributor Author

@aitchiss thanks for the guidance Suzanne, sounds good, will write the test and update the PR 👌

@fyodorio fyodorio marked this pull request as draft August 17, 2021 16:42
@pr-triage pr-triage bot added PR: draft bot applied label for PR's that are a work in progress and removed PR: unreviewed bot applied label for PR's with no review labels Aug 18, 2021
@fyodorio fyodorio marked this pull request as ready for review August 18, 2021 08:53
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: draft bot applied label for PR's that are a work in progress labels Aug 18, 2021
@fyodorio
Copy link
Contributor Author

@aitchiss @rhymes @msarit @Ridhwana I have just added the e2e test case, please take a look

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Aug 18, 2021
@rhymes rhymes merged commit 56669ec into forem:main Aug 18, 2021
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Aug 18, 2021
@fyodorio fyodorio deleted the fyodorio/close-listing-details-modal-on-navigation-14459 branch August 18, 2021 14:56
@cmgorton
Copy link
Contributor

cmgorton commented Sep 3, 2021

@fyodorio thanks again for working on this bug. We are wrapping up the bug smash event and I wanted to encourage you to write a post about your experience if you have time.
You can use this template.
https://dev.to/new/devbugsmash

@fyodorio
Copy link
Contributor Author

@fyodorio thanks again for working on this bug. We are wrapping up the bug smash event and I wanted to encourage you to write a post about your experience if you have time.
You can use this template.
https://dev.to/new/devbugsmash

Done, @cmgorton, sorry that it's quite late, busy September 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Listing details modal doesn't close on navigation event triggered from it
7 participants