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
Autocomplete: duplicate list within iframe for non visual users #47907
Changes from all commits
ea2eed7
c975302
2c330f5
fc19831
d1f628c
d94b7b7
9550337
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,12 +57,14 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
} ) | ||
) | ||
); | ||
await requestUtils.activateTheme( 'emptytheme' ); | ||
await requestUtils.activatePlugin( 'gutenberg-test-autocompleter' ); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllUsers(); | ||
await requestUtils.deactivatePlugin( 'gutenberg-test-autocompleter' ); | ||
await requestUtils.activateTheme( 'twentytwentyone' ); | ||
} ); | ||
|
||
test.beforeEach( async ( { admin } ) => { | ||
|
@@ -98,11 +100,28 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
<!-- /wp:paragraph -->`; | ||
} | ||
|
||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
await page.keyboard.type( testData.triggerString ); | ||
await expect( | ||
page.locator( `role=option[name="${ testData.optionText }"i]` ) | ||
).toBeVisible(); | ||
const ariaOwns = await editor.canvas.evaluate( () => { | ||
return document.activeElement.getAttribute( 'aria-owns' ); | ||
} ); | ||
const ariaActiveDescendant = await editor.canvas.evaluate( () => { | ||
return document.activeElement.getAttribute( | ||
'aria-activedescendant' | ||
); | ||
} ); | ||
// Ensure `aria-owns` is part of the same document and ensure the | ||
// selected option is equal to the active descendant. | ||
await expect( | ||
await editor.canvas | ||
.locator( `#${ ariaOwns } [aria-selected="true"]` ) | ||
.getAttribute( 'id' ) | ||
).toBe( ariaActiveDescendant ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( '.' ); | ||
|
||
|
@@ -131,7 +150,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
<!-- /wp:paragraph -->`; | ||
} | ||
|
||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
await page.keyboard.type( 'Stuck in the middle with you.' ); | ||
await pageUtils.pressKeyTimes( 'ArrowLeft', 'you.'.length ); | ||
await page.keyboard.type( testData.triggerString ); | ||
|
@@ -169,7 +190,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
<!-- /wp:paragraph -->`; | ||
} | ||
|
||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
await page.keyboard.type( testData.firstTriggerString ); | ||
await expect( | ||
page.locator( | ||
|
@@ -209,7 +232,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
<!-- /wp:paragraph -->`; | ||
} | ||
|
||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
await page.keyboard.type( testData.triggerString ); | ||
await expect( | ||
page.locator( `role=option[name="${ testData.optionText }"i]` ) | ||
|
@@ -247,7 +272,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
<!-- /wp:paragraph -->`; | ||
} | ||
|
||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
await page.keyboard.type( testData.triggerString ); | ||
await expect( | ||
page.locator( `role=option[name="${ testData.optionText }"i]` ) | ||
|
@@ -282,7 +309,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
<!-- /wp:paragraph -->`; | ||
} | ||
|
||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
await page.keyboard.type( testData.triggerString ); | ||
await expect( | ||
page.locator( `role=option[name="${ testData.optionText }"i]` ) | ||
|
@@ -301,7 +330,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
page, | ||
editor, | ||
} ) => { | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
// The 'Grapes' option is disabled in our test plugin, so it should not insert the grapes emoji | ||
await page.keyboard.type( 'Sorry, we are all out of ~g' ); | ||
await expect( | ||
|
@@ -367,7 +398,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
<!-- /wp:paragraph -->`; | ||
} | ||
|
||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( | ||
'role=button[name="Add default block"i]' | ||
); | ||
|
||
for ( let i = 0; i < 4; i++ ) { | ||
await page.keyboard.type( testData.triggerString ); | ||
|
@@ -393,7 +426,7 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
page, | ||
editor, | ||
} ) => { | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '@fr' ); | ||
await expect( | ||
page.locator( 'role=option', { hasText: 'Frodo Baggins' } ) | ||
|
@@ -412,8 +445,9 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
|
||
test( 'should hide UI when selection changes (by keyboard)', async ( { | ||
page, | ||
editor, | ||
} ) => { | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await editor.canvas.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '@fr' ); | ||
await expect( | ||
page.locator( 'role=option', { hasText: 'Frodo Baggins' } ) | ||
|
@@ -426,13 +460,20 @@ test.describe( 'Autocomplete (@firefox, @webkit)', () => { | |
|
||
test( 'should hide UI when selection changes (by mouse)', async ( { | ||
page, | ||
editor, | ||
pageUtils, | ||
} ) => { | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '@fr' ); | ||
await editor.canvas.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '@' ); | ||
await pageUtils.pressKeyWithModifier( 'primary', 'b' ); | ||
await page.keyboard.type( 'f' ); | ||
await pageUtils.pressKeyWithModifier( 'primary', 'b' ); | ||
await page.keyboard.type( 'r' ); | ||
await expect( | ||
page.locator( 'role=option', { hasText: 'Frodo Baggins' } ) | ||
).toBeVisible(); | ||
await page.click( '[data-type="core/paragraph"]' ); | ||
// Use the strong tag to move the selection by mouse within the mention. | ||
await editor.canvas.click( '[data-type="core/paragraph"] strong' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was actually passing for the wrong reason. The autocomplete component has an on click outside handler that hides the popover, which doesn't work in the iframe when clicking in a block. In the test we should perform a click that changes the selection but still within the mention. |
||
await expect( | ||
page.locator( 'role=option', { hasText: 'Frodo Baggins' } ) | ||
).not.toBeVisible(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a related failure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are now run in the iframe, so yes. |
||
|
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 probably a better fit in a unit test than an e2e test. Could it be done in a unit test environment giving the current architecture?
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.
Why should it be a unit test? We're checking if it's correct for an iframe because we need to duplicate the markup inside the iframe.
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.
It's just my preference since unit tests are faster and more reliable for this kind of task. I don't think we need anything from a real browser to perform this test. That said, it can still be tested in e2e tests if you prefer it though 🙂 . Feel free to ignore!
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.
Here's some more context to why
Autocomplete
has mostly e2e tests instead of unit tests :)#42674 (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.
Thanks for the context! I would probably still prefer an integration test (rendering both
AutoComplete
andRichText
without mocking), but nvm if it's too much trouble to set up.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.
Agreed — we just went for what we thought was the best trade-off between required efforts and results.
Out of curiosity, where would those tests live in the repo?
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.
@glendaviesnz had some ideas about adding more integration tests to the repo. I haven't put many thoughts into it yet 😅 , so I'll just shamelessly defer this question to him 😆 .
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.
It is still on my to-do list to look at ways that we can more easily provide for
integration
level testing for blocks, etc. rather than having to rely on e2e, eg. some way of testing the interaction between block inspector/toolbar/edit components without having to fire up a full WP instance. I am hoping to take more of a look at this once 6.2 is sorted.