Skip to content

LG-8507 Search Results Pluralization#7728

Merged
JackRyan1989 merged 5 commits intomainfrom
jryan/lg-8507-search-results-pluralization
Jan 31, 2023
Merged

LG-8507 Search Results Pluralization#7728
JackRyan1989 merged 5 commits intomainfrom
jryan/lg-8507-search-results-pluralization

Conversation

@JackRyan1989
Copy link
Contributor

🎫 Ticket

🛠 Summary of changes

  • Added one and other fields to in_person_proofing.body.location.po_search.results_description
  • Updated copy in each appropriate field for each available translation: en, es, and fr.
  • Added two test cases: 1. checking correct pluralization for single results 2. checking correct pluralization for multiple (in this case 2) results.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Confirm front end changes for each translation: english, spanish and french
  • Confirm that i18n tests pass.
  • Confirm that new test spec passes.

@JackRyan1989 JackRyan1989 requested a review from a team January 30, 2023 21:14
@JackRyan1989 JackRyan1989 self-assigned this Jan 30, 2023
@JackRyan1989 JackRyan1989 removed their assignment Jan 30, 2023
Copy link
Contributor

@allthesignals allthesignals left a comment

Choose a reason for hiding this comment

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

I just had a concern about false positives, let me know if I'm missing something

Comment on lines +259 to +265
const searchResultAlert = findByText(
t('in_person_proofing.body.location.po_search.results_description', {
address: '222 Merchandise Mart Plaza',
count: MULTI_LOCATION_RESPONSE.length,
}),
);
expect(searchResultAlert).to.exist();
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't recall exactly how i18n works in the test context but it surprises me that this would work... are you sure this isn't a false positive? Like, maybe it isn't interpolating those values and you're just asserting for in_person_proofing.body.location.po_search.results_description (I'd expect it t to ignore the params).

That said, I'm not really sure!

Copy link
Contributor

@aduth aduth Jan 30, 2023

Choose a reason for hiding this comment

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

findByText returns a promise, which will be truthy, but I don't think that's what you're actually wanting to test.

!!new Promise(() => {})
// true

I expect you'd want to await the findByText, which will throw if it never finds the text.

https://testing-library.com/docs/queries/about/#types-of-queries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Matt, I'm trying to replicate as closely as possible what's happening in in-person-locations.tsx:

<h3 role="status">
        {!isPilot &&
          t('in_person_proofing.body.location.po_search.results_description', {
            address,
            count: locations?.length,
          })}
 </h3>

So I think t does take in a second parameter that is an object.

Copy link
Contributor Author

@JackRyan1989 JackRyan1989 Jan 30, 2023

Choose a reason for hiding this comment

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

findByText returns a promise, which will be truthy, but I don't think that's what you're actually wanting to test.

!!new Promise(() => {})
// true

I expect you'd want to await the findByText, which will throw if it never finds the text.

Great catch! I'm incorporating that change.

Copy link
Contributor

Choose a reason for hiding this comment

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

@JackRyan1989 yup, it does take that as an argument, but I'm not sure this works the same way in the test environment since it displays the translation paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok gotcha. Yeah you're right. It's not actually translating the content:

Screen Shot 2023-01-30 at 4 49 38 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I was thinking about this a little bit more... I'm not sure what one should do in this case.

It'd be nice if our i18n library would append dynamic arguments to the dictionary path when under test. Then we could assert for evidence of the behavior. Or it could even append which one it rendered: results_description.one or results_description.other.

@aduth any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or it could even append which one it rendered: results_description.one or results_description.other.

yeah that matches my expectations, we'd render the one or the other "string" which in this case happens to be the key

Copy link
Contributor

Choose a reason for hiding this comment

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

@JackRyan1989 @zachmargolis made a great suggestion, and I gave it a shot in a branch here: https://github.com/18F/identity-idp/tree/wmg/lg-8507-test-setup

I did run into some snags with the (confusing) way I set up the test here...

  1. Note that you'll want your MULTI_LOCATION_RESPONSE as the response body of LOCATIONS_URL, not ADDRESS_SEARCH_URL.
  2. I think the before hook you were using wasn't getting applied to the relevant test. I went ahead and moved it inside the test in the branch linked above... open to feedback on a better way to organize test-specific server responses because it's still a pain point to use.

Copy link
Contributor

@aduth aduth Jan 31, 2023

Choose a reason for hiding this comment

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

By default, there is no locale data loaded in the test environment, and the default behavior of the i18n library absent locale strings is to render the given string. This is usually okay for testing, but unfortunately it doesn't account for pluralization, so you either have to be content in testing the parent key, or set up the locale data in the tests with pluralization data (plain JS approach, React context approach). (Edit: I see this is what @zachmargolis recommended in the linked Slack thread 🤦 )

@allthesignals allthesignals mentioned this pull request Jan 31, 2023
@allthesignals allthesignals self-requested a review January 31, 2023 16:35
Copy link
Contributor

@allthesignals allthesignals left a comment

Choose a reason for hiding this comment

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

Great!

@JackRyan1989 JackRyan1989 merged commit 6f68fd9 into main Jan 31, 2023
@JackRyan1989 JackRyan1989 deleted the jryan/lg-8507-search-results-pluralization branch January 31, 2023 17:04
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.

5 participants