ngx-mask icon indicating copy to clipboard operation
ngx-mask copied to clipboard

Misleading "backspace/delete" tests

Open manuelmeister opened this issue 4 years ago • 1 comments

Description

The "Directive: Mask (Delete)" tests do not replicate real browser behavior at all. With real "Delete/Backspace" events, the browser actually deletes the characters selected / next to the cursor.

Example

For instance this test only tests if the value that is set at the beginning is formatted correctly. https://github.com/JsDaddy/ngx-mask/blob/fb6f176ce841bb78b3ec5ca4e3a3d52bce7404ac/projects/ngx-mask-lib/src/test/delete.spec.ts#L24-L39 The same would happen if the two triggerEventHandlers were omitted, because after the value "2/34/5678" is set, the input value is automatically formatted to "23/45/678". Also the cursor position is checked incorrectly. After a backspace at position 1 (between "2" and "3") the cursor should be at position 0.

Problem

With these tests, a false sense of security is created and changes that would solve the misbehavior fail.

Solution

Issues probably caused by these tests or relevant:

https://github.com/JsDaddy/ngx-mask/issues/664 https://github.com/JsDaddy/ngx-mask/issues/799 https://github.com/JsDaddy/ngx-mask/issues/844 https://github.com/JsDaddy/ngx-mask/issues/865

There are also other issues like you can't select text and delete the selected text with backspace. Instead it will only delete one character.
Screen Shot 2021-05-20 at 11 16 33 Screen Shot 2021-05-20 at 11 16 40

manuelmeister avatar May 20 '21 13:05 manuelmeister

~~Maybe these tests and mask directive changes could fix #899 as well?~~ 🙈

Nevermind, just noticed it is only for deleting characters but not when adding new ones with multiple masks.

KingDarBoja avatar May 20 '21 14:05 KingDarBoja

@manuelmeister @KingDarBoja Seems like we merged a couple request relative to this . If problem still actual please create new one issues or connect with me directly

NepipenkoIgor avatar Sep 13 '22 14:09 NepipenkoIgor