Download wp-calypso/client/controller/test/controller.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.35 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/controller/test/controller.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/controller/test/controller.js
-
curl -L -o controller.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/controller/test/controller.js
2.35 kB
| /** | |
| * @jest-environment jsdom | |
| */ | |
| import * as page from '@automattic/calypso-router'; | |
| import configureStore from 'redux-mock-store'; | |
| import addQueryArgs from 'calypso/lib/url/add-query-args'; | |
| import { redirectMyJetpack } from '../index.web'; | |
| jest.mock( '@automattic/calypso-router' ); | |
| const mockStore = configureStore(); | |
| describe( 'redirectMyJetpack', () => { | |
| let pageSpy; | |
| let next; | |
| const query = { | |
| site: 'example.com', | |
| redirect_to: encodeURIComponent( 'http://example.com/wp-admin/admin.php?page=my-jetpack' ), | |
| source: 'my-jetpack', | |
| }; | |
| const context = { | |
| store: mockStore( { | |
| currentUser: { | |
| id: null, | |
| }, | |
| ui: { | |
| selectedSiteId: null, | |
| }, | |
| } ), | |
| query, | |
| params: { | |
| // These properties are parsed from the path | |
| domainOrProduct: 'jetpack_backup_t1_yearly', | |
| product: '196967475', | |
| }, | |
| path: addQueryArgs( query, `/checkout/123123/jetpack_backup_t1_yearly` ), | |
| pathname: '/checkout/123123/jetpack_backup_t1_yearly', | |
| }; | |
| beforeEach( () => { | |
| pageSpy = jest.spyOn( page, 'default' ); | |
| next = jest.fn(); | |
| } ); | |
| afterEach( () => { | |
| pageSpy.mockRestore(); | |
| next.mockRestore(); | |
| } ); | |
| it( 'should redirect checkout with site id to siteless checkout if user is not logged in', () => { | |
| const redirectUrl = addQueryArgs( | |
| { | |
| connect_after_checkout: true, | |
| from_site_slug: context.query.site, | |
| admin_url: context.query.redirect_to.split( '?' )[ 0 ], | |
| }, | |
| context.path.replace( /checkout\/[^?/]+\//, 'checkout/jetpack/' ) | |
| ); | |
| redirectMyJetpack( context, next ); | |
| expect( pageSpy ).toHaveBeenCalledWith( redirectUrl ); | |
| expect( next ).not.toHaveBeenCalled(); | |
| } ); | |
| it( 'should redirect checkout with site slug to siteless checkout if user is not logged in', () => { | |
| const contextWithSiteSlug = { | |
| ...context, | |
| path: addQueryArgs( query, `/checkout/example.com/jetpack_backup_t1_yearly` ), | |
| pathname: '/checkout/example.com/jetpack_backup_t1_yearly', | |
| }; | |
| const redirectUrl = addQueryArgs( | |
| { | |
| connect_after_checkout: true, | |
| from_site_slug: context.query.site, | |
| admin_url: context.query.redirect_to.split( '?' )[ 0 ], | |
| }, | |
| context.path.replace( /checkout\/[^?/]+\//, 'checkout/jetpack/' ) | |
| ); | |
| redirectMyJetpack( contextWithSiteSlug, next ); | |
| expect( pageSpy ).toHaveBeenCalledWith( redirectUrl ); | |
| expect( next ).not.toHaveBeenCalled(); | |
| } ); | |
| } ); | |