@@ -5,12 +5,14 @@ import { MOCK_STACK_A_ID } from './support/mock/stacks';
5
5
6
6
describe ( 'Commit Actions' , ( ) => {
7
7
let mockBackend : MockBackend ;
8
+
8
9
beforeEach ( ( ) => {
9
10
mockBackend = new MockBackend ( ) ;
10
11
mockCommand ( 'stack_details' , ( params ) => mockBackend . getStackDetails ( params ) ) ;
11
12
mockCommand ( 'update_commit_message' , ( params ) => mockBackend . updateCommitMessage ( params ) ) ;
12
13
mockCommand ( 'changes_in_worktree' , ( params ) => mockBackend . getWorktreeChanges ( params ) ) ;
13
14
mockCommand ( 'tree_change_diffs' , ( params ) => mockBackend . getDiff ( params ) ) ;
15
+ mockCommand ( 'changes_in_commit' , ( params ) => mockBackend . getCommitChanges ( params ) ) ;
14
16
mockCommand ( 'create_commit_from_worktree_changes' , ( params ) =>
15
17
mockBackend . createCommit ( params )
16
18
) ;
@@ -31,6 +33,7 @@ describe('Commit Actions', () => {
31
33
const newCommitMessageBody = 'New commit message body' ;
32
34
33
35
cy . spy ( mockBackend , 'updateCommitMessage' ) . as ( 'updateCommitMessageSpy' ) ;
36
+ cy . spy ( mockBackend , 'getDiff' ) . as ( 'getDiffSpy' ) ;
34
37
35
38
// Click on the first commit
36
39
cy . getByTestId ( 'commit-row' ) . first ( ) . should ( 'contain' , originalCommitMessage ) . click ( ) ;
@@ -78,6 +81,9 @@ describe('Commit Actions', () => {
78
81
commitOid : mockBackend . commitOid ,
79
82
message : `${ newCommitMessageTitle } \n\n${ newCommitMessageBody } `
80
83
} ) ;
84
+
85
+ // Should never get the diff information, because there are no partial changes being committed.
86
+ expect ( mockBackend . getDiff ) . to . have . callCount ( 0 ) ;
81
87
} ) ;
82
88
83
89
it ( 'Should be able to commit' , ( ) => {
@@ -107,6 +113,9 @@ describe('Commit Actions', () => {
107
113
// Should open the new commit drawer
108
114
cy . getByTestId ( 'new-commit-drawer' ) . should ( 'be.visible' ) ;
109
115
116
+ // Should have the "Your commit goes here" text
117
+ cy . getByTestId ( 'your-commit-goes-here' ) . should ( 'be.visible' ) . should ( 'have.class' , 'first' ) ;
118
+
110
119
// Should have selected the file
111
120
cy . getByTestId ( 'uncommitted-changes-file-list-item' )
112
121
. first ( )
@@ -135,7 +144,101 @@ describe('Commit Actions', () => {
135
144
cy . getByTestId ( 'commit-drawer-title' ) . should ( 'contain' , newCommitMessage ) ;
136
145
cy . getByTestId ( 'commit-drawer-description' ) . should ( 'contain' , newCommitMessageBody ) ;
137
146
138
- // Should never get the diff information, becase there are no partial changes being commmitted.
139
- cy . get ( '@getDiffSpy' ) . should ( 'not.be.called' ) ;
147
+ // Should never get the diff information, because there are no partial changes being committed.
148
+ expect ( mockBackend . getDiff ) . to . have . callCount ( 0 ) ;
149
+ } ) ;
150
+ } ) ;
151
+
152
+ describe ( 'Commit Actions with no stacks' , ( ) => {
153
+ let mockBackend : MockBackend ;
154
+
155
+ beforeEach ( ( ) => {
156
+ mockBackend = new MockBackend ( { initalStacks : [ ] } ) ;
157
+ mockCommand ( 'stacks' , ( ) => mockBackend . getStacks ( ) ) ;
158
+ mockCommand ( 'create_virtual_branch' , ( ) => mockBackend . createBranch ( ) ) ;
159
+ mockCommand ( 'canned_branch_name' , ( ) => mockBackend . getCannedBranchName ( ) ) ;
160
+ mockCommand ( 'stack_details' , ( params ) => mockBackend . getStackDetails ( params ) ) ;
161
+ mockCommand ( 'update_commit_message' , ( params ) => mockBackend . updateCommitMessage ( params ) ) ;
162
+ mockCommand ( 'changes_in_worktree' , ( params ) => mockBackend . getWorktreeChanges ( params ) ) ;
163
+ mockCommand ( 'tree_change_diffs' , ( params ) => mockBackend . getDiff ( params ) ) ;
164
+ mockCommand ( 'changes_in_commit' , ( params ) => mockBackend . getCommitChanges ( params ) ) ;
165
+ mockCommand ( 'create_commit_from_worktree_changes' , ( params ) =>
166
+ mockBackend . createCommit ( params )
167
+ ) ;
168
+
169
+ cy . visit ( '/' ) ;
170
+
171
+ cy . url ( ) . should ( 'include' , `/${ PROJECT_ID } /workspace` ) ;
172
+ } ) ;
173
+
174
+ afterEach ( ( ) => {
175
+ clearCommandMocks ( ) ;
176
+ } ) ;
177
+
178
+ it ( 'Should be able to commit even without a stack present' , ( ) => {
179
+ const newCommitMessage = 'New commit message' ;
180
+ const newCommitMessageBody = 'New commit message body' ;
181
+
182
+ // spies
183
+ cy . spy ( mockBackend , 'getDiff' ) . as ( 'getDiffSpy' ) ;
184
+ cy . spy ( mockBackend , 'createBranch' ) . as ( 'createBranchSpy' ) ;
185
+
186
+ // There should be uncommitted changes
187
+ cy . getByTestId ( 'uncommitted-changes-file-list' ) . should ( 'be.visible' ) ;
188
+
189
+ const fileNames = mockBackend . getWorktreeChangesFileNames ( ) ;
190
+
191
+ expect ( fileNames ) . to . have . length ( 1 ) ;
192
+
193
+ const fileName = fileNames [ 0 ] ! ;
194
+
195
+ cy . getByTestId ( 'uncommitted-changes-file-list-item' )
196
+ . first ( )
197
+ . should ( 'be.visible' )
198
+ . should ( 'contain' , fileName ) ;
199
+
200
+ // Click on the commit button
201
+ cy . getByTestId ( 'start-commit-button' ) . should ( 'be.visible' ) . should ( 'be.enabled' ) . click ( ) ;
202
+
203
+ // Should open the new commit drawer
204
+ cy . getByTestId ( 'new-commit-drawer' ) . should ( 'be.visible' ) ;
205
+
206
+ // Should display the draft stack
207
+ cy . getByTestId ( 'stack-draft' ) . should ( 'be.visible' ) ;
208
+ cy . getByTestId ( 'stack-draft' ) . should ( 'contain' , mockBackend . cannedBranchName ) ;
209
+
210
+ // Should have the "Your commit goes here" text
211
+ cy . getByTestId ( 'your-commit-goes-here' ) . should ( 'be.visible' ) . should ( 'have.class' , 'draft' ) ;
212
+
213
+ // Should have selected the file
214
+ cy . getByTestId ( 'uncommitted-changes-file-list-item' )
215
+ . first ( )
216
+ . get ( 'input[type="checkbox"]' )
217
+ . should ( 'be.checked' ) ;
218
+
219
+ // Type in a commit message
220
+ cy . getByTestId ( 'commit-drawer-title-input' )
221
+ . should ( 'be.visible' )
222
+ . should ( 'be.enabled' )
223
+ . type ( newCommitMessage ) ; // Type the new commit message
224
+
225
+ // Type in a description
226
+ cy . getByTestId ( 'commit-drawer-description-input' )
227
+ . should ( 'be.visible' )
228
+ . click ( )
229
+ . type ( newCommitMessageBody ) ; // Type the new commit message body
230
+
231
+ // Click on the commit button
232
+ cy . getByTestId ( 'commit-drawer-action-button' ) . should ( 'be.visible' ) . should ( 'be.enabled' ) . click ( ) ;
233
+
234
+ // Should display the commit rows
235
+ cy . getByTestId ( 'commit-row' ) . should ( 'have.length' , 1 ) ;
236
+
237
+ // Should commit and select the new commit
238
+ cy . getByTestId ( 'commit-drawer-title' ) . should ( 'contain' , newCommitMessage ) ;
239
+ cy . getByTestId ( 'commit-drawer-description' ) . should ( 'contain' , newCommitMessageBody ) ;
240
+
241
+ // Should never get the diff information, because there are no partial changes being committed.
242
+ expect ( mockBackend . getDiff ) . to . have . callCount ( 0 ) ;
140
243
} ) ;
141
244
} ) ;
0 commit comments