From 9d5bb00d37fef33bd684fd7873133e0f6472fe6b Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Fri, 9 Jul 2021 22:36:28 -0400 Subject: [PATCH 1/3] Add unsupported block title translation test --- .../missing/test/edit-integration.native.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packages/block-library/src/missing/test/edit-integration.native.js diff --git a/packages/block-library/src/missing/test/edit-integration.native.js b/packages/block-library/src/missing/test/edit-integration.native.js new file mode 100644 index 0000000000000..4ffa2f8bf0f39 --- /dev/null +++ b/packages/block-library/src/missing/test/edit-integration.native.js @@ -0,0 +1,50 @@ +/** + * External dependencies + */ +import { initializeEditor } from 'test/helpers'; + +/** + * WordPress dependencies + */ +import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; +import * as i18n from '@wordpress/i18n'; +jest.mock( '@wordpress/i18n', () => { + const actual = jest.requireActual( '@wordpress/i18n' ); + return { + ...actual, + _x: jest.fn( actual._x ), + }; +} ); + +/** + * Internal dependencies + */ +import { registerCoreBlocks } from '../..'; + +beforeAll( () => { + // Register all core blocks + registerCoreBlocks(); +} ); + +afterAll( () => { + // Clean up registered blocks + getBlockTypes().forEach( ( block ) => { + unregisterBlockType( block.name ); + } ); +} ); + +describe( 'Unsupported block', () => { + it( 'requests translated block title', async () => { + const initialHtml = ` +
12
34
+ `; + await initializeEditor( { + initialHtml, + } ); + + // jest spy for the _x translation function + const _xSpy = jest.spyOn( i18n, '_x' ); + + expect( _xSpy ).toHaveBeenCalled(); + } ); +} ); From 5004fe6dc9599f1ff42bef37b08e58dd100fe814 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Tue, 13 Jul 2021 12:43:06 -0400 Subject: [PATCH 2/3] Update unsupported block placeholder test - Instead of checking if the `_x` translation function was called, we now instead mock the translations and verify that the translated string appears in the UI. - Add a test to verify translations in the unsupported block bottom sheet title. --- .../missing/test/edit-integration.native.js | 62 ++++++++++++++----- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/packages/block-library/src/missing/test/edit-integration.native.js b/packages/block-library/src/missing/test/edit-integration.native.js index 4ffa2f8bf0f39..ed9bfe13aad7d 100644 --- a/packages/block-library/src/missing/test/edit-integration.native.js +++ b/packages/block-library/src/missing/test/edit-integration.native.js @@ -1,20 +1,13 @@ /** * External dependencies */ -import { initializeEditor } from 'test/helpers'; +import { initializeEditor, fireEvent, waitFor, within } from 'test/helpers'; /** * WordPress dependencies */ import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; -import * as i18n from '@wordpress/i18n'; -jest.mock( '@wordpress/i18n', () => { - const actual = jest.requireActual( '@wordpress/i18n' ); - return { - ...actual, - _x: jest.fn( actual._x ), - }; -} ); +import { setLocaleData } from '@wordpress/i18n'; /** * Internal dependencies @@ -22,11 +15,20 @@ jest.mock( '@wordpress/i18n', () => { import { registerCoreBlocks } from '../..'; beforeAll( () => { + // Mock translations + setLocaleData( { + 'block title\u0004Table': [ 'Tabla' ], + "'%s' is not fully-supported": [ '«%s» no es totalmente compatible' ], + } ); + // Register all core blocks registerCoreBlocks(); } ); afterAll( () => { + // Clean up translations + setLocaleData( {} ); + // Clean up registered blocks getBlockTypes().forEach( ( block ) => { unregisterBlockType( block.name ); @@ -34,17 +36,49 @@ afterAll( () => { } ); describe( 'Unsupported block', () => { - it( 'requests translated block title', async () => { + it( 'requests translated block title in block placeholder', async () => { + const initialHtml = ` +
12
34
+ `; + const { getByA11yLabel } = await initializeEditor( { + initialHtml, + } ); + + const missingBlock = await waitFor( () => + getByA11yLabel( /Unsupported Block\. Row 1/ ) + ); + + const translatedTableTitle = within( missingBlock ).getByText( + 'Tabla' + ); + + expect( translatedTableTitle ).toBeDefined(); + } ); + + it( 'requests translated block title in bottom sheet', async () => { const initialHtml = `
12
34
`; - await initializeEditor( { + const { getByA11yLabel, getByText } = await initializeEditor( { initialHtml, } ); - // jest spy for the _x translation function - const _xSpy = jest.spyOn( i18n, '_x' ); + const missingBlock = await waitFor( () => + getByA11yLabel( /Unsupported Block\. Row 1/ ) + ); + + fireEvent.press( missingBlock ); + + const helpButton = await waitFor( () => + getByA11yLabel( /Help button/ ) + ); + + fireEvent.press( helpButton ); + + const bottomSheetTitle = await waitFor( () => + getByText( '«Tabla» no es totalmente compatible' ) + ); - expect( _xSpy ).toHaveBeenCalled(); + expect( bottomSheetTitle ).toBeDefined(); } ); } ); From b1dbe54b2deb7e58b4c2deeb4491647fa7fb786a Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 15 Jul 2021 10:03:42 -0400 Subject: [PATCH 3/3] Tweak element query for clarity --- .../block-library/src/missing/test/edit-integration.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/missing/test/edit-integration.native.js b/packages/block-library/src/missing/test/edit-integration.native.js index ed9bfe13aad7d..eab4fa1f6f304 100644 --- a/packages/block-library/src/missing/test/edit-integration.native.js +++ b/packages/block-library/src/missing/test/edit-integration.native.js @@ -70,7 +70,7 @@ describe( 'Unsupported block', () => { fireEvent.press( missingBlock ); const helpButton = await waitFor( () => - getByA11yLabel( /Help button/ ) + getByA11yLabel( 'Help button' ) ); fireEvent.press( helpButton );