@@ -217,13 +217,12 @@ describe('accordion', function () {
217217 describe ( 'is-open attribute' , function ( ) {
218218 beforeEach ( function ( ) {
219219 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>' ;
224224 element = angular . element ( tpl ) ;
225- scope . open1 = false ;
226- scope . open2 = true ;
225+ scope . open = { first : false , second : true } ;
227226 $compile ( element ) ( scope ) ;
228227 scope . $digest ( ) ;
229228 groups = element . find ( '.accordion-group' ) ;
@@ -237,11 +236,11 @@ describe('accordion', function () {
237236 it ( 'should toggle variable on element click' , function ( ) {
238237 findGroupLink ( 0 ) . click ( ) ;
239238 scope . $digest ( ) ;
240- expect ( scope . open1 ) . toBe ( true ) ;
239+ expect ( scope . open . first ) . toBe ( true ) ;
241240
242241 findGroupLink ( 0 ) . click ( ) ;
243242 scope . $digest ( ) ;
244- expect ( scope . open1 ) . toBe ( false ) ;
243+ expect ( scope . open . second ) . toBe ( false ) ;
245244 } ) ;
246245 } ) ;
247246
@@ -272,6 +271,42 @@ describe('accordion', function () {
272271 } ) ;
273272 } ) ;
274273
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+
275310 describe ( 'accordion-heading element' , function ( ) {
276311 beforeEach ( function ( ) {
277312 var tpl =
0 commit comments