Skip to content

Commit

Permalink
Search: add support for adding wpcom plan to the shopping cart (#43545)
Browse files Browse the repository at this point in the history
* Enable adding search plans to the cart,

including Atomic sites.

* Enable WP.com sites and subsequent redirect to checkout.

* Enable wpcom_search when processing search purchase

in this way we use jetpack_Search and wpcom_search as product slugs,
but add the later when submitting purchase for WP.com sites.
Also, we remove notice when processing WP.com sites.

* Search: discern product type depending on the type of site

irrespective of the info passed in the url.

* Add support for AT: move the condition checking permissions to the end not redirect to /plans.

* Manage product type at checkout depending on the type of site.

* Correct Jetpack site recognition.

We were using a non-exisitng prop.

* Add icon to the Jetpack Search description,

both at /me/purchase and /my-plan tab.
Also, list the product under /my-plan tab for WP.com sites.

* Enable WPCOM Search purchase in development and stage environments.

* Restrict jetpack_search slug to non-Atomic JP sites.

* Revert "Enable WP.com sites and subsequent redirect to checkout."

This reverts commit 7aabac2.

* Parse monthly product option.

* Enable redirect to checkout for WP.com sites in the  development and stage environments.

Expand the definition of the IS_DOT_COM_GET_SEARCH constant.

* Remove redundant line deletion.

And redundant prop introduction.
  • Loading branch information
AnnaMag authored Jul 1, 2020
1 parent d9a5995 commit 40d6c88
Show file tree
Hide file tree
Showing 15 changed files with 1,367 additions and 40 deletions.
118 changes: 118 additions & 0 deletions client/jetpack-connect/bk-test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/** @jest-environment jsdom */

/**
* External dependencies
*/
import page from 'page';
import React from 'react';
import { externalRedirect } from 'lib/route';
import { identity, noop } from 'lodash';
import { shallow } from 'enzyme';

/**
* Internal dependencies
*/
import { jetpackConnection } from '../jetpack-connection';

const REQUIRED_PROPS = {
checkUrl: noop,
confirmJetpackInstallStatus: noop,
dismissUrl: noop,
getJetpackSiteByUrl: noop,
isRequestingSites: false,
jetpackConnectSite: undefined,
recordTracksEvent: noop,
translate: identity,
};

const ConnectWithHOC = jetpackConnection( () => <div /> );

jest.mock( 'page', () => ( {
redirect: jest.fn(),
} ) );

jest.mock( 'lib/route/path', () => ( {
externalRedirect: jest.fn(),
} ) );

describe( 'ConnectWithHOC', () => {
beforeEach( () => {
externalRedirect.mockReset();
page.redirect.mockReset();
} );

describe( 'makeSafeRedirectionFunction', () => {
test( 'should make a function that can calls the wrapper function', () => {
const component = shallow( <ConnectWithHOC { ...REQUIRED_PROPS } /> );
const innerFunc = jest.fn();
const wrapperFunc = component.instance().makeSafeRedirectionFunction( innerFunc );
expect( () => wrapperFunc() ).not.toThrow();
} );

test( 'should protect against multiple calls', () => {
const innerFunc = jest.fn();
const component = shallow( <ConnectWithHOC { ...REQUIRED_PROPS } /> );
const wrapperFunc = component.instance().makeSafeRedirectionFunction( innerFunc );
wrapperFunc();
wrapperFunc();
wrapperFunc();
expect( innerFunc ).toHaveBeenCalledTimes( 1 );
} );
} );

describe( 'goToRemoteAuth', () => {
test( 'should fire redirect', () => {
const component = shallow( <ConnectWithHOC { ...REQUIRED_PROPS } /> );
component.instance().goToRemoteAuth( 'example.com' );

expect( externalRedirect ).toHaveBeenCalledTimes( 1 );
expect( externalRedirect.mock.calls[ 0 ] ).toMatchSnapshot();
} );

test( 'should dispatch analytics', () => {
const url = 'example.com';
const spy = jest.fn();
const component = shallow(
<ConnectWithHOC { ...REQUIRED_PROPS } recordTracksEvent={ spy } />
);
spy.mockReset();
component.instance().goToRemoteAuth( url );

expect( spy ).toHaveBeenCalledTimes( 1 );
expect( spy.mock.calls[ 0 ] ).toMatchSnapshot();
} );
} );

describe( 'goToPlans', () => {
test( 'should fire redirect', () => {
const component = shallow( <ConnectWithHOC { ...REQUIRED_PROPS } /> );
component.instance().goToPlans( 'example.com' );

expect( page.redirect ).toHaveBeenCalledTimes( 1 );
expect( page.redirect ).toHaveBeenCalledWith( '/jetpack/connect/plans/example.com' );
} );

test( 'should redirect to a site slug', () => {
const url = 'https://example.com/sub-directory-install';
const component = shallow( <ConnectWithHOC { ...REQUIRED_PROPS } /> );
component.instance().goToPlans( url );

expect( page.redirect ).toHaveBeenCalledWith(
'/jetpack/connect/plans/example.com::sub-directory-install'
);
} );

test( 'should dispatch analytics', () => {
const url = 'example.com';
const spy = jest.fn();
const component = shallow(
<ConnectWithHOC { ...REQUIRED_PROPS } recordTracksEvent={ spy } />
);
spy.mockReset();
component.instance().goToPlans( url );

expect( spy ).toHaveBeenCalledTimes( 1 );
expect( spy.mock.calls[ 0 ] ).toMatchSnapshot();
} );
} );
} );
Loading

0 comments on commit 40d6c88

Please sign in to comment.