@@ -133,6 +133,7 @@ describe("Collections", () => {
133
133
describe ( "confirm before disassociating libraries" , ( ) => {
134
134
let wrapper : ReactWrapper ;
135
135
let confirmStub : sinon . SinonStub ;
136
+ let instance : CollectionEditForm ;
136
137
137
138
const initialLibraries = [
138
139
{ short_name : "palace" , name : "Palace" } ,
@@ -142,13 +143,11 @@ describe("Collections", () => {
142
143
id : 7 ,
143
144
name : "An OPDS Collection" ,
144
145
protocol : "OPDS Import" ,
145
-
146
146
libraries : [ ...initialLibraries ] ,
147
147
} ;
148
148
149
149
beforeEach ( ( ) => {
150
150
confirmStub = sinon . stub ( window , "confirm" ) ;
151
-
152
151
wrapper = mount (
153
152
< CollectionEditForm
154
153
disabled = { false }
@@ -162,40 +161,64 @@ describe("Collections", () => {
162
161
listDataKey = "collections"
163
162
/>
164
163
) ;
164
+ instance = wrapper . instance ( ) as CollectionEditForm ;
165
165
} ) ;
166
166
167
167
afterEach ( ( ) => {
168
168
confirmStub . restore ( ) ;
169
169
} ) ;
170
170
171
- it ( "calls window.confirm when delete button is clicked " , ( ) => {
171
+ it ( "prompts for confirmation before removing a library " , ( ) => {
172
172
confirmStub . returns ( false ) ;
173
173
174
174
// The confirmation dialog should not be invoked before we click.
175
- expect ( confirmStub . calledOnce ) . to . be . false ;
175
+ expect ( confirmStub . called ) . to . be . false ;
176
176
177
177
wrapper . find ( "button.remove-btn" ) . at ( 0 ) . simulate ( "click" ) ;
178
178
expect ( confirmStub . calledOnce ) . to . be . true ;
179
- expect ( confirmStub . firstCall . args . length ) . to . equal ( 1 ) ;
180
179
const message : string = confirmStub . firstCall . args [ 0 ] ;
181
180
expect ( message ) . to . equal (
182
181
'Disassociating library "Palace" from this collection will ' +
183
182
"remove all loans and holds for its patrons. Do you wish to continue?"
184
183
) ;
185
184
} ) ;
186
185
187
- it ( "does not delete library if confirmation is canceled" , ( ) => {
186
+ it ( "removes library if confirmation is accepted" , ( ) => {
187
+ confirmStub . returns ( true ) ;
188
+ wrapper . find ( "button.remove-btn" ) . at ( 0 ) . simulate ( "click" ) ;
189
+
190
+ // Ensure confirmation was sought.
191
+ expect ( confirmStub . calledOnce ) . to . be . true ;
192
+
193
+ // We deleted the first library, so it should be gone from the state.
194
+ expect ( wrapper . state ( "libraries" ) ) . to . deep . equal ( [ initialLibraries [ 1 ] ] ) ;
195
+ } ) ;
196
+
197
+ it ( "does not remove library if confirmation is canceled" , ( ) => {
188
198
confirmStub . returns ( false ) ;
189
199
wrapper . find ( "button.remove-btn" ) . at ( 0 ) . simulate ( "click" ) ;
200
+
201
+ // Ensure confirmation was sought.
202
+ expect ( confirmStub . calledOnce ) . to . be . true ;
203
+
190
204
// We didn't delete, so we should still have the originals.
191
205
expect ( wrapper . state ( "libraries" ) ) . to . deep . equal ( initialLibraries ) ;
192
206
} ) ;
193
207
194
- it ( "deletes library if confirmation is accepted" , ( ) => {
195
- confirmStub . returns ( true ) ;
208
+ it ( "uses library short_name in confirmation when full name is not available" , ( ) => {
209
+ const getLibraryStub = stub ( instance , "getLibrary" ) . returns ( null ) ;
210
+ confirmStub . returns ( false ) ;
211
+
196
212
wrapper . find ( "button.remove-btn" ) . at ( 0 ) . simulate ( "click" ) ;
197
- // We deleted the first library, so it should be gone from the state.
198
- expect ( wrapper . state ( "libraries" ) ) . to . deep . equal ( [ initialLibraries [ 1 ] ] ) ;
213
+
214
+ expect ( confirmStub . calledOnce ) . to . be . true ;
215
+ const message : string = confirmStub . firstCall . args [ 0 ] ;
216
+ const libraryShortName = initialLibraries [ 0 ] . short_name ;
217
+ expect ( message ) . to . equal (
218
+ `Disassociating library "${ libraryShortName } " from this collection will ` +
219
+ "remove all loans and holds for its patrons. Do you wish to continue?"
220
+ ) ;
221
+ getLibraryStub . restore ( ) ;
199
222
} ) ;
200
223
} ) ;
201
224
} ) ;
0 commit comments