File size: 2,528 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
import getJetpackSites from 'calypso/state/selectors/get-jetpack-sites';
import { userState } from './fixtures/user-state';

describe( 'getJetpackSites()', () => {
	test( 'should return an empty array if no sites exist in state', () => {
		const state = {
			...userState,
			sites: {
				items: {},
			},
		};
		const sites = getJetpackSites( state );
		expect( sites ).toEqual( [] );
	} );

	test( 'should return an empty array if the sites existing are not Jetpack sites', () => {
		const state = {
			...userState,
			sites: {
				items: {
					2916287: { ID: 2916287, name: 'WordPress.com Example Blog' },
					2916286: { ID: 2916286, name: 'WordPress.com Example Blog' },
				},
			},
		};
		const sites = getJetpackSites( state );
		expect( sites ).toEqual( [] );
	} );

	test( 'should return one Jetpack site if only one site exists and it is a Jetpack site', () => {
		const state = {
			...userState,
			sites: {
				items: {
					2916289: {
						ID: 2916289,
						jetpack: true,
						options: {
							unmapped_url: 'https://example.wordpress.com',
						},
					},
				},
			},
		};
		const sites = getJetpackSites( state );
		expect( sites ).toHaveLength( 1 );
		expect( sites[ 0 ].ID ).toEqual( 2916289 );
	} );

	test( 'should return all the sites in state if all of them are Jetpack sites', () => {
		const state = {
			...userState,
			sites: {
				items: {
					2916288: {
						ID: 2916288,
						jetpack: true,
					},
					2916289: {
						ID: 2916289,
						jetpack: true,
						options: {
							unmapped_url: 'https://example2.wordpress.com',
						},
					},
				},
			},
			siteSettings: {
				items: {},
			},
		};
		const sites = getJetpackSites( state );
		expect( sites ).toHaveLength( 2 );
		expect( sites[ 0 ].ID ).toEqual( 2916288 );
		expect( sites[ 1 ].ID ).toEqual( 2916289 );
	} );

	test( 'should return only the Jetpack sites if the state contains Jetpack and non Jetpack sites', () => {
		const state = {
			...userState,
			sites: {
				items: {
					2916288: {
						ID: 2916288,
						jetpack: true,
					},
					2916287: {
						ID: 2916287,
						name: 'WordPress.com Example Blog',
					},
					2916289: {
						ID: 2916289,
						jetpack: true,
					},
					2916286: {
						ID: 2916286,
						name: 'WordPress.com Example Blog',
					},
				},
			},
			siteSettings: {
				items: {},
			},
		};
		const sites = getJetpackSites( state );
		expect( sites ).toHaveLength( 2 );
		expect( sites[ 0 ].ID ).toEqual( 2916288 );
		expect( sites[ 1 ].ID ).toEqual( 2916289 );
	} );
} );