File size: 3,768 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
 * @jest-environment jsdom
 */
import { render as testingLibraryRender } from '@testing-library/react';
import { AuthContext } from '../../../app/auth';
import { Plan } from '../index';
import type { User, Site } from '../../../data/types';

const userId = 1;

function render( ui: React.ReactElement ) {
	return testingLibraryRender(
		<AuthContext.Provider value={ { user: { ID: userId } as User } }>{ ui }</AuthContext.Provider>
	);
}

describe( '<Plan>', () => {
	test( 'for staging sites, it renders "Staging"', () => {
		const site = {
			is_wpcom_staging_site: true,
		} as Site;
		const { container } = render( <Plan site={ site } /> );
		expect( container.textContent ).toBe( 'Staging' );
	} );

	test( 'for self-hosted, Jetpack-connected sites, active Jetpack plugin, it renders the Jetpack logo and plan name', () => {
		const site = {
			is_wpcom_atomic: false,
			jetpack_connection: true,
			jetpack: true,
			plan: {
				product_name_short: 'Free',
			},
		} as Site;
		const { container } = render( <Plan site={ site } /> );
		expect( container.querySelector( 'svg' ) ).toBeInTheDocument();
		expect( container.textContent ).toBe( 'Free' );
	} );

	test( 'for self-hosted, Jetpack-connected sites, inactive Jetpack plugin, it renders dash', () => {
		const site = {
			is_wpcom_atomic: false,
			jetpack_connection: true,
			jetpack: false,
			plan: {
				product_name_short: 'Free',
			},
		} as Site;
		const { container } = render( <Plan site={ site } /> );
		expect( container.textContent ).toBe( '-' );
	} );

	test( 'for WordPress.com Simple sites, it renders the plan name', () => {
		const site = {
			is_wpcom_atomic: false,
			jetpack_connection: false,
			jetpack: false,
			plan: {
				product_name_short: 'Premium',
			},
		} as Site;
		const { container } = render( <Plan site={ site } /> );
		expect( container.textContent ).toBe( 'Premium' );
	} );

	test( 'for WordPress.com Atomic sites, it renders the plan name', () => {
		const site = {
			is_wpcom_atomic: true,
			jetpack_connection: true,
			jetpack: true,
			plan: {
				product_name_short: 'Business',
			},
		} as Site;
		const { container } = render( <Plan site={ site } /> );
		expect( container.textContent ).toBe( 'Business' );
	} );

	test( 'for sites with expired plan, it renders the plan name with "-expired" suffix', () => {
		const site = {
			plan: {
				product_name_short: 'Business',
				expired: true,
			},
		} as Site;
		const { container } = render( <Plan site={ site } /> );
		expect( container.textContent ).toBe( 'Business-expired' );
	} );

	test( 'for sites with expired plan, it renders the plan name with "-expired" suffix and a renewal nag for the site owner', () => {
		const site = {
			slug: 'test.wordpress.com',
			site_owner: userId,
			plan: {
				product_slug: 'business-bundle',
				product_name_short: 'Business',
				expired: true,
			},
		} as Site;
		const { getByText, getByRole } = render( <Plan site={ site } /> );
		expect( getByText( 'Business-expired' ) ).toBeInTheDocument();
		expect( getByRole( 'link', { name: /Renew plan/ } ) ).toHaveAttribute(
			'href',
			'/checkout/test.wordpress.com/business-bundle'
		);
	} );

	test( 'for Trial sites with expired plan, it renders the plan name with "-expired" suffix and an upgrade nag for the site owner', () => {
		const site = {
			slug: 'test.wordpress.com',
			site_owner: userId,
			plan: {
				product_slug: 'ecommerce-trial-bundle-monthly',
				product_name_short: 'Trial',
				expired: true,
			},
		} as Site;
		const { getByText, getByRole } = render( <Plan site={ site } /> );
		expect( getByText( 'Trial-expired' ) ).toBeInTheDocument();
		expect( getByRole( 'link', { name: /Upgrade/ } ) ).toHaveAttribute(
			'href',
			'/plans/test.wordpress.com'
		);
	} );
} );