Download wp-calypso/client/controller/test/shared.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/controller/test/shared.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/controller/test/shared.js
-
curl -L -o shared.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/controller/test/shared.js
1.36 kB
| import { setLocale } from '../../state/ui/language/actions'; | |
| import { setLocaleMiddleware } from '../shared'; | |
| describe( 'setLocaleMiddleware', () => { | |
| const next = jest.fn(); | |
| const dispatch = jest.fn(); | |
| let context; | |
| let middleware; | |
| beforeEach( () => { | |
| next.mockClear(); | |
| dispatch.mockClear(); | |
| context = { query: {}, params: {}, store: { dispatch } }; | |
| middleware = setLocaleMiddleware(); | |
| } ); | |
| it( "doesn't dispatch locale event if no language params found", () => { | |
| middleware( context, next ); | |
| expect( next ).toHaveBeenCalledTimes( 1 ); | |
| expect( context.store.dispatch ).toHaveBeenCalledTimes( 0 ); | |
| } ); | |
| it( 'Dispatch locale event if language param is in URL', () => { | |
| context.params.lang = 'fr'; | |
| middleware( context, next ); | |
| expect( next ).toHaveBeenCalledTimes( 1 ); | |
| expect( context.store.dispatch ).toHaveBeenCalledTimes( 1 ); | |
| expect( context.store.dispatch ).toHaveBeenCalledWith( setLocale( 'fr' ) ); | |
| expect( context.lang ).toEqual( 'fr' ); | |
| } ); | |
| it( 'Dispatch locale event if language param is query param', () => { | |
| context.query.lang = 'fr'; | |
| middleware( context, next ); | |
| expect( next ).toHaveBeenCalledTimes( 1 ); | |
| expect( context.store.dispatch ).toHaveBeenCalledTimes( 1 ); | |
| expect( context.store.dispatch ).toHaveBeenCalledWith( setLocale( 'fr' ) ); | |
| expect( context.lang ).toEqual( 'fr' ); | |
| } ); | |
| } ); | |