-
Notifications
You must be signed in to change notification settings - Fork 17
Fix empty language section and TypeError when no languages are available #1228
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
Changes from 20 commits
5116bec
97cecf1
2deefe2
1475519
ee1e636
707778c
6ceed0b
a32122b
f3b7053
c215e16
704ac79
4d60c89
a16fc90
89648da
3820476
f925dcf
22218eb
5c3bb6b
b845d14
4f0832d
de17268
3ac5fc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -157,6 +157,15 @@ function InactiveLocalesSelect( { | |||
| ) } | ||||
| </optgroup> | ||||
| ) } | ||||
| { ! hasItems && ( | ||||
| <option | ||||
| key="unavailable" | ||||
| value="unavailable" | ||||
| lang="unavailable" | ||||
|
||||
| lang="unavailable" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||||||||||||||||||||||||||||||
| <?php | ||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||
| Plugin Name: No Languages | ||||||||||||||||||||||||||||||||||||
| Plugin URI: https://wordpress.org/ | ||||||||||||||||||||||||||||||||||||
| Description: For testing purposes only. Removes all available languages and translations. | ||||||||||||||||||||||||||||||||||||
| Version: 1.0.0 | ||||||||||||||||||||||||||||||||||||
| Text Domain: no-languages | ||||||||||||||||||||||||||||||||||||
| Domain Path: languages/ | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| add_filter( 'file_mod_allowed', '__return_false' ); | ||||||||||||||||||||||||||||||||||||
| add_filter( 'get_available_languages', '__return_empty_array' ); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| add_filter( 'get_available_languages', '__return_empty_array' ); | |
| add_filter( 'get_available_languages', '__return_empty_array' ); | |
| add_filter( | |
| 'translations_api', | |
| function ( $result, $action, $args ) { | |
| if ( 'core' === $action ) { | |
| // Return an empty translations set so wp_get_available_translations() yields an empty array. | |
| return array( | |
| 'translations' => array(), | |
| ); | |
| } | |
| return $result; | |
| }, | |
| 10, | |
| 3 | |
| ); |
swissspidy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,55 @@ | ||
| import { test, expect } from '@wordpress/e2e-test-utils-playwright'; | ||
|
|
||
| test.describe( 'No Languages Available', () => { | ||
| test.beforeEach( async ( { requestUtils } ) => { | ||
| await requestUtils.activatePlugin( 'no-languages' ); | ||
| } ); | ||
|
|
||
| test.afterEach( async ( { requestUtils } ) => { | ||
| await requestUtils.deactivatePlugin( 'no-languages' ); | ||
| } ); | ||
|
|
||
| test( 'should still display the preferred languages UI with no selectable languages', async ( { | ||
| admin, | ||
| page, | ||
| } ) => { | ||
| const errors: string[] = []; | ||
| page.on( 'console', ( msg ) => { | ||
| if ( msg.type() === 'error' ) { | ||
| errors.push( msg.text() ); | ||
| } | ||
| } ); | ||
|
Comment on lines
+16
to
+21
|
||
|
|
||
| await admin.visitAdminPage( 'options-general.php' ); | ||
|
|
||
| // The native WordPress language dropdown should be replaced. | ||
| await expect( page.locator( '#WPLANG' ) ).toBeHidden(); | ||
|
|
||
| // The plugin's preferred-languages UI should still be visible. | ||
| await expect( | ||
| page.getByRole( 'listbox', { name: 'Language' } ) | ||
| ).toBeVisible(); | ||
|
|
||
| // The inactive locales dropdown should be disabled since there are no languages. | ||
| await expect( | ||
| page.getByRole( 'combobox', { name: 'Inactive Locales' } ) | ||
| ).toHaveValue( 'unavailable' ); | ||
|
|
||
| // The "Add to list" button should also be disabled. | ||
| await expect( | ||
| page.getByRole( 'button', { name: /Add to list/ } ) | ||
| ).toBeDisabled(); | ||
|
|
||
| const introText = page.getByText( | ||
| 'Choose languages for displaying WordPress in, in order of preference.' | ||
| ); | ||
| const fallbackText = page.locator( '.active-locales-empty-message' ); | ||
|
|
||
| await expect( introText ).toBeVisible(); | ||
| await expect( fallbackText ).toBeVisible(); | ||
| } ); | ||
| } ); | ||
|
|
||
| test.describe( 'Settings Page', () => { | ||
| test( 'should display the preferred languages form', async ( { | ||
| admin, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasAnyLanguageswas added as a required prop onActiveLocalesProps, but there are existing call sites that don't provide it (e.g.src/components/test/ActiveLocales.tsx). This will break TypeScript builds/unit tests. Either update allActiveLocalesusages to pass the prop, or makehasAnyLanguagesoptional with a sensible default insideActiveLocales.