|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import { initializeEditor, fireEvent, waitFor, within } from 'test/helpers'; |
| 5 | + |
| 6 | +/** |
| 7 | + * WordPress dependencies |
| 8 | + */ |
| 9 | +import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; |
| 10 | +import { setLocaleData } from '@wordpress/i18n'; |
| 11 | + |
| 12 | +/** |
| 13 | + * Internal dependencies |
| 14 | + */ |
| 15 | +import { registerCoreBlocks } from '../..'; |
| 16 | + |
| 17 | +beforeAll( () => { |
| 18 | + // Mock translations |
| 19 | + setLocaleData( { |
| 20 | + 'block title\u0004Table': [ 'Tabla' ], |
| 21 | + "'%s' is not fully-supported": [ '«%s» no es totalmente compatible' ], |
| 22 | + } ); |
| 23 | + |
| 24 | + // Register all core blocks |
| 25 | + registerCoreBlocks(); |
| 26 | +} ); |
| 27 | + |
| 28 | +afterAll( () => { |
| 29 | + // Clean up translations |
| 30 | + setLocaleData( {} ); |
| 31 | + |
| 32 | + // Clean up registered blocks |
| 33 | + getBlockTypes().forEach( ( block ) => { |
| 34 | + unregisterBlockType( block.name ); |
| 35 | + } ); |
| 36 | +} ); |
| 37 | + |
| 38 | +describe( 'Unsupported block', () => { |
| 39 | + it( 'requests translated block title in block placeholder', async () => { |
| 40 | + const initialHtml = `<!-- wp:table --> |
| 41 | + <figure class="wp-block-table"><table><tbody><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></tbody></table></figure> |
| 42 | + <!-- /wp:table -->`; |
| 43 | + const { getByA11yLabel } = await initializeEditor( { |
| 44 | + initialHtml, |
| 45 | + } ); |
| 46 | + |
| 47 | + const missingBlock = await waitFor( () => |
| 48 | + getByA11yLabel( /Unsupported Block\. Row 1/ ) |
| 49 | + ); |
| 50 | + |
| 51 | + const translatedTableTitle = within( missingBlock ).getByText( |
| 52 | + 'Tabla' |
| 53 | + ); |
| 54 | + |
| 55 | + expect( translatedTableTitle ).toBeDefined(); |
| 56 | + } ); |
| 57 | + |
| 58 | + it( 'requests translated block title in bottom sheet', async () => { |
| 59 | + const initialHtml = `<!-- wp:table --> |
| 60 | + <figure class="wp-block-table"><table><tbody><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></tbody></table></figure> |
| 61 | + <!-- /wp:table -->`; |
| 62 | + const { getByA11yLabel, getByText } = await initializeEditor( { |
| 63 | + initialHtml, |
| 64 | + } ); |
| 65 | + |
| 66 | + const missingBlock = await waitFor( () => |
| 67 | + getByA11yLabel( /Unsupported Block\. Row 1/ ) |
| 68 | + ); |
| 69 | + |
| 70 | + fireEvent.press( missingBlock ); |
| 71 | + |
| 72 | + const helpButton = await waitFor( () => |
| 73 | + getByA11yLabel( 'Help button' ) |
| 74 | + ); |
| 75 | + |
| 76 | + fireEvent.press( helpButton ); |
| 77 | + |
| 78 | + const bottomSheetTitle = await waitFor( () => |
| 79 | + getByText( '«Tabla» no es totalmente compatible' ) |
| 80 | + ); |
| 81 | + |
| 82 | + expect( bottomSheetTitle ).toBeDefined(); |
| 83 | + } ); |
| 84 | +} ); |
0 commit comments