File size: 5,214 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
127
128
129
130
131
132
133
134
135
136
137
138
/**
 * @jest-environment jsdom
 */

const translate = ( x ) => x;

import {
	PLAN_ECOMMERCE,
	PLAN_ECOMMERCE_2_YEARS,
	PLAN_BUSINESS,
	PLAN_BUSINESS_2_YEARS,
	PLAN_PREMIUM,
	PLAN_PREMIUM_2_YEARS,
	PLAN_PERSONAL,
	PLAN_PERSONAL_2_YEARS,
	PLAN_FREE,
} from '@automattic/calypso-products';
import { render, screen } from '@testing-library/react';
import { PlanStorageBar } from '../bar';

describe( 'PlanStorageBar basic tests', () => {
	const props = {
		translate,
		mediaStorage: {
			storageUsedBytes: 100,
			maxStorageBytes: 1000,
		},
		siteSlug: 'example.com',
		sitePlanSlug: PLAN_FREE,
	};

	test( 'should not blow up and have class .plan-storage-bar', () => {
		const { container } = render( <PlanStorageBar { ...props } /> );
		expect( container.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );
	} );

	test( 'should render ProgressBar', () => {
		render( <PlanStorageBar { ...props } /> );
		const progressBar = screen.queryByRole( 'progressbar' );
		expect( progressBar ).toBeDefined();
		expect( progressBar ).toHaveAttribute( 'aria-valuenow', '10' );
	} );

	test( 'should render when storage is limited', () => {
		const { container: premContainer } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_PREMIUM } />
		);
		expect( premContainer.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: prem2Container } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_PREMIUM_2_YEARS } />
		);
		expect( prem2Container.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: persContailer } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_PERSONAL } />
		);
		expect( persContailer.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: pers2Container } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_PERSONAL_2_YEARS } />
		);
		expect( pers2Container.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: freeContainer } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_FREE } />
		);
		expect( freeContainer.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: busContainer } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_BUSINESS } />
		);
		expect( busContainer.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: bus2Container } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_BUSINESS_2_YEARS } />
		);
		expect( bus2Container.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: ecomContainer } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_ECOMMERCE } />
		);
		expect( ecomContainer.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: ecom2Container } = render(
			<PlanStorageBar { ...props } sitePlanSlug={ PLAN_ECOMMERCE_2_YEARS } />
		);
		expect( ecom2Container.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );
	} );

	test( 'should not render when storage has valid maxStorageBytes', () => {
		const { container: storage1 } = render(
			<PlanStorageBar { ...props } mediaStorage={ { maxStorageBytes: 1 } } />
		);
		expect( storage1.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: storage0 } = render(
			<PlanStorageBar { ...props } mediaStorage={ { maxStorageBytes: 0 } } />
		);
		expect( storage0.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );

		const { container: storage50 } = render(
			<PlanStorageBar { ...props } mediaStorage={ { maxStorageBytes: 50 } } />
		);
		expect( storage50.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 1 );
	} );

	test( 'should not render when storage is falsey or -1', () => {
		const { container: storage0 } = render( <PlanStorageBar { ...props } mediaStorage={ 0 } /> );
		expect( storage0.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 0 );

		const { container: storageFalse } = render(
			<PlanStorageBar { ...props } mediaStorage={ false } />
		);
		expect( storageFalse.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 0 );

		const { container: storageNull } = render(
			<PlanStorageBar { ...props } mediaStorage={ null } />
		);
		expect( storageNull.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 0 );

		const { container: storageUnlimited } = render(
			<PlanStorageBar { ...props } mediaStorage={ { maxStorageBytes: -1 } } />
		);
		expect( storageUnlimited.getElementsByClassName( 'plan-storage__bar' ) ).toHaveLength( 0 );
	} );

	test( 'should include upgrade link when displayUpgradeLink is true', () => {
		const { container } = render( <PlanStorageBar { ...props } displayUpgradeLink /> );
		expect( container.getElementsByClassName( 'plan-storage__storage-link' ) ).toHaveLength( 1 );
	} );

	test( 'should not include upgrade link when displayUpgradeLink is false', () => {
		const { container } = render( <PlanStorageBar { ...props } displayUpgradeLink={ false } /> );
		expect( container.getElementsByClassName( 'plan-storage__storage-link' ) ).toHaveLength( 0 );
	} );
} );