-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Mobile - Text color formatting - Adds integration tests #37530
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/format-library/src/text-color/test/__snapshots__/index.native.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Text color allows toggling the highlight color feature to selected text 1`] = ` | ||
| "<!-- wp:paragraph --> | ||
| <p><mark style=\\"background-color:rgba(0, 0, 0, 0);color:#f78da7\\" class=\\"has-inline-color has-pale-pink-color\\">Hello this is a test</mark></p> | ||
| <!-- /wp:paragraph -->" | ||
| `; | ||
|
|
||
| exports[`Text color allows toggling the highlight color feature to type new text 1`] = ` | ||
| "<!-- wp:paragraph --> | ||
| <p><mark style=\\"background-color:rgba(0, 0, 0, 0);color:#f78da7\\" class=\\"has-inline-color has-pale-pink-color\\"></mark></p> | ||
| <!-- /wp:paragraph -->" | ||
| `; | ||
|
|
||
| exports[`Text color creates a paragraph block with the text color format 1`] = ` | ||
| "<!-- wp:paragraph --> | ||
| <p>Hello <mark style=\\"background-color:rgba(0,0,0,0);color:#cf2e2e\\" class=\\"has-inline-color has-vivid-red-color\\">this is a test</mark></p> | ||
| <!-- /wp:paragraph -->" | ||
| `; |
170 changes: 170 additions & 0 deletions
170
packages/format-library/src/text-color/test/index.native.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { | ||
| getEditorHtml, | ||
| initializeEditor, | ||
| fireEvent, | ||
| waitFor, | ||
| } from 'test/helpers'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { setDefaultBlockName, unregisterBlockType } from '@wordpress/blocks'; | ||
| import { registerBlock, coreBlocks } from '@wordpress/block-library'; | ||
|
|
||
| const COLOR_PINK = '#f78da7'; | ||
| const paragraph = coreBlocks[ 'core/paragraph' ]; | ||
|
|
||
| const TEXT_WITH_COLOR = `<!-- wp:paragraph --> | ||
| <p>Hello <mark style="background-color:rgba(0,0,0,0);color:#cf2e2e" class="has-inline-color has-vivid-red-color">this is a test</mark></p> | ||
| <!-- /wp:paragraph -->`; | ||
|
|
||
| beforeAll( () => { | ||
| registerBlock( paragraph ); | ||
| setDefaultBlockName( paragraph.name ); | ||
| } ); | ||
|
|
||
| afterAll( () => { | ||
| unregisterBlockType( paragraph.name ); | ||
| } ); | ||
|
|
||
| describe( 'Text color', () => { | ||
| it( 'shows the text color formatting button in the toolbar', async () => { | ||
| const { getByA11yLabel } = await initializeEditor(); | ||
|
|
||
| // Wait for the editor placeholder | ||
| const paragraphPlaceholder = await waitFor( () => | ||
| getByA11yLabel( 'Add paragraph block' ) | ||
| ); | ||
| expect( paragraphPlaceholder ).toBeDefined(); | ||
| fireEvent.press( paragraphPlaceholder ); | ||
|
|
||
| // Wait for the block to be created | ||
| const paragraphBlock = await waitFor( () => | ||
| getByA11yLabel( /Paragraph Block\. Row 1/ ) | ||
| ); | ||
| expect( paragraphBlock ).toBeDefined(); | ||
|
|
||
| // Look for the highlight text color button | ||
| const textColorButton = await waitFor( () => | ||
| getByA11yLabel( 'Text color' ) | ||
| ); | ||
| expect( textColorButton ).toBeDefined(); | ||
| } ); | ||
|
|
||
| it( 'allows toggling the highlight color feature to type new text', async () => { | ||
| const { | ||
| getByA11yLabel, | ||
| getByTestId, | ||
| getByA11yHint, | ||
| } = await initializeEditor(); | ||
|
|
||
| // Wait for the editor placeholder | ||
| const paragraphPlaceholder = await waitFor( () => | ||
| getByA11yLabel( 'Add paragraph block' ) | ||
| ); | ||
| expect( paragraphPlaceholder ).toBeDefined(); | ||
| fireEvent.press( paragraphPlaceholder ); | ||
|
|
||
| // Wait for the block to be created | ||
| const paragraphBlock = await waitFor( () => | ||
| getByA11yLabel( /Paragraph Block\. Row 1/ ) | ||
| ); | ||
| expect( paragraphBlock ).toBeDefined(); | ||
|
|
||
| // Look for the highlight text color button | ||
| const textColorButton = await waitFor( () => | ||
| getByA11yLabel( 'Text color' ) | ||
| ); | ||
| expect( textColorButton ).toBeDefined(); | ||
| fireEvent.press( textColorButton ); | ||
|
|
||
| // Wait for Inline color modal to be visible | ||
| const inlineTextColorModal = getByTestId( 'inline-text-color' ); | ||
| await waitFor( () => inlineTextColorModal.props.isVisible ); | ||
|
|
||
| // Look for the pink color button | ||
| const pinkColorButton = await waitFor( () => | ||
| getByA11yHint( COLOR_PINK ) | ||
| ); | ||
| expect( pinkColorButton ).toBeDefined(); | ||
| fireEvent.press( pinkColorButton ); | ||
|
|
||
| // Dismiss the inline color modal | ||
| fireEvent( inlineTextColorModal, 'backdropPress' ); | ||
|
geriux marked this conversation as resolved.
Outdated
|
||
|
|
||
| expect( getEditorHtml() ).toMatchSnapshot(); | ||
| } ); | ||
|
|
||
| it( 'allows toggling the highlight color feature to selected text', async () => { | ||
| const { | ||
| getByA11yLabel, | ||
| getByTestId, | ||
| getByPlaceholderText, | ||
| getByA11yHint, | ||
| } = await initializeEditor(); | ||
| const text = 'Hello this is a test'; | ||
|
|
||
| // Wait for the editor placeholder | ||
| const paragraphPlaceholder = await waitFor( () => | ||
| getByA11yLabel( 'Add paragraph block' ) | ||
| ); | ||
| expect( paragraphPlaceholder ).toBeDefined(); | ||
| fireEvent.press( paragraphPlaceholder ); | ||
|
|
||
| // Wait for the block to be created | ||
| const paragraphBlock = await waitFor( () => | ||
| getByA11yLabel( /Paragraph Block\. Row 1/ ) | ||
| ); | ||
| expect( paragraphBlock ).toBeDefined(); | ||
|
|
||
| // Update TextInput value | ||
| const paragraphText = getByPlaceholderText( 'Start writing…' ); | ||
| fireEvent( paragraphText, 'onSelectionChange', 0, text.length, text, { | ||
| nativeEvent: { | ||
| eventCount: 1, | ||
| target: undefined, | ||
| text, | ||
| }, | ||
| } ); | ||
|
|
||
| // Look for the highlight text color button | ||
| const textColorButton = await waitFor( () => | ||
| getByA11yLabel( 'Text color' ) | ||
| ); | ||
| expect( textColorButton ).toBeDefined(); | ||
| fireEvent.press( textColorButton ); | ||
|
|
||
| // Wait for Inline color modal to be visible | ||
| const inlineTextColorModal = getByTestId( 'inline-text-color' ); | ||
| await waitFor( () => inlineTextColorModal.props.isVisible ); | ||
|
|
||
| // Look for the pink color button | ||
| const pinkColorButton = await waitFor( () => | ||
| getByA11yHint( COLOR_PINK ) | ||
| ); | ||
| expect( pinkColorButton ).toBeDefined(); | ||
| fireEvent.press( pinkColorButton ); | ||
|
|
||
| // Dismiss the inline color modal | ||
| fireEvent( inlineTextColorModal, 'backdropPress' ); | ||
|
geriux marked this conversation as resolved.
Outdated
|
||
|
|
||
| expect( getEditorHtml() ).toMatchSnapshot(); | ||
| } ); | ||
|
|
||
| it( 'creates a paragraph block with the text color format', async () => { | ||
| const { getByA11yLabel } = await initializeEditor( { | ||
| initialHtml: TEXT_WITH_COLOR, | ||
| } ); | ||
|
|
||
| // Wait for the block to be created | ||
| const paragraphBlock = await waitFor( () => | ||
| getByA11yLabel( /Paragraph Block\. Row 1/ ) | ||
| ); | ||
| expect( paragraphBlock ).toBeDefined(); | ||
|
|
||
| expect( getEditorHtml() ).toMatchSnapshot(); | ||
| } ); | ||
| } ); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.