Skip to content
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

Lowercase language code from item statement #548

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ export default function createActions(
{ commit }: RootContext,
languageCode: string | undefined | null | false,
) {
if ( typeof languageCode === 'string' ) {
languageCode = languageCode.toLowerCase(); // T349652
}
if ( typeof languageCode === 'string' && !languageCodesProvider.isValid( languageCode ) ) {
languageCode = false;
}
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/store/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ describe( 'HANDLE_LANGUAGE_CHANGE', () => {
} );

it( 'validates and sets to state if valid lang code was returned', async () => {
const getLanguageCodeFromItemMock = jest.fn().mockResolvedValue( 'de' );
// T349652: en-GB from item (preferred IETF lanugage tag format) is lowercased to en-gb (MediaWiki code)
const getLanguageCodeFromItemMock = jest.fn().mockResolvedValue( 'en-GB' );
const isValidMock = jest.fn().mockReturnValue( true );
const actions = createActions(
unusedLexemeCreator,
Expand Down Expand Up @@ -387,9 +388,9 @@ describe( 'HANDLE_LANGUAGE_CHANGE', () => {

expect( store.state.language ).toStrictEqual( { id: 'Q456' } );
expect( store.state.spellingVariant ).toBe( '' );
expect( store.state.languageCodeFromLanguageItem ).toBe( 'de' );
expect( store.state.languageCodeFromLanguageItem ).toBe( 'en-gb' );
expect( getLanguageCodeFromItemMock ).toHaveBeenCalledWith( 'Q456' );
expect( isValidMock ).toHaveBeenCalledWith( 'de' );
expect( isValidMock ).toHaveBeenCalledWith( 'en-gb' );
} );

it( 'validates and sets false state if invalid lang code was returned', async () => {
Expand Down