@@ -78,7 +78,7 @@ describe('toasterContainer', function () {
78
78
expect ( scope . toasters . length ) . toBe ( 2 ) ;
79
79
} ) ;
80
80
81
- it ( 'should not allow subsequent duplicates if prevent-duplicates is true without toastId param ' , function ( ) {
81
+ it ( 'should not allow subsequent duplicates if prevent-duplicates is true and body matches ' , function ( ) {
82
82
var container = angular . element (
83
83
'<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>' ) ;
84
84
@@ -92,12 +92,27 @@ describe('toasterContainer', function () {
92
92
toaster . pop ( { type : 'info' , title : 'title' , body : 'body' } ) ;
93
93
toaster . pop ( { type : 'info' , title : 'title' , body : 'body' } ) ;
94
94
95
+ expect ( scope . toasters . length ) . toBe ( 1 ) ;
96
+ } ) ;
97
+
98
+ it ( 'should not allow subsequent duplicates if prevent-duplicates is true and id matches with unique bodies' , function ( ) {
99
+ var container = angular . element (
100
+ '<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>' ) ;
101
+
102
+ $compile ( container ) ( rootScope ) ;
95
103
rootScope . $digest ( ) ;
104
+
105
+ var scope = container . scope ( ) ;
106
+
107
+ expect ( scope . toasters . length ) . toBe ( 0 ) ;
108
+
109
+ var toastWrapper = toaster . pop ( { type : 'info' , title : 'title' , body : 'body' } ) ;
110
+ toaster . pop ( { type : 'info' , title : 'title' , body : 'body2' , toastId : toastWrapper . toastId } ) ;
96
111
97
112
expect ( scope . toasters . length ) . toBe ( 1 ) ;
98
113
} ) ;
99
-
100
- it ( 'should allow subsequent duplicates if prevent-duplicates is true with unique toastId params' , function ( ) {
114
+
115
+ it ( 'should allow subsequent duplicates if prevent-duplicates is true with unique toastId and body params' , function ( ) {
101
116
var container = angular . element (
102
117
'<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>' ) ;
103
118
@@ -109,7 +124,7 @@ describe('toasterContainer', function () {
109
124
expect ( scope . toasters . length ) . toBe ( 0 ) ;
110
125
111
126
toaster . pop ( { type : 'info' , title : 'title' , body : 'body' , toastId : 1 } ) ;
112
- toaster . pop ( { type : 'info' , title : 'title' , body : 'body ' , toastId : 2 } ) ;
127
+ toaster . pop ( { type : 'info' , title : 'title' , body : 'body2 ' , toastId : 2 } ) ;
113
128
114
129
rootScope . $digest ( ) ;
115
130
@@ -416,18 +431,18 @@ describe('toasterContainer', function () {
416
431
417
432
418
433
describe ( 'removeToast' , function ( ) {
419
- it ( 'should not remove toast if id does not match a toast id ' , function ( ) {
434
+ it ( 'should not remove toast if toastId does not match a toastId ' , function ( ) {
420
435
var container = compileContainer ( ) ;
421
436
var scope = container . scope ( ) ;
422
437
423
- toaster . pop ( { type : 'info' , body : 'toast 1' } ) ;
424
- toaster . pop ( { type : 'info' , body : 'toast 2' } ) ;
438
+ var toast1 = toaster . pop ( { type : 'info' , body : 'toast 1' } ) ;
439
+ var toast2 = toaster . pop ( { type : 'info' , body : 'toast 2' } ) ;
425
440
426
441
rootScope . $digest ( ) ;
427
442
428
443
expect ( scope . toasters . length ) . toBe ( 2 ) ;
429
- expect ( scope . toasters [ 0 ] . id ) . toBe ( 2 )
430
- expect ( scope . toasters [ 1 ] . id ) . toBe ( 1 )
444
+ expect ( scope . toasters [ 1 ] . toastId ) . toBe ( toast1 . toastId )
445
+ expect ( scope . toasters [ 0 ] . toastId ) . toBe ( toast2 . toastId )
431
446
432
447
scope . removeToast ( 3 ) ;
433
448
@@ -446,10 +461,10 @@ describe('toasterContainer', function () {
446
461
447
462
spyOn ( mock , 'callback' ) ;
448
463
449
- toaster . pop ( { type : 'info' , body : 'toast 1' , onHideCallback : mock . callback } ) ;
464
+ var toast = toaster . pop ( { type : 'info' , body : 'toast 1' , onHideCallback : mock . callback } ) ;
450
465
451
466
rootScope . $digest ( ) ;
452
- scope . removeToast ( 1 ) ;
467
+ scope . removeToast ( toast . toastId ) ;
453
468
rootScope . $digest ( ) ;
454
469
455
470
expect ( mock . callback ) . toHaveBeenCalled ( ) ;
@@ -619,16 +634,16 @@ describe('toasterContainer', function () {
619
634
620
635
// removeAllToasts explicitly looks for toast.uid, which is only set
621
636
// if toastId is passed as a parameter
622
- toaster . pop ( { type : 'info' , body : 'toast 1' , toasterId : 1 , toastId : 1 } ) ;
623
- toaster . pop ( { type : 'info' , body : 'toast 2' , toasterId : 2 , toastId : 1 } ) ;
624
- toaster . pop ( { type : 'info' , body : 'toast 3' , toasterId : 2 , toastId : 2 } ) ;
637
+ var toast1 = toaster . pop ( { type : 'info' , body : 'toast 1' , toasterId : 1 , toastId : 1 } ) ;
638
+ var toast2 = toaster . pop ( { type : 'info' , body : 'toast 2' , toasterId : 2 , toastId : 1 } ) ;
639
+ var toast3 = toaster . pop ( { type : 'info' , body : 'toast 3' , toasterId : 2 , toastId : 2 } ) ;
625
640
626
641
rootScope . $digest ( ) ;
627
642
628
643
expect ( scope1 . toasters . length ) . toBe ( 1 ) ;
629
644
expect ( scope2 . toasters . length ) . toBe ( 2 ) ;
630
645
631
- toaster . clear ( 2 , 1 ) ;
646
+ toaster . clear ( 2 , toast2 . toastId ) ;
632
647
633
648
rootScope . $digest ( ) ;
634
649
0 commit comments