LG-8507 Search Results Pluralization#7728
Conversation
…ation of search results
…-search-results-pluralization
allthesignals
left a comment
There was a problem hiding this comment.
I just had a concern about false positives, let me know if I'm missing something
| 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(); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
findByText returns a promise, which will be truthy, but I don't think that's what you're actually wanting to test.
!!new Promise(() => {})
// trueI 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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
findByTextreturns a promise, which will be truthy, but I don't think that's what you're actually wanting to test.!!new Promise(() => {}) // trueI expect you'd want to
awaitthefindByText, which will throw if it never finds the text.
Great catch! I'm incorporating that change.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Or it could even append which one it rendered:
results_description.oneorresults_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
There was a problem hiding this comment.
@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...
- Note that you'll want your
MULTI_LOCATION_RESPONSEas the response body ofLOCATIONS_URL, notADDRESS_SEARCH_URL. - I think the
beforehook 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.
There was a problem hiding this comment.
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 🤦 )

🎫 Ticket
🛠 Summary of changes
oneandotherfields toin_person_proofing.body.location.po_search.results_description📜 Testing Plan
Provide a checklist of steps to confirm the changes.