Skip to content
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

Error when fillIn/ typeIn attempt to enter a value longer than maxlength #747

Merged
merged 6 commits into from
May 5, 2020

Conversation

jaydgruber
Copy link
Contributor

@jaydgruber jaydgruber commented Dec 3, 2019

What

  • adds failing test cases where fillIn and typeIn ignore the maxlength attribute of an input
  • adds a util function isMaxLengthConstrained
  • if isMaxLengthConstrained = true, will
  • fill-in helper
    • replaces element.value w/ the new value, truncated to maxlength if needed
  • for type-in helper:
    • on character entries that would exceed the maxlength, fires ['keydown', 'keypress', 'keyup'] events, but no input event, and element.value does not change
  • adds unit test cases for same

Why

@rwjblue
Copy link
Member

rwjblue commented Dec 4, 2019

Thanks for working on failing test cases here! If you have the time, you can probably implement a check that truncates (or whatever the "right" behavior is) here in these spots:

element.value = element.value + character;

@rwjblue rwjblue added the bug label Dec 4, 2019
@jaydgruber
Copy link
Contributor Author

I think fillIn is pretty straightforward - just truncate at maxlength, as it replaces any previous value in the control.

For typeIn I'm less sure. I think typeIn is additive, so if I did

await typeIn('input', 'a');
await typeIn('input', 'b');

I would end up w/ 'ab'. So I guess typeIn should stop modifying element.value when the maxlength of the combined (previous values + new values).length === maxlength.
But I think it should still fire all the key events? Like if a user tried to type past the maxlength of a field, they still hit the keys, just no more values get added.

@rwjblue
Copy link
Member

rwjblue commented Dec 4, 2019

But I think it should still fire all the key events? Like if a user tried to type past the maxlength of a field, they still hit the keys, just no more values get added.

Yep, that is what I think also but we should confirm that is the actual browser.

@jaydgruber
Copy link
Contributor Author

I went down a bit of a rabbit hole reading docs around https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation
[max, maxlength, min, minlength, pattern, size, step] all have validation that prevents form submission, but looks like only maxlength prevents users from entering values.
I tried to figure out a way to check the Constraint Validation API's https://webplatform.github.io/docs/dom/ValidityState/tooLong/, but was getting false negatives. Not sure what sort of event (dirty flag maybe?) needs to be fired to get checkValidity to report correctly when the input was not user-entered.
Anyways, abandoned that approach in favor of simpler one-off

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes were needed to typeIn?

addon-test-support/@ember/test-helpers/dom/fill-in.ts Outdated Show resolved Hide resolved
addon-test-support/@ember/test-helpers/dom/fill-in.ts Outdated Show resolved Hide resolved
@jaydgruber jaydgruber changed the title Adds failing test cases for fillIn and typeIn do not respect maxlength attribute WIP: Adds failing test cases for fillIn and typeIn do not respect maxlength attribute Dec 6, 2019
@jaydgruber
Copy link
Contributor Author

Still working on typeIn

@jaydgruber jaydgruber changed the title WIP: Adds failing test cases for fillIn and typeIn do not respect maxlength attribute [Bugfix] makes fillIn and typeIn respect maxlength attribute Dec 17, 2019
@jaydgruber jaydgruber changed the title [Bugfix] makes fillIn and typeIn respect maxlength attribute WIP: [Bugfix] makes fillIn and typeIn respect maxlength attribute Dec 17, 2019
@jaydgruber jaydgruber changed the title WIP: [Bugfix] makes fillIn and typeIn respect maxlength attribute [Bugfix] makes fillIn and typeIn respect maxlength attribute Dec 17, 2019
@btecu
Copy link

btecu commented Feb 26, 2020

@jaydgruber what's the status on this?

@jaydgruber
Copy link
Contributor Author

oh I guess I could have pinged someone for re-review. this one should be ready to go, pending the one above question about do I need to do more to make it 'TypeScript-y'

@rwjblue
Copy link
Member

rwjblue commented Apr 20, 2020

@ro0gr - Would you mind reviewing? This touches a bunch of the same general areas as #741 / #779 / #778 so it will need to land after those.

@ro0gr
Copy link
Contributor

ro0gr commented Apr 20, 2020

Seems like input event stops being triggered once we reach the maxlength constraint. I've checked it in https://codepen.io/ro0gr/pen/YzyGvrZ?editors=1010

As far as I can see, in this PR, we try to trim the input and keep emitting events. If my codepen test is correct, I think we should not emit any events. Maybe we should even throw, to make un-intended fillIn more clear to the test helper user. Some context with related discussion in the thread #778 (comment)

@jaydgruber jaydgruber changed the title [Bugfix] makes fillIn and typeIn respect maxlength attribute WIP: [Bugfix] makes fillIn and typeIn respect maxlength attribute Apr 20, 2020
@jaydgruber
Copy link
Contributor Author

Yeah, I think throw similarly makes sense here

@ro0gr
Copy link
Contributor

ro0gr commented Apr 21, 2020

@jaydgruber I just wanna check if you are going to keep working on this? in case you are busy with something else, I can take it over. Otherwise it'd be glad to provide any assistance!

@rwjblue
Copy link
Member

rwjblue commented Apr 21, 2020

OK #741, #779, and #778 have all landed. This is ready for a rebase, and the tweaks that @ro0gr mentioned above (thanks @ro0gr for reviewing!).

@jaydgruber
Copy link
Contributor Author

@ro0gr I won't be able to get to it until probably Friday. I've got no objections if you want to pick it up. Thanks

@ro0gr
Copy link
Contributor

ro0gr commented Apr 21, 2020

@jaydgruber Great! sounds like you are in the game :) Take your time.

@jaydgruber jaydgruber marked this pull request as draft April 25, 2020 00:26
@jaydgruber jaydgruber marked this pull request as ready for review April 25, 2020 02:22
@jaydgruber jaydgruber changed the title WIP: [Bugfix] makes fillIn and typeIn respect maxlength attribute [Bugfix] makes fillIn and typeIn respect maxlength attribute Apr 25, 2020
@jaydgruber
Copy link
Contributor Author

@ro0gr this should be ready for another look

Copy link
Contributor

@ro0gr ro0gr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Events test for IE seems to be broken though.

await assert.rejects(
typeIn(element, tooLongString).finally(() => {
// should throw before the second input event
assert.verifySteps(expectedEvents.slice(0, 8));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like for isIE11 it would expect to throw before the third keypress, that doesn't seem correct.

@rwjblue do we have IE tests broken?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, it is possible, we don't have IE11 under CI test at the moment. We should look into hooking that up... 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I corrected the assertion here, but I don't have an IE launcher for testem locally, so not sure the best way to confirm

@jaydgruber jaydgruber changed the title [Bugfix] makes fillIn and typeIn respect maxlength attribute WIP: [Bugfix] makes fillIn and typeIn respect maxlength attribute Apr 29, 2020
@jaydgruber jaydgruber changed the title WIP: [Bugfix] makes fillIn and typeIn respect maxlength attribute [Bugfix] makes fillIn and typeIn respect maxlength attribute May 4, 2020
Copy link
Contributor

@ro0gr ro0gr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@rwjblue rwjblue changed the title [Bugfix] makes fillIn and typeIn respect maxlength attribute Error when fillIn/ typeIn attempt to enter a value longer than maxlength May 5, 2020
@rwjblue
Copy link
Member

rwjblue commented May 5, 2020

Awesome, thank you!

@rwjblue rwjblue merged commit 1881f3e into emberjs:master May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants