Skip to content

Commit

Permalink
fix: skip click on enter
Browse files Browse the repository at this point in the history
- update login fixture to match previous fixture (starting at index page)
  • Loading branch information
jperl committed Jul 9, 2020
1 parent 8a83b0e commit 1121d33
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 336 deletions.
2 changes: 1 addition & 1 deletion src/build-workflow/buildClickSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const filterClickEvents = (events: ElementEvent[]): ElementEvent[] => {
const previousEvent = events[i - 1];
if (
previousEvent &&
['keydown', 'keyup'].includes(previousEvent.name) &&
['change', 'keydown', 'keyup'].includes(previousEvent.name) &&
event.time - previousEvent.time < 50
) {
// skip system-initiated clicks triggered by a key press
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`buildClickSteps builds one click per group of mousedown/click events 1`
Array [
0,
2,
43,
41,
]
`;

Expand Down
101 changes: 17 additions & 84 deletions test/build-workflow/__snapshots__/buildSteps.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,22 @@ Array [
"isTrusted": true,
"name": "mousedown",
"page": 0,
"selector": "p",
"selector": "text=Log in",
"target": Object {
"attrs": Object {},
"attrs": Object {
"href": "/login",
},
"children": Array [
Object {
"content": "To log in, use ",
"type": "text",
},
Object {
"attrs": Object {},
"children": Array [
Object {
"content": "tomsmith",
"type": "text",
},
],
"name": "i",
"type": "tag",
"voidElement": false,
},
Object {
"content": " as the username, and ",
"type": "text",
},
Object {
"attrs": Object {},
"children": Array [
Object {
"content": "SuperSecretPassword!",
"type": "text",
},
],
"name": "i",
"type": "tag",
"voidElement": false,
},
Object {
"content": " as the password.",
"content": "Log in",
"type": "text",
},
],
"name": "p",
"name": "a",
"type": "tag",
"voidElement": false,
},
"time": 1594315658170,
"time": 1594320817272,
},
"index": 0,
},
Expand All @@ -78,14 +48,14 @@ Array [
"type": "tag",
"voidElement": true,
},
"time": 1594315658987,
"time": 1594320835058,
},
"index": 1,
},
Object {
"action": "fill",
"event": Object {
"index": 25,
"index": 26,
"isTrusted": true,
"name": "input",
"page": 0,
Expand All @@ -102,7 +72,7 @@ Array [
"type": "tag",
"voidElement": true,
},
"time": 1594315661241,
"time": 1594320836394,
"value": "tomsmith",
},
"index": 2,
Expand All @@ -128,7 +98,7 @@ Array [
"type": "tag",
"voidElement": true,
},
"time": 1594315661554,
"time": 1594320836752,
"value": "Tab",
},
"index": 3,
Expand All @@ -154,7 +124,7 @@ Array [
"type": "tag",
"voidElement": true,
},
"time": 1594315662066,
"time": 1594320837432,
"value": "SuperSecretPassword!",
},
"index": 4,
Expand All @@ -180,53 +150,16 @@ Array [
"type": "tag",
"voidElement": true,
},
"time": 1594315663331,
"value": "Tab",
},
"index": 5,
"value": "Tab",
},
Object {
"action": "press",
"event": Object {
"index": 40,
"isTrusted": true,
"name": "keydown",
"page": 0,
"selector": "button",
"target": Object {
"attrs": Object {
"style": "cursor: pointer;",
"type": "submit",
},
"children": Array [
Object {
"attrs": Object {},
"children": Array [
Object {
"content": "Log in",
"type": "text",
},
],
"name": "p",
"type": "tag",
"voidElement": false,
},
],
"name": "button",
"type": "tag",
"voidElement": false,
},
"time": 1594315663737,
"time": 1594320838011,
"value": "Enter",
},
"index": 6,
"index": 5,
"value": "Enter",
},
Object {
"action": "click",
"event": Object {
"index": 43,
"index": 41,
"isTrusted": true,
"name": "mousedown",
"page": 0,
Expand All @@ -251,9 +184,9 @@ Array [
"type": "tag",
"voidElement": false,
},
"time": 1594315665876,
"time": 1594320839676,
},
"index": 7,
"index": 6,
},
]
`;
5 changes: 3 additions & 2 deletions test/build-workflow/buildClickSteps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('buildClickSteps', () => {

it('builds one click per group of mousedown/click events', () => {
const steps = buildClickSteps(loginEvents);

expect(
steps.map((step) => loginEvents.indexOf(step.event)),
).toMatchSnapshot();
Expand All @@ -23,8 +24,8 @@ describe('buildClickSteps', () => {
it('skips click triggered by Enter', () => {
const steps = buildClickSteps(loginEvents);

// check there is not a click on the password
expect(steps.length).toEqual(3);
// click on login link
expect(steps[0].event.target.attrs.href).toEqual('/login');

// click on initial input
expect(steps[1].event.selector).toEqual('#username');
Expand Down
7 changes: 3 additions & 4 deletions test/create-code/__snapshots__/CodeFileUpdater.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

exports[`CodeFileUpdater update saves code with new steps 1`] = `
" someCode();
await page.click(\\"p\\");
await page.click(\\"text=Log in\\");
await page.click(\\"#username\\");
// 🐺 create code here
otherCode();"
`;

exports[`CodeFileUpdater update saves code with new steps 2`] = `
" someCode();
await page.click(\\"p\\");
await page.click(\\"text=Log in\\");
await page.click(\\"#username\\");
await page.fill(\\"#username\\", \\"tomsmith\\");
await page.press(\\"#username\\", \\"Tab\\");
await page.fill(\\"#password\\", \\"SuperSecretPassword!\\");
await page.press(\\"#password\\", \\"Tab\\");
await page.press(\\"button\\", \\"Enter\\");
await page.press(\\"#password\\", \\"Enter\\");
await page.click(\\"text=Log out\\");
// 🐺 create code here
otherCode();"
Expand Down
2 changes: 1 addition & 1 deletion test/create-code/__snapshots__/CodeReconciler.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CodeReconciler.reconcile inserts new expressions 1`] = `
"await page.click(\\"p\\");
"await page.click(\\"text=Log in\\");
// 🐺 create code here"
`;

Expand Down

0 comments on commit 1121d33

Please sign in to comment.