File size: 1,360 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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' );
} );
} );
|