File size: 2,935 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
import { SECTION_SET } from 'calypso/state/action-types';
import { serialize, deserialize } from 'calypso/state/utils';
import reducer, { upgradeIntent } from '../reducer';

describe( 'reducer', () => {
	test( 'should include expected keys in return value', () => {
		expect( Object.keys( reducer( undefined, {} ) ) ).toEqual( [ 'upgradeIntent' ] );
	} );

	describe( '#upgradeIntent()', () => {
		test( 'should persist value', () => {
			const state = serialize( upgradeIntent, 'hallows' );
			expect( state ).toBe( 'hallows' );
		} );

		test( 'should restore value', () => {
			const state = deserialize( upgradeIntent, 'always' );
			expect( state ).toBe( 'always' );
		} );

		test( 'should default to empty string', () => {
			const state = upgradeIntent( undefined, {} );
			expect( state ).toBe( '' );
		} );

		test( 'should return existing state for unsupported action type', () => {
			const state = upgradeIntent( 'penseive', { type: 'EXPECTO_PATRONUM' } );
			expect( state ).toBe( 'penseive' );
		} );

		test( 'should return existing state without section name', () => {
			const state = upgradeIntent( 'time turner', { type: SECTION_SET } );
			expect( state ).toBe( 'time turner' );
		} );

		test( 'should return existing state while loading', () => {
			const state = upgradeIntent( 'quaffle', { type: SECTION_SET, isLoading: true } );
			expect( state ).toBe( 'quaffle' );
		} );

		test( 'should return existing state for checkout', () => {
			const state = upgradeIntent( 'bludger', {
				type: SECTION_SET,
				section: { name: 'checkout' },
			} );
			expect( state ).toBe( 'bludger' );
		} );

		test( 'should return existing state for checkout-thank-you', () => {
			const state = upgradeIntent( 'snitch', {
				type: SECTION_SET,
				section: { name: 'checkout-thank-you' },
			} );
			expect( state ).toBe( 'snitch' );
		} );

		test( 'should return existing state for plans', () => {
			const state = upgradeIntent( 'nimbus', {
				type: SECTION_SET,
				section: { name: 'plans' },
			} );
			expect( state ).toBe( 'nimbus' );
		} );

		test( 'should return plugins for plugins', () => {
			const state = upgradeIntent( 'firebolt', {
				type: SECTION_SET,
				section: { name: 'plugins' },
			} );
			expect( state ).toBe( 'plugins' );
		} );

		test( 'should return themes for themes', () => {
			const state = upgradeIntent( 'hippogryph', {
				type: SECTION_SET,
				section: { name: 'themes' },
			} );
			expect( state ).toBe( 'themes' );
		} );

		test( 'should return hosting for hosting', () => {
			const state = upgradeIntent( 'blastendedskrewt', {
				type: SECTION_SET,
				section: { name: 'hosting' },
			} );
			expect( state ).toBe( 'hosting' );
		} );

		test( 'should return empty string for other section', () => {
			const state = upgradeIntent( 'plugins', {
				type: SECTION_SET,
				section: { name: 'restricted section' },
			} );
			expect( state ).toBe( '' );
		} );
	} );
} );