diff --git a/packages/format-library/src/text-color/inline.native.js b/packages/format-library/src/text-color/inline.native.js index efbf6db545e5dd..b81f13ffd9207f 100644 --- a/packages/format-library/src/text-color/inline.native.js +++ b/packages/format-library/src/text-color/inline.native.js @@ -148,6 +148,7 @@ export default function InlineColorUI( { name, value, onChange, onClose } ) { contentStyle={ { paddingLeft: 0, paddingRight: 0 } } hasNavigation leftButton={ null } + testID="inline-text-color-modal" > diff --git a/packages/format-library/src/text-color/test/__snapshots__/index.native.js.snap b/packages/format-library/src/text-color/test/__snapshots__/index.native.js.snap new file mode 100644 index 00000000000000..f2abb6be0d0118 --- /dev/null +++ b/packages/format-library/src/text-color/test/__snapshots__/index.native.js.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Text color allows toggling the highlight color feature to selected text 1`] = ` +" +

Hello this is a test

+" +`; + +exports[`Text color allows toggling the highlight color feature to type new text 1`] = ` +" +

+" +`; + +exports[`Text color creates a paragraph block with the text color format 1`] = ` +" +

Hello this is a test

+" +`; diff --git a/packages/format-library/src/text-color/test/index.native.js b/packages/format-library/src/text-color/test/index.native.js new file mode 100644 index 00000000000000..742fb52822235e --- /dev/null +++ b/packages/format-library/src/text-color/test/index.native.js @@ -0,0 +1,164 @@ +/** + * 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 = ` +

Hello this is a test

+`; + +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-modal' ); + await waitFor( () => inlineTextColorModal.props.isVisible ); + + // Look for the pink color button + const pinkColorButton = await waitFor( () => + getByA11yHint( COLOR_PINK ) + ); + expect( pinkColorButton ).toBeDefined(); + fireEvent.press( pinkColorButton ); + + 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-modal' ); + await waitFor( () => inlineTextColorModal.props.isVisible ); + + // Look for the pink color button + const pinkColorButton = await waitFor( () => + getByA11yHint( COLOR_PINK ) + ); + expect( pinkColorButton ).toBeDefined(); + fireEvent.press( pinkColorButton ); + + 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(); + } ); +} );