@@ -217,13 +217,12 @@ describe('accordion', function () {
217
217
describe ( 'is-open attribute' , function ( ) {
218
218
beforeEach ( function ( ) {
219
219
var tpl =
220
- " <accordion>" +
221
- " <accordion-group heading=\ "title 1\ " is-open=\"open1\ ">Content 1</accordion-group>" +
222
- " <accordion-group heading=\ "title 2\ " is-open=\"open2\ ">Content 2</accordion-group>" +
223
- " </accordion>" ;
220
+ ' <accordion>' +
221
+ ' <accordion-group heading="title 1" is-open="open.first ">Content 1</accordion-group>' +
222
+ ' <accordion-group heading="title 2" is-open="open.second ">Content 2</accordion-group>' +
223
+ ' </accordion>' ;
224
224
element = angular . element ( tpl ) ;
225
- scope . open1 = false ;
226
- scope . open2 = true ;
225
+ scope . open = { first : false , second : true } ;
227
226
$compile ( element ) ( scope ) ;
228
227
scope . $digest ( ) ;
229
228
groups = element . find ( '.accordion-group' ) ;
@@ -237,11 +236,11 @@ describe('accordion', function () {
237
236
it ( 'should toggle variable on element click' , function ( ) {
238
237
findGroupLink ( 0 ) . click ( ) ;
239
238
scope . $digest ( ) ;
240
- expect ( scope . open1 ) . toBe ( true ) ;
239
+ expect ( scope . open . first ) . toBe ( true ) ;
241
240
242
241
findGroupLink ( 0 ) . click ( ) ;
243
242
scope . $digest ( ) ;
244
- expect ( scope . open1 ) . toBe ( false ) ;
243
+ expect ( scope . open . second ) . toBe ( false ) ;
245
244
} ) ;
246
245
} ) ;
247
246
@@ -272,6 +271,42 @@ describe('accordion', function () {
272
271
} ) ;
273
272
} ) ;
274
273
274
+ describe ( 'is-open attribute with dynamic groups' , function ( ) {
275
+ var model ;
276
+ beforeEach ( function ( ) {
277
+ var tpl =
278
+ '<accordion>' +
279
+ '<accordion-group ng-repeat="group in groups" heading="{{group.name}}" is-open="group.open">{{group.content}}</accordion-group>' +
280
+ '</accordion>' ;
281
+ element = angular . element ( tpl ) ;
282
+ scope . groups = [
283
+ { name : 'title 1' , content : 'Content 1' , open : false } ,
284
+ { name : 'title 2' , content : 'Content 2' , open : true }
285
+ ] ;
286
+ $compile ( element ) ( scope ) ;
287
+ scope . $digest ( ) ;
288
+
289
+ groups = element . find ( '.accordion-group' ) ;
290
+ } ) ;
291
+
292
+ it ( 'should have visible group body when the group with isOpen set to true' , function ( ) {
293
+ expect ( findGroupBody ( 0 ) . scope ( ) . isOpen ) . toBe ( false ) ;
294
+ expect ( findGroupBody ( 1 ) . scope ( ) . isOpen ) . toBe ( true ) ;
295
+ } ) ;
296
+
297
+ it ( 'should toggle element on click' , function ( ) {
298
+ findGroupLink ( 0 ) . click ( ) ;
299
+ scope . $digest ( ) ;
300
+ expect ( findGroupBody ( 0 ) . scope ( ) . isOpen ) . toBe ( true ) ;
301
+ expect ( scope . groups [ 0 ] . open ) . toBe ( true ) ;
302
+
303
+ findGroupLink ( 0 ) . click ( ) ;
304
+ scope . $digest ( ) ;
305
+ expect ( findGroupBody ( 0 ) . scope ( ) . isOpen ) . toBe ( false ) ;
306
+ expect ( scope . groups [ 0 ] . open ) . toBe ( false ) ;
307
+ } ) ;
308
+ } ) ;
309
+
275
310
describe ( 'accordion-heading element' , function ( ) {
276
311
beforeEach ( function ( ) {
277
312
var tpl =
0 commit comments