File size: 1,766 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
/**
* @jest-environment jsdom
*/
import { render, screen } from '@testing-library/react';
import { Provider as ReduxProvider } from 'react-redux';
import { createReduxStore } from 'calypso/state';
import AccountSettingsClose from '../main';
describe( 'AccountSettingsClose', () => {
it( 'Shows Manage purchases button when refundable purchases exist', () => {
render(
<ReduxProvider store={ createTestStore( true, true ) }>
<AccountSettingsClose />
</ReduxProvider>
);
expect( screen.queryByTestId( 'manage-purchases-button' ) ).toBeInTheDocument();
} );
it( 'Tells user to wait if they still have an Atomic site', () => {
render(
<ReduxProvider store={ createTestStore( false, true ) }>
<AccountSettingsClose />
</ReduxProvider>
);
expect( screen.queryByTestId( 'contact-support-button' ) ).toBeInTheDocument();
} );
it( 'Allows user to close account if no refundable purchases & no Atomic site', () => {
render(
<ReduxProvider store={ createTestStore( false, false ) }>
<AccountSettingsClose />
</ReduxProvider>
);
expect( screen.queryByTestId( 'close-account-button' ) ).toBeInTheDocument();
} );
} );
function createTestStore( is_refundable, is_automated_transfer ) {
return createReduxStore(
{
currentUser: {
id: 1,
user: {
primary_blog: 'example',
},
},
purchases: {
hasLoadedUserPurchasesFromServer: true,
data: [
{
is_refundable,
user_id: 1,
product_slug: 'premium_theme',
},
],
},
sites: {
items: {
1234: {
ID: '1234',
URL: 'http://example.com',
is_wpcom_atomic: true,
options: {
is_automated_transfer,
},
},
},
},
},
( state ) => {
return state;
}
);
}
|