-
Notifications
You must be signed in to change notification settings - Fork 152
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: add readOnly prop #4427
fix: add readOnly prop #4427
Conversation
Storybook staging is available at https://kiwicom-orbit-sarka-input-select-mobile-readonly.surge.sh |
Size Change: +30 B (+0.01%) Total Size: 445 kB
ℹ️ View Unchanged
|
Deploying orbit with Cloudflare Pages
|
packages/orbit-components/src/InputSelect/InputSelect.ct-story.tsx
Outdated
Show resolved
Hide resolved
In general, I have added readOnly prop to In case it's Or would you suggest solving this issue in any other way? 🤔 cc @DSil |
8d08ae5
to
53cdd7c
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.
The described issue is precisely the InputSelect
being readOnly
on mobile. That is not expected, but I see it still happens here. I also don't understand why forcing it to be readOnly
in all stories. The idea is that it is readOnly
only when the readOnly
prop is actually passed to the component.
981e73b
to
22a7f61
Compare
I don't understand, the
I set the readOnly prop as a knob.
|
24540e0
to
954237b
Compare
packages/orbit-components/src/InputSelect/__tests__/index.test.tsx
Outdated
Show resolved
Hide resolved
packages/orbit-components/src/InputSelect/__tests__/index.test.tsx
Outdated
Show resolved
Hide resolved
packages/orbit-components/src/InputSelect/__tests__/index.test.tsx
Outdated
Show resolved
Hide resolved
packages/orbit-components/src/InputSelect/InputSelect.ct-story.tsx
Outdated
Show resolved
Hide resolved
a4958c2
to
4e33b40
Compare
expect(input).toHaveValue(jetLiOption.title); | ||
|
||
await user.tab(); | ||
expect(onFocus).toHaveBeenCalled(); |
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 call this assertion for every of event (fireEvent, user.tab, user.type)
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 removed tests for events "Enter" and "onKeyDown". I think they can't be triggered from the mobile view (?).
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.
Asserting the same function call repeatedly is not worth here. It will always return true if it was called at least once. We need to use toHaveBeenCalledTimes
and increment the number of times.
Actually, that is good to see that the test was not asserting correctly. Because the second call (after click) was actually not happening.
Because if we click on something that is already focused, the onFocus
call won't happen again. We need to blur it first. So we need to have input.blur()
after the first assertion.
Then, there is a technical limitation on fireEvent.click
, as it does not work for readOnly elements. Therefore, we need to use userEvent event here. Something like await user.click(input)
. That way I believe we will be able to assert the second onFocus call correctly.
Hi @DSil |
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.
Almost there, just a test issue
expect(input).toHaveValue(jetLiOption.title); | ||
|
||
await user.tab(); | ||
expect(onFocus).toHaveBeenCalled(); |
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.
Asserting the same function call repeatedly is not worth here. It will always return true if it was called at least once. We need to use toHaveBeenCalledTimes
and increment the number of times.
Actually, that is good to see that the test was not asserting correctly. Because the second call (after click) was actually not happening.
Because if we click on something that is already focused, the onFocus
call won't happen again. We need to blur it first. So we need to have input.blur()
after the first assertion.
Then, there is a technical limitation on fireEvent.click
, as it does not work for readOnly elements. Therefore, we need to use userEvent event here. Something like await user.click(input)
. That way I believe we will be able to assert the second onFocus call correctly.
|
||
// Assert that input field still includes the same value | ||
await user.type(input, "Arnold"); | ||
expect(onFocus).toHaveBeenCalled(); |
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 not correct! And it was passing precisely because this assertion was done incorrectly. If the input is readOnly, the user.type
event should have no effect. And because it has no effect, the onChange
is never called. Therefore, the onFocus
is also never called, as expected. So we have two options here:
- We either remove this interaction entirely (why would we test
user.type
on a readonly input?) - We change the assertion to assert the same amount of calls as in the assertion before, to ensure that
onFocus
was not called
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 went with 2nd option, I would like to ensure that typing in readOnly prop is not possible and the value is still the same.
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.
That is ok, but
I would like to ensure that typing in readOnly prop is not possible
This is not our responsibility in the first place. We should not be testing native behaviors 😄
4e33b40
to
c86ce46
Compare
c86ce46
to
9e6ebc6
Compare
This Pull Request meets the following criteria:
For new components:
d.ts
files and are exported inindex.d.ts
Closes https://kiwicom.atlassian.net/browse/FEPLT-2061