-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add LocalizedMoneyInput Component #339
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.
Oh, I forgot to submit 🙈. Hopefully not all outdated
src/components/inputs/localized-money-input/localized-money-input.js
Outdated
Show resolved
Hide resolved
src/components/inputs/localized-money-input/localized-money-input.percy.js
Outdated
Show resolved
Hide resolved
selectedCurrency: 'CAD', | ||
hideExpansionControls: true, | ||
}); | ||
const USDInput = container.querySelector('input[name="foo.USD.amount"]'); |
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.
Would be nice to do the changes in moneyinput first so we could do getByLabelText here
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.
Looking good so far!
I've got a few suggestions for the API of the static methods to be more inline with how we're doing things in LocalizedTextInput
.
src/components/inputs/localized-money-input/localized-money-input.js
Outdated
Show resolved
Hide resolved
src/components/inputs/localized-money-input/localized-money-input.js
Outdated
Show resolved
Hide resolved
src/components/inputs/localized-money-input/localized-money-input.spec.js
Outdated
Show resolved
Hide resolved
src/components/inputs/localized-money-input/localized-money-input.spec.js
Outdated
Show resolved
Hide resolved
1722ab7
to
b0228ac
Compare
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.
Looks very good to me 👍 Thanks for working on it. We're almost over the finish line 🏁
The MoneyInput
now supports labels, so we can probably improve the tests by using other get-methods (e.g. getByLabelText
).
We're also missing some translations.
selectedCurrency: 'CAD', | ||
}); | ||
const event = { target: { value: '17.34' } }; | ||
const input = container.querySelector('input[name="foo.CAD.amount"]'); |
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.
Is there a way to find this input using a label or another approach than querySelector
? We should strive not to use other getters first. I believe we should be able to, now that MoneyInput
works with labels. You probably need to rebase first.
}); | ||
getByLabelText(/show all currencies/i).click(); | ||
const event = { target: { value: '12.98' } }; | ||
const USDInput = container.querySelector('input[name="foo.USD.amount"]'); |
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'd rename this to usdInput
. It's a regular variable so it should start lowercase. Otherwise the USDInput.value
access later on looks like we're reading a static property from a class. It's pretty nitpicky, but I wouldn't want this naming pattern to start spreading.
@@ -0,0 +1,115 @@ | |||
import React from 'react'; | |||
import { |
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.
can you refactor this to match our current VRT tests?
we need one .visualroute.js and one .visualspec.js 👍
|
||
const value = { | ||
EUR: '12.77', | ||
USD: '13.55', | ||
CAD: '19.82', | ||
}; | ||
|
||
screenshot('LocalizedMoneyInput', () => ( | ||
export const routePath = '/localized-money-input'; |
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.
👍
expect( | ||
container.querySelector('input[name="foo.CAD.amount"]') | ||
).toBeInTheDocument(); | ||
expect(getByLabelText('CAD')).toBeInTheDocument(); |
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 doesn't really test that it has an HTML name though?
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.
not directly, or indirectly :D
updated the test name
name: 'foo', | ||
selectedCurrency: 'CAD', | ||
onBlur, | ||
}); | ||
const input = container.querySelector('input[name="foo.CAD.amount"]'); | ||
const input = getByLabelText('CAD'); |
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.
👍
src/components/inputs/localized-money-input/localized-money-input.spec.js
Show resolved
Hide resolved
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 a lot!
I pinged @filippobocik for a review of the Visual Regression Tests baseline. @montezume This looks ready to be reviewed again. |
const initialValues = docToFormValues(doc); | ||
const renderErrors = (errors) => { | ||
Object.keys(errors.prices).reduce(currency => { | ||
const error = errors.prices[currency]?.missing && ( |
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.
Is it just the diff or is the formatting off?
errors, | ||
touched, | ||
setFieldValue, | ||
setFieldTouched, |
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.
We don't use half of these below, should we remove them given that this is a copy and paste basis?
onBlur: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
hideExpansionControls: PropTypes.bool, | ||
isDefaultExpanded: (props, propName, componentName, ...rest) => { |
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.
@dferber90 is this consistent with #389?
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 nice catch! Yeah, this needs to be changed indeed! I totally missed it :/
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.
so isDefaultExpanded
will be defaultExpandCurrencies
?
this doesn't sound like a boolean prop, or did I misunderstand the change here
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.
@dferber90 please clarify the intended prop here :)
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 believe it should be
hideCurrencyExpansionControls,
isDefaultExpanded
right?
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 clarification
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.
What we want is:
defaultExpandCurrencies // replaces isDefaultExpanded
hideCurrencyExpansionControls // replaces hideExpansionControls
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.
done
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.
There are still references to isDefaultExpanded
in the README and in a spec file 🔍
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.
sorry forgot to push :D
import Constraints from '../../constraints'; | ||
import { | ||
createLocalizedDataAttributes, | ||
getHasErrorOnRemainingLanguages, |
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.
did we decide where or not it makes sense to make these into their own functions, instead of reusing the language ones?
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.
Maybe renaming the function would be good enough?
@islam3zzat can you rebase to master and see if there's any issues now that #387 has been merged? |
hideCurrencyExpansionControls
hideCurrencyExpansionControls
defaultExpandCurrencies
…alized-money-input
defaultExpandCurrencies
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 all your hard work @islam3zzat 🎉
I merged as @islam3zzat didn't have the permissions to do so himself. Nice to have this in 🌈 |
Thanks @dferber90 |
Summary
Description