File size: 2,739 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
import canCurrentUserManagePlugins from 'calypso/state/selectors/can-current-user-manage-plugins';

describe( 'canCurrentUserManagePlugins()', () => {
	test( 'should return false if no capabilities information exist in state', () => {
		const state = {
			currentUser: {
				capabilities: {},
			},
		};
		expect( canCurrentUserManagePlugins( state ) ).toBe( false );
	} );

	test( 'should return false if one site capability exists without referring if the user can manage it or not', () => {
		const state = {
			currentUser: {
				capabilities: {
					2916284: {
						edit_pages: true,
					},
				},
			},
		};
		expect( canCurrentUserManagePlugins( state ) ).toBe( false );
	} );

	test( 'should return false if several sites capabilities exists without referring if the user can manage it or not', () => {
		const state = {
			currentUser: {
				capabilities: {
					2916284: {
						edit_pages: true,
					},
					2916285: {
						edit_posts: false,
					},
					2916286: {},
				},
			},
		};
		expect( canCurrentUserManagePlugins( state ) ).toBe( false );
	} );

	test( 'should return false if sites capabilities explicitly tell the user can not manage', () => {
		const state = {
			currentUser: {
				capabilities: {
					2916284: {
						edit_pages: true,
						manage_options: false,
					},
					2916285: {
						edit_posts: false,
						manage_options: false,
					},
					2916286: {
						manage_options: false,
					},
				},
			},
		};
		expect( canCurrentUserManagePlugins( state ) ).toBe( false );
	} );

	test( 'should return true if just one site capability exists and the user can manage it', () => {
		const state = {
			currentUser: {
				capabilities: {
					2916284: {
						manage_options: true,
					},
				},
			},
		};
		expect( canCurrentUserManagePlugins( state ) ).toBe( true );
	} );

	test( 'should return true if many sites capabilities exist and the user can manage in all of them', () => {
		const state = {
			currentUser: {
				capabilities: {
					2916284: {
						edit_pages: true,
						manage_options: true,
					},
					2916285: {
						edit_posts: false,
						manage_options: true,
					},
					2916286: {
						manage_options: true,
					},
				},
			},
		};
		expect( canCurrentUserManagePlugins( state ) ).toBe( true );
	} );

	test( 'should return true if many sites capabilities exist and the user can manage in just one', () => {
		const state = {
			currentUser: {
				capabilities: {
					2916284: {
						edit_pages: true,
						manage_options: false,
					},
					2916285: {
						edit_posts: true,
						manage_options: true,
					},
					2916286: {
						manage_options: false,
					},
				},
			},
		};
		expect( canCurrentUserManagePlugins( state ) ).toBe( true );
	} );
} );