Skip to content

Commit 17898a2

Browse files
author
Paul Von Schrottky
authored
Add unsupported block title translation test (#33340)
* Add unsupported block title translation test * 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. * Tweak element query for clarity
1 parent 4fdffac commit 17898a2

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)