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
Fix Search header doesn't mention type #3154 #3161
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right idea but unfortunately you'll need to create a string for each add-on type. I think doing it just for ADDON_TYPE_EXTENSION
, ADDON_TYPE_DICT
, ADDON_TYPE_LANG
, and ADDON_TYPE_THEME
like in https://github.com/mozilla/addons-frontend/blob/master/src/amo/components/SearchForm/index.js#L207 should be fine.
You'll also need to add tests for these strings. All your tests are passing but you're missing test coverage for the code you added, so you'll want to look at the TestSearchContextCard
and add test cases for each one of these states.
|
||
let searchText; | ||
|
||
if (!loading && query) { | ||
if (!loading && query && addonType) { | ||
const addon = addonType === 'persona' ? 'theme' : addonType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately addonType
is not localised, so this won't work in any language that isn't English (and even then, addonType
isn't very readible if it's something like langpack
).
So this will need to be more of an if
/else
case like we have here: https://github.com/mozilla/addons-frontend/blob/master/src/amo/components/SearchForm/index.js#L207
Sorry about that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright! I don't know why I didn't think of it. Sorry, my bad!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, we've made the same mistake too, that's the only reason why I knew to look out for it! 😉
Codecov Report
@@ Coverage Diff @@
## master mozilla/addons-frontend#3161 +/- ##
==========================================
+ Coverage 95.1% 95.13% +0.03%
==========================================
Files 155 155
Lines 2837 2856 +19
Branches 555 564 +9
==========================================
+ Hits 2698 2717 +19
Misses 120 120
Partials 19 19
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the really good test specs (and the tests!)
This looks great, aside from just a few tweaks in the test file it's good. The only major thing to fix is to put the entire string in the gettext call (eg ``'%(count)s dictionaries found for "%(query)s"'instead of substituing in the
addonType`.)
We tried to do that in the past but there are edge cases with localisation. Sorry about that, it's annoying but it's the best way to get the best localisations.
Thanks so much for the quick reply to my earlier review though. 😄
|
||
if (!loading && query) { | ||
if (addonType === ADDON_TYPE_EXTENSION) { | ||
addOn = i18n.ngettext('extension', 'extensions', count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is clever but unfortunately it's best to put the entire string in here instead. Some locales have complex pluralisation rules and it's best to have the entire string in context. I know it's a bit less elegant that way, but if you look at the example I referenced earlier that's how we do it. Could you put the entire string (in both singular and plural forms) in one gettext call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure, thanks for letting me know regarding this. Will keep this in mind in future.
'%(count)s %(addOn)s found for "%(query)s"' | ||
), { count: i18n.formatNumber(count), addOn, query } | ||
); | ||
} else if (!loading && query && !addonType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the !addonType
is redundant; because you test for addonType
above and this is otherwise the same check you can just remove that check here 😄
.toIncludeText('2 extensions found for "test"'); | ||
}); | ||
|
||
// addonType = ADDON_TYPE_EXTENSION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need these comments here, you wrote really good test specs actually (👍🏻) and the dispatchSearchResults
calls show which type you're using so you can remove these comments.
.toIncludeText('1 dictionary found for "test"'); | ||
}); | ||
|
||
it('should render plural form when multipe results are found with addonType as ADDON_TYPE_DICT', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here: multipe should be multiple. 😄
}); | ||
|
||
// addonType = ADDON_TYPE_DICT | ||
it('should render singular form when only one result is found with addonType as ADDON_TYPE_DICT', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just end with ADDON_TYPE_DICT
instead of addonType as ADDON_TYPE_DICT
. Similar for the rest of the test specs.
They're otherwise really good though, thanks for writing really clear test specs! 👍
@tofumatt , I have updated the code. Please let me know if you recommend any more changes. Thanks. |
'%(count)s themes found for "%(query)s"', | ||
count), { count: i18n.formatNumber(count), query } | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use an else
block that shows some kind of generic message like '12 results found for...'
@kumar303, I was gonna do that before but couldn't find a test case regarding the same when the |
Thanks. The |
@kumar303 , Here is what I think, the |
It's an edge case but it's still possible. You can get trigger a "valid" search with this archaic type (if you edit the URL): http://localhost:3000/en-US/firefox/search/?platform=mac&q=firefox&type=theme This |
@kumar303 , it works for the cases if |
@kumar303, Take this for an example, The screen is stuck there since |
That looks like a separate bug. It's not so important since no user would see it while using the site. |
@kumar303 , Okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It looks like you also addressed @tofumatt's change requests so we can merge this.
Thanks so much for the patch, @PunitGr! Your contribution has been added to our recognition wiki. If you'd like to set up a profile on mozillians.org, I would be happy to vouch for you. Welcome onboard! I look forward to seeing you around. :) |
Hi @caitmuenster Thank you so much for the invitation. I've set up my profile. I would be grateful if you can vouch for my profile here https://mozillians.org/en-US/u/PunitGr/ |
\o/ You're all vouched! |
Fixes mozilla/addons#10778
This PR fixes the
Search Header mention type issue
which appears while searching a query.I've updated the
SearchText
string by usingaddonType
fromfilters
which fixes this bug. Also, changed theaddonType
text to plural if search results are more than 1.Screenshots
Thanks!