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

refactor: Use Pagination component in react-uswds #897

Merged
merged 10 commits into from
Jan 17, 2023

Conversation

jcbcapps
Copy link
Contributor

SC-747

Proposed changes

With the merging of this PR into the ReactUSWDS library, we ported over the Pagination component developed for this project. This PR removes the Pagination component and imports it from the ReactUSWDS library.


Reviewer notes

Run the app locally and navigate to /about-us/orbit-blog and make sure that you have at least 10 ORBITBlog articles published in your local CMS. You should be able to see the Pagination component at the bottom of the page.

Bonus: a quick way to test out the different variations of the Pagination component, would be to adjust the value of the articlesPerPage variable on line 72 in orbit-blog.tsx. If you have a few articles published, then changing this number and refreshing the page will update the component.

Setup

The usual. Make sure you are running both the CMS and the portal client locally.


Code review steps

As the original developer, I have

  • Met the acceptance criteria, or will meet them in subsequent PRs or stories
    • ...
  • Created new stories in Storybook if applicable
    • Checked that all Storybook accessibility checks are passing
  • Created/modified automated unit tests in Jest
    • Including jest-axe checks when UI changes
  • Created/modified automated E2E tests in Cypress
    • Including cypress-axe checks when UI changes
    • Checked that the E2E test build is not failing
  • Performed a11y testing:
    • Checked responsiveness in mobile, tablet, and desktop
    • Checked keyboard navigability
    • Tested with VoiceOver in Safari
    • Checked VO's rotor menu for landmarks, page heading structure and links
    • Used a browser a11y tool to check for issues (WAVE, axe, ANDI or Accessibility addon tab for Storybook)
  • Requested a design review for user-facing changes
  • For any new migrations/schema changes:
    • Followed guidelines for zero-downtime deploys

As code reviewer(s), I have

  • Pulled this branch locally and tested it
  • Reviewed this code and left comments
  • Checked that all code is adequately covered by tests
    • Checked that the E2E test build is not failing
  • Made it clear which comments need to be addressed before this work is merged
  • Considered marking this as accepted even if there are small changes needed
  • Performed a11y testing:
    • Checked responsiveness in mobile, tablet, and desktop
    • Checked keyboard navigability
    • Tested with VoiceOver in Safari
    • Checked VO's rotor menu for landmarks, page heading structure and links
    • Used a browser a11y tool to check for issues (WAVE, axe, ANDI or Accessibility addon tab for Storybook)

As a designer reviewer, I have

  • Checked in the design translated visually
  • Checked behavior
  • Checked different states (empty, one, some, error)
  • Checked for landmarks, page heading structure, and links
  • Tried to break the intended flow
  • Performed a11y testing:
    • Checked responsiveness in mobile, tablet, and desktop
    • Checked keyboard navigability
    • Tested with VoiceOver in Safari
    • Checked VO's rotor menu for landmarks, page heading structure and links
    • Used a browser a11y tool to check for issues (WAVE, axe, ANDI or Accessibility addon tab for Storybook)

As a test user, I have

  • Run through the Test Script:
    • On commercial internet in IE11
    • On commercial internet in Firefox
    • On commercial internet in Chrome
    • On commercial internet in Safari
    • On NIPR in IE11
    • On NIPR in Firefox
    • On NIPR in Chrome
    • On NIPR in Safari
    • On a mobile device in Firefox
    • On a mobile device in Chrome
    • On a mobile device in Safari
  • Added any anomalous behavior to this PR

Screenshots

pagination-1
pagination-2

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #747: Use Pagination component in react-uswds instead of our own.

@@ -84,7 +84,7 @@ export const getServerSideProps: GetServerSideProps = async (
})
// Calculate total pages
// If NaN, return 1 page
const totalPages = Math.ceil(articlesCount / articlesPerPage) || 1
const totalPages = Math.floor(articlesCount / articlesPerPage) || 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This determines the number of pages to display in the Pagination component. If the number of published articles was exactly 10 (the number of articles per page, specified in a constant on line 72) Math.ceil was causing the calculation to round up, creating a page link in the component that just linked to an empty page. Changing this to Math.floor returns the greatest integer less than or equal to its numeric argument, fixing the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: I did some testing this seems to not be an issue because of Math.ceil but the fact that the graphql query articlesCount near line 75 is returning the total number of articles, regardless of their status. I had 12 in my db and page 2 didn't show up. I marked them as draft and the total count was still 12. So I've pushed a commit up that updates the query filter things down to just published and puts Math.ceil back in since with 12 articles we want 2 pages and 12/10 is 1.2.

