@@ -87,60 +87,65 @@ describe('StagingComponent', () => {
87
87
} )
88
88
89
89
describe ( 'focusing lists' , ( ) => {
90
- it ( 'focuses staged and unstaged lists accordingly' , async ( ) => {
91
- const workdirPath = await copyRepositoryDir ( 1 )
92
- const repository = await buildRepository ( workdirPath )
93
- const component = new StagingComponent ( { repository} )
94
-
95
- await component . lastModelDataRefreshPromise
96
- await component . selectList ( ListTypes . STAGED )
97
- assert . equal ( component . getSelectedList ( ) , ListTypes . STAGED )
98
- let selectedLists = component . element . querySelectorAll ( '.git-Panel-item.is-focused .is-header' )
99
- assert . equal ( selectedLists . length , 1 )
100
- assert . equal ( selectedLists [ 0 ] . textContent , 'Staged Changes' )
101
-
102
- await component . selectList ( ListTypes . UNSTAGED )
103
- assert . equal ( component . getSelectedList ( ) , ListTypes . UNSTAGED )
104
- selectedLists = component . element . querySelectorAll ( '.git-Panel-item.is-focused .is-header' )
105
- assert . equal ( selectedLists . length , 1 )
106
- assert . equal ( selectedLists [ 0 ] . textContent , 'Unstaged Changes' )
107
-
108
- await component . selectList ( ListTypes . STAGED )
109
- assert . equal ( component . getSelectedList ( ) , ListTypes . STAGED )
110
- selectedLists = component . element . querySelectorAll ( '.git-Panel-item.is-focused .is-header' )
111
- assert . equal ( selectedLists . length , 1 )
112
- assert . equal ( selectedLists [ 0 ] . textContent , 'Staged Changes' )
113
- } )
114
-
115
- describe ( 'git:focus-unstaged-changes' , ( ) => {
116
- it ( 'sets the unstaged list to be focused' , async ( ) => {
90
+ describe ( 'when lists are not empty' , ( ) => {
91
+ let component
92
+ beforeEach ( async ( ) => {
117
93
const workdirPath = await copyRepositoryDir ( 1 )
118
94
const repository = await buildRepository ( workdirPath )
119
95
fs . writeFileSync ( path . join ( workdirPath , 'a.txt' ) , 'a change\n' )
120
96
fs . unlinkSync ( path . join ( workdirPath , 'b.txt' ) )
121
- const component = new StagingComponent ( { repository} )
97
+ component = new StagingComponent ( { repository} )
122
98
await component . lastModelDataRefreshPromise
123
- component . selectList ( ListTypes . STAGED )
124
- assert . equal ( component . getSelectedList ( ) , ListTypes . STAGED )
125
99
126
- atom . commands . dispatch ( component . element , 'git:focus-unstaged-changes' )
127
- assert . equal ( component . getSelectedList ( ) , ListTypes . UNSTAGED )
128
- } )
129
- } )
100
+ const { stagedChangesComponent, unstagedChangesComponent} = component . refs
101
+ const initialUnstagedFilePatches = unstagedChangesComponent . filePatches
130
102
131
- describe ( 'git:focus-staged-changes' , ( ) => {
132
- it ( 'sets the unstaged list to be focused' , async ( ) => {
133
- const workdirPath = await copyRepositoryDir ( 1 )
134
- const repository = await buildRepository ( workdirPath )
135
- fs . writeFileSync ( path . join ( workdirPath , 'a.txt' ) , 'a change\n' )
136
- fs . unlinkSync ( path . join ( workdirPath , 'b.txt' ) )
137
- const component = new StagingComponent ( { repository} )
103
+ // Create three staged files, leaving three unstaged
104
+ await unstagedChangesComponent . didConfirmFilePatch ( initialUnstagedFilePatches [ 0 ] )
138
105
await component . lastModelDataRefreshPromise
139
- component . selectList ( ListTypes . UNSTAGED )
106
+
107
+ assert . equal ( stagedChangesComponent . filePatches . length , 1 )
108
+ assert . equal ( unstagedChangesComponent . filePatches . length , 1 )
109
+ } )
110
+
111
+ it ( 'focuses staged and unstaged lists accordingly' , async ( ) => {
112
+ await component . selectList ( ListTypes . STAGED )
113
+ assert . equal ( component . getSelectedList ( ) , ListTypes . STAGED )
114
+ let selectedLists = component . element . querySelectorAll ( '.git-Panel-item.is-focused .is-header' )
115
+ assert . equal ( selectedLists . length , 1 )
116
+ assert . equal ( selectedLists [ 0 ] . textContent , 'Staged Changes' )
117
+
118
+ await component . selectList ( ListTypes . UNSTAGED )
140
119
assert . equal ( component . getSelectedList ( ) , ListTypes . UNSTAGED )
120
+ selectedLists = component . element . querySelectorAll ( '.git-Panel-item.is-focused .is-header' )
121
+ assert . equal ( selectedLists . length , 1 )
122
+ assert . equal ( selectedLists [ 0 ] . textContent , 'Unstaged Changes' )
141
123
142
- atom . commands . dispatch ( component . element , 'git:focus-staged-changes' )
124
+ await component . selectList ( ListTypes . STAGED )
143
125
assert . equal ( component . getSelectedList ( ) , ListTypes . STAGED )
126
+ selectedLists = component . element . querySelectorAll ( '.git-Panel-item.is-focused .is-header' )
127
+ assert . equal ( selectedLists . length , 1 )
128
+ assert . equal ( selectedLists [ 0 ] . textContent , 'Staged Changes' )
129
+ } )
130
+
131
+ describe ( 'git:focus-unstaged-changes' , ( ) => {
132
+ it ( 'sets the unstaged list to be focused' , ( ) => {
133
+ component . selectList ( ListTypes . STAGED )
134
+ assert . equal ( component . getSelectedList ( ) , ListTypes . STAGED )
135
+
136
+ atom . commands . dispatch ( component . element , 'git:focus-unstaged-changes' )
137
+ assert . equal ( component . getSelectedList ( ) , ListTypes . UNSTAGED )
138
+ } )
139
+ } )
140
+
141
+ describe ( 'git:focus-staged-changes' , ( ) => {
142
+ it ( 'sets the unstaged list to be focused' , ( ) => {
143
+ component . selectList ( ListTypes . UNSTAGED )
144
+ assert . equal ( component . getSelectedList ( ) , ListTypes . UNSTAGED )
145
+
146
+ atom . commands . dispatch ( component . element , 'git:focus-staged-changes' )
147
+ assert . equal ( component . getSelectedList ( ) , ListTypes . STAGED )
148
+ } )
144
149
} )
145
150
} )
146
151
} )
0 commit comments