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

Embed block integration tests part 2 #35533

Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ae77e2e
added test for Embed block caption.
jd-alexander Oct 12, 2021
d7446d1
Merge remote-tracking branch 'origin/rnmobile/add/embed-block-integra…
jd-alexander Oct 14, 2021
afc1ddb
WIP
jd-alexander Oct 14, 2021
67ae243
fixed unneeded diff change.
jd-alexander Oct 14, 2021
f03d25d
WIP block settings
jd-alexander Oct 14, 2021
eab90f9
Merge remote-tracking branch 'origin/rnmobile/add/embed-block-integra…
jd-alexander Oct 15, 2021
e9f5c8b
Mocked RCTAztecView to utilize an underlying TextInput.
jd-alexander Oct 15, 2021
4b9d41f
Fixed Embed block caption test issues.
jd-alexander Oct 15, 2021
5000152
Created test - toggle resize for smaller devices media settings
jd-alexander Oct 15, 2021
0f4d623
Added cannot embed test.
jd-alexander Oct 15, 2021
f03c6ad
Removed unneeded test id.
jd-alexander Oct 15, 2021
9ee25d0
Merge branch 'rnmobile/add/embed-block-integration-tests' into rnmobi…
fluiddot Oct 19, 2021
b75b4e9
Merge branch 'rnmobile/add/embed-block-integration-tests' into rnmobi…
jd-alexander Oct 27, 2021
9b4287d
WIP insert embed from slash inserter.
jd-alexander Oct 27, 2021
b675261
Mock fetch request in cannot embed test case
fluiddot Nov 2, 2021
60e8cab
Trigger onSelectionChange event instead of onChange
fluiddot Nov 2, 2021
3b7faa9
Query slash inserter item by text
fluiddot Nov 2, 2021
9b29c49
Add expected HTML to slash inserter test case
fluiddot Nov 2, 2021
95a8a23
Mock autocomplete component styles
fluiddot Nov 2, 2021
1d3bce0
Set paragraph as default block
fluiddot Nov 2, 2021
afffdc1
Add empty paragraph HTML constant
fluiddot Nov 2, 2021
8d01d96
Add test suite for insert via slash inserter case
fluiddot Nov 2, 2021
231d832
Update toggle responsive test case
fluiddot Nov 2, 2021
3b1b260
Merge branch 'rnmobile/add/embed-block-integration-tests' into rnmobi…
fluiddot Nov 2, 2021
651c80e
Fix request mock for theme endpoint
fluiddot Nov 2, 2021
8e932aa
Add slash inserter cases for most used providers
fluiddot Nov 2, 2021
b56dc46
Expect for block settings button instead edit URL button
fluiddot Nov 2, 2021
520680a
Use snapshot testing instead of checking HTML
fluiddot Nov 2, 2021
70475b7
Add block settings test suite
fluiddot Nov 2, 2021
a13c5fd
Add embed test snapshots
fluiddot Nov 2, 2021
902ca9b
Use snapshot in insert generic embed block test
fluiddot Nov 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/block-library/src/embed/test/index.native.js
Expand Up @@ -816,4 +816,36 @@ describe( 'Embed block', () => {

expect( cannotEmbedText ).toBeDefined();
} );

it( 'insert embed from slash inserter', async () => {
const embedBlockSlashInserter = '/Embed';
const { getByPlaceholderText, getByA11yLabel } = await initializeEditor(
{
initialHtml:
'<!-- wp:paragraph --><p></p><!-- /wp:paragraph -->',
}
);

const paragraphText = getByPlaceholderText( 'Start writing…' );
fireEvent( paragraphText, 'focus' );
fireEvent( paragraphText, 'onChange', {
nativeEvent: {
eventCount: 1,
target: undefined,
text: embedBlockSlashInserter,
},
} );

fireEvent.press(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is that the Slash inserter should be visible once the text that has the / followed by Embed is entered. Therefore, we should be able to press the Embed block button within the Autocomplete UI.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a great idea, I'm wondering if we could query by the Embed text instead of the a11y label, as the items in the slash inserter display a text label, wdyt?

Screenshot 2021-11-02 at 14 09 15

Copy link
Contributor

Choose a reason for hiding this comment

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

I applied this suggestion in this commit.

await waitFor( () => getByA11yLabel( 'Embed block' ) )
);

const block = await waitFor( () =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the test is failing at this point. It seems the AutocompleteUI for the slash inserter is not being rendered based on the events being set to the paragraph block. This will be investigated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From an investigation standpoint, I realized that the getAutoCompleterUI located within the native implementation is not being called when the the onChange event is sent via fireEvent.

fireEvent( paragraphText, 'onChange', {

I am wondering if a prop is missing from the mocked RCTAztecView that needs to be implemented, so that it can be rendered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once the aforementioned issue is resolved, I am going to be replicating the test setup here https://github.com/WordPress/gutenberg/blob/rnmobile/add/embed-block-integration-tests-2/packages/block-library/src/embed/test/index.native.js#L193 so that all the providers that are shown within the AutocompleteUI can be tested and verified.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if a prop is missing from the mocked RCTAztecView that needs to be implemented, so that it can be rendered.

Interesting, I'll investigate this further in case we need to add extra functionality in the mock.

Copy link
Contributor

Choose a reason for hiding this comment

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

After digging into how the autocomplete works, I found out that we had to trigger a different event in the RichText component as well as set the paragraph block as the default block, which is required by the autocomplete logic (I'll add more details about this topic in the file changes).

Copy link
Contributor

Choose a reason for hiding this comment

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

getByA11yLabel( /Embed Block\. Row 1/ )
);

const blockName = within( block ).getByText( 'Embed' );

expect( blockName ).toBeDefined();
} );
} );