-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[RNMobile] Spacer block: Fix import of MIN_SPACER_SIZE
constant
#40053
Conversation
Size Change: 0 B Total Size: 1.22 MB ℹ️ View Unchanged
|
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.
LGTM! I tested this on both iOS and Android 🚀
Thanks for adding tests! I think we can now remove some of them here. And also from the test suites.
|
||
// Open block settings | ||
fireEvent.press( getByA11yLabel( 'Open Settings' ) ); | ||
await waitFor( |
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 a blocker and something to consider for a follow-up PR, could we introduce a helper that would make this wait be used like:
await waitForTestId( 'block-settings-modal' );
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.
Sure, it would be great if we had more helpers to reduce code in tests and make it easier to read. Actually, some time ago I created this PR #38619 where I added several helpers, however, I haven't spared enough time to push it. For this case, we could use the helper openBlockSettings
which will wait for the block settings modal to be opened.
Regarding the helper you mentioned (i.e. waitForTestId
), I'm not sure if it would fit the requirement here as we're not only waiting for a component with a test Id but also for the modal to be visible. The way I see the implementation of that helper would be:
const waitForTestId = ( testId ) => {
return waitFor( () => getByTestId( testId) );
};
However, in this case, we're also looking for the prop isVisible
to be true
:
getByTestId( 'block-settings-modal' ).props.isVisible
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 for not making it clear before, I think the helper should include the truth-check for isVisible
. Do you perhaps mean that sometimes we want to check it and others not?
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 for not making it clear before, I think the helper should include the truth-check for isVisible.
Oh ok, that makes sense, although not every component has the isVisible
prop. I think that in this case, the helper would be specific to modals or another type of component that its visibility is determined by a prop (although can't think of another component 🤔 ). Hence, we could name it differently like waitForModal
or waitForModalByTestId
instead, wdyt?
Do you perhaps mean that sometimes we want to check it and others not?
Yep, in some cases, usually where state updates occur, we need to wait for a component to be rendered via the waitFor
. That's why I thought that the helper waitForTestId
would behave as I outlined in this comment.
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.
Hence, we could name it differently like waitForModal or waitForModalByTestId instead, wdyt?
Sounds good to me. In the end, my main goal with the comment thread here is to see if we can reduce the verbosity of the code, so anything towards that end I'm 👍
Yep, I think we could remove the ones that don't require checking visual changes. Besides, I noticed that they're a bit outdated as we no longer have a slider to modify the |
…0053) * Fix import of MIN_SPACER_SIZE constant * Add tests for Spacer block
@@ -14,7 +14,7 @@ import { __ } from '@wordpress/i18n'; | |||
/** | |||
* Internal dependencies | |||
*/ | |||
import { MIN_SPACER_SIZE } from './edit'; | |||
import { MIN_SPACER_SIZE } from './edit.js'; |
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.
Hmm, can we rethink the implementation here? I think it's highly unintuitive to use the extension-specific form here to load the constant from the web variant of the file and I think can easily lead to hard to find bugs.
Instead, can we define the constant in a constants.js
file? that file won't be forked unless it needs to and define the value for both the web and native mobile to use. WDYT @fluiddot ?
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.
Hmm, can we rethink the implementation here? I think it's highly unintuitive to use the extension-specific form here to load the constant from the web variant of the file and I think can easily lead to hard to find bugs.
Instead, can we define the constant in a
constants.js
file? that file won't be forked unless it needs to and define the value for both the web and native mobile to use. WDYT @fluiddot ?
Good point and I totally agree, I'll open a new PR with that change 👍 .
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.
FYI in this PR we'll add the constants file.
What?
Fix import of
MIN_SPACER_SIZE
constant in Spacer block.Why?
After the changes introduced in #39577, the
MIN_SPACER_SIZE
constant is now used as themin
prop passed to theUnitControl
component (reference). However, the current import statement (reference) is pointing to the native version of theedit
file instead of the web version, where the constant is defined (reference).This implies that the value used in the
min
prop isundefined
, which leads to a crash in the app when theUnitControl
component is focused.How?
Use
./edit.js
as the import path instead of./edit
to assure we load the constant from the rightedit
file.Testing Instructions
Screenshots or screencast
N/A