Copy link
Contributor

@gidjin gidjin Jan 6, 2023

Choose a reason for hiding this comment

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

Probably worth eventually adding an e2e test for this, unless there are some orbit-blog unit tests around. Is this something we can test in src/__tests__/pages/about-us/orbit-blog.test.tsx? I would think mocking out the query with the where info and checking it's called at least would be enough, if it's possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch on the articlesCount! I'm not seeing any orbit-blog tests anywhere, but I agree we should test somehow. I can add that test file for the orbit-blog and mock out the query like you mentioned. Do you want me to also create a story in the backlog for an e2e test for pagination?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wanted to add, because I just found it, there is ArticleList.test.tsx that tests the pagination display. But the numbers are passed in manually via props. So I still don't think there is anything testing the actual query.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bummer, I think an e2e test would be good enough especially since that will test a real query. Though I would want to wait for the seed database work to be done before starting it since we'll need enough data to show the pagination. Long way to say yes please add a story to create an e2e test for this.

Copy link
Contributor

@gidjin gidjin left a comment

Choose a reason for hiding this comment

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

I haven't approved pending the question about if there is a way to add a test for the count since it was incorrectly returning all articles instead of only published.

@@ -84,7 +84,7 @@ export const getServerSideProps: GetServerSideProps = async (
})
// Calculate total pages
// If NaN, return 1 page
const totalPages = Math.ceil(articlesCount / articlesPerPage) || 1
const totalPages = Math.floor(articlesCount / articlesPerPage) || 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: I did some testing this seems to not be an issue because of Math.ceil but the fact that the graphql query articlesCount near line 75 is returning the total number of articles, regardless of their status. I had 12 in my db and page 2 didn't show up. I marked them as draft and the total count was still 12. So I've pushed a commit up that updates the query filter things down to just published and puts Math.ceil back in since with 12 articles we want 2 pages and 12/10 is 1.2.

@@ -84,7 +84,7 @@ export const getServerSideProps: GetServerSideProps = async (
})
// Calculate total pages
// If NaN, return 1 page
const totalPages = Math.ceil(articlesCount / articlesPerPage) || 1
const totalPages = Math.floor(articlesCount / articlesPerPage) || 1
Copy link
Contributor

@gidjin gidjin Jan 6, 2023

Choose a reason for hiding this comment

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

Probably worth eventually adding an e2e test for this, unless there are some orbit-blog unit tests around. Is this something we can test in src/__tests__/pages/about-us/orbit-blog.test.tsx? I would think mocking out the query with the where info and checking it's called at least would be enough, if it's possible.

@jcbcapps jcbcapps requested a review from a team as a code owner January 10, 2023 16:42
@jcbcapps jcbcapps requested a review from gidjin January 10, 2023 17:09
Copy link
Contributor

@gidjin gidjin left a comment

Choose a reason for hiding this comment

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

Changes look good, and since a story to add an e2e test will be created soon I'm approving this now.

Copy link
Contributor

@shkeating shkeating left a comment

Choose a reason for hiding this comment

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

As per the intro page, I think we still need to track this component in Happo because we want to be notified if any changes in global CSS results in unintended visual changes. I would say to refactor the stories pages, but not get rid of them.

I would move your original pagination.stories.tsx file into src/stories and change the output to use the imported react uswds component. this will also ensure the styling isn't getting changed by importing it from react uswds. in this branch's currnt state, we are deleting the component out of storybook, and in turn happo, so we can't tell if the component was impacted, and we will lost the ability to track future changes going forward.

image

Copy link
Contributor

@shkeating shkeating left a comment

Choose a reason for hiding this comment

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

sweet, happo confirms that the changes are not breaking, as you see the images are there (search 'pagination' in the 'Unchanged' tab, and even though its using the react uswds code, we aren't seeing any diffs ⭐️

@jcbcapps jcbcapps merged commit a325cda into main Jan 17, 2023
@jcbcapps jcbcapps deleted the sc-747/replace-pagination-component branch January 17, 2023 22:10
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.

3 participants