@@ -11,11 +11,13 @@ import { useSourceControlStore } from '@/stores/sourceControl.store';
11
11
import { useUIStore } from '@/stores/ui.store' ;
12
12
import { useRBACStore } from '@/stores/rbac.store' ;
13
13
import { createComponentRenderer } from '@/__tests__/render' ;
14
+ import { useProjectsStore } from '@/stores/projects.store' ;
14
15
15
16
let pinia : ReturnType < typeof createTestingPinia > ;
16
17
let sourceControlStore : ReturnType < typeof useSourceControlStore > ;
17
18
let uiStore : ReturnType < typeof useUIStore > ;
18
19
let rbacStore : ReturnType < typeof useRBACStore > ;
20
+ let projectStore : ReturnType < typeof useProjectsStore > ;
19
21
20
22
const showMessage = vi . fn ( ) ;
21
23
const showError = vi . fn ( ) ;
@@ -38,6 +40,7 @@ describe('MainSidebarSourceControl', () => {
38
40
} ) ;
39
41
40
42
rbacStore = useRBACStore ( pinia ) ;
43
+ projectStore = useProjectsStore ( pinia ) ;
41
44
vi . spyOn ( rbacStore , 'hasScope' ) . mockReturnValue ( true ) ;
42
45
43
46
sourceControlStore = useSourceControlStore ( ) ;
@@ -58,8 +61,72 @@ describe('MainSidebarSourceControl', () => {
58
61
expect ( getByTestId ( 'main-sidebar-source-control' ) ) . toBeEmptyDOMElement ( ) ;
59
62
} ) ;
60
63
64
+ describe ( 'when connected as project admin' , ( ) => {
65
+ beforeEach ( ( ) => {
66
+ vi . spyOn ( rbacStore , 'hasScope' ) . mockReturnValue ( false ) ;
67
+ vi . spyOn ( sourceControlStore , 'preferences' , 'get' ) . mockReturnValue ( {
68
+ branchName : 'main' ,
69
+ branches : [ ] ,
70
+ repositoryUrl : '' ,
71
+ branchReadOnly : false ,
72
+ branchColor : '#5296D6' ,
73
+ connected : true ,
74
+ publicKey : '' ,
75
+ } ) ;
76
+ projectStore . myProjects = [
77
+ {
78
+ id : '1' ,
79
+ name : 'Test Project' ,
80
+ type : 'team' ,
81
+ scopes : [ 'sourceControl:push' ] ,
82
+ icon : { type : 'emoji' , value : '🚀' } ,
83
+ createdAt : '2023-01-01T00:00:00Z' ,
84
+ updatedAt : '2023-01-01T00:00:00Z' ,
85
+ role : 'project:admin' ,
86
+ } ,
87
+ ] ;
88
+ } ) ;
89
+
90
+ it ( 'should render the appropriate content' , async ( ) => {
91
+ const { getByTestId, queryByTestId } = renderComponent ( {
92
+ pinia,
93
+ props : { isCollapsed : false } ,
94
+ } ) ;
95
+ expect ( getByTestId ( 'main-sidebar-source-control-connected' ) ) . toBeInTheDocument ( ) ;
96
+ expect ( queryByTestId ( 'main-sidebar-source-control-setup' ) ) . not . toBeInTheDocument ( ) ;
97
+
98
+ const pushButton = queryByTestId ( 'main-sidebar-source-control-push' ) ;
99
+ expect ( pushButton ) . toBeInTheDocument ( ) ;
100
+ expect ( pushButton ) . not . toBeDisabled ( ) ;
101
+
102
+ const pullButton = queryByTestId ( 'main-sidebar-source-control-pull' ) ;
103
+ expect ( pullButton ) . toBeInTheDocument ( ) ;
104
+ expect ( pullButton ) . toBeDisabled ( ) ;
105
+ } ) ;
106
+
107
+ it ( 'should disable push button if branch is read-only' , async ( ) => {
108
+ vi . spyOn ( sourceControlStore , 'preferences' , 'get' ) . mockReturnValue ( {
109
+ branchName : 'main' ,
110
+ branches : [ ] ,
111
+ repositoryUrl : '' ,
112
+ branchReadOnly : true ,
113
+ branchColor : '#5296D6' ,
114
+ connected : true ,
115
+ publicKey : '' ,
116
+ } ) ;
117
+
118
+ const { getByTestId } = renderComponent ( {
119
+ pinia,
120
+ props : { isCollapsed : false } ,
121
+ } ) ;
122
+ const pushButton = getByTestId ( 'main-sidebar-source-control-push' ) ;
123
+ expect ( pushButton ) . toBeDisabled ( ) ;
124
+ } ) ;
125
+ } ) ;
126
+
61
127
describe ( 'when connected' , ( ) => {
62
128
beforeEach ( ( ) => {
129
+ vi . spyOn ( rbacStore , 'hasScope' ) . mockReturnValue ( true ) ;
63
130
vi . spyOn ( sourceControlStore , 'preferences' , 'get' ) . mockReturnValue ( {
64
131
branchName : 'main' ,
65
132
branches : [ ] ,
@@ -78,6 +145,32 @@ describe('MainSidebarSourceControl', () => {
78
145
} ) ;
79
146
expect ( getByTestId ( 'main-sidebar-source-control-connected' ) ) . toBeInTheDocument ( ) ;
80
147
expect ( queryByTestId ( 'main-sidebar-source-control-setup' ) ) . not . toBeInTheDocument ( ) ;
148
+
149
+ const pushButton = queryByTestId ( 'main-sidebar-source-control-push' ) ;
150
+ expect ( pushButton ) . toBeInTheDocument ( ) ;
151
+ expect ( pushButton ) . not . toBeDisabled ( ) ;
152
+
153
+ const pullButton = queryByTestId ( 'main-sidebar-source-control-pull' ) ;
154
+ expect ( pullButton ) . toBeInTheDocument ( ) ;
155
+ expect ( pullButton ) . not . toBeDisabled ( ) ;
156
+ } ) ;
157
+
158
+ it ( 'should disable push button if branch is read-only' , async ( ) => {
159
+ vi . spyOn ( sourceControlStore , 'preferences' , 'get' ) . mockReturnValue ( {
160
+ branchName : 'main' ,
161
+ branches : [ ] ,
162
+ repositoryUrl : '' ,
163
+ branchReadOnly : true ,
164
+ branchColor : '#5296D6' ,
165
+ connected : true ,
166
+ publicKey : '' ,
167
+ } ) ;
168
+ const { getByTestId } = renderComponent ( {
169
+ pinia,
170
+ props : { isCollapsed : false } ,
171
+ } ) ;
172
+ const pushButton = getByTestId ( 'main-sidebar-source-control-push' ) ;
173
+ expect ( pushButton ) . toBeDisabled ( ) ;
81
174
} ) ;
82
175
83
176
it ( 'should show toast error if pull response http status code is not 409' , async ( ) => {
0 commit comments