Skip to content

Commit 97e46f3

Browse files
committed
Merge pull request #203 from Stabzs/master
2.0.0 Consolidate uid/id/toasterId into single toasterId
2 parents 465b6a8 + e2a77aa commit 97e46f3

6 files changed

+211
-121
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ AngularJS-Toaster
44
**AngularJS Toaster** is an AngularJS port of the **toastr** non-blocking notification jQuery library. It requires AngularJS v1.2.6 or higher and angular-animate for the CSS3 transformations.
55

66
[![Build Status](https://travis-ci.org/jirikavi/AngularJS-Toaster.svg)](https://travis-ci.org/jirikavi/AngularJS-Toaster)
7-
[![Coverage Status](https://coveralls.io/repos/jirikavi/AngularJS-Toaster/badge.svg?branch=master&service=github&busting=3)](https://coveralls.io/github/jirikavi/AngularJS-Toaster?branch=master)
7+
[![Coverage Status](https://coveralls.io/repos/jirikavi/AngularJS-Toaster/badge.svg?branch=master&service=github&busted=1)](https://coveralls.io/github/jirikavi/AngularJS-Toaster?branch=master)
88

9-
### Current Version 1.2.1
9+
### Current Version 2.0.0
1010

1111
## Angular Compatibility
1212
AngularJS-Toaster requires AngularJS v1.2.6 or higher and specifically targets AngularJS, not Angular 2, although it could be used via ngUpgrade.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-toaster",
3-
"version": "1.2.1",
3+
"version": "2.0.0",
44
"description": "AngularJS Toaster is a customized version of toastr non-blocking notification javascript library",
55
"author": "Jiri Kavulak",
66
"license": "MIT",

test/toasterContainerSpec.js

+30-15
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('toasterContainer', function () {
7878
expect(scope.toasters.length).toBe(2);
7979
});
8080

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 () {
8282
var container = angular.element(
8383
'<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>');
8484

@@ -92,12 +92,27 @@ describe('toasterContainer', function () {
9292
toaster.pop({ type: 'info', title: 'title', body: 'body' });
9393
toaster.pop({ type: 'info', title: 'title', body: 'body' });
9494

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);
95103
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 });
96111

97112
expect(scope.toasters.length).toBe(1);
98113
});
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 () {
101116
var container = angular.element(
102117
'<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>');
103118

@@ -109,7 +124,7 @@ describe('toasterContainer', function () {
109124
expect(scope.toasters.length).toBe(0);
110125

111126
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 });
113128

114129
rootScope.$digest();
115130

@@ -416,18 +431,18 @@ describe('toasterContainer', function () {
416431

417432

418433
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() {
420435
var container = compileContainer();
421436
var scope = container.scope();
422437

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' });
425440

426441
rootScope.$digest();
427442

428443
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)
431446

432447
scope.removeToast(3);
433448

@@ -446,10 +461,10 @@ describe('toasterContainer', function () {
446461

447462
spyOn(mock, 'callback');
448463

449-
toaster.pop({ type: 'info', body: 'toast 1', onHideCallback: mock.callback });
464+
var toast = toaster.pop({ type: 'info', body: 'toast 1', onHideCallback: mock.callback });
450465

451466
rootScope.$digest();
452-
scope.removeToast(1);
467+
scope.removeToast(toast.toastId);
453468
rootScope.$digest();
454469

455470
expect(mock.callback).toHaveBeenCalled();
@@ -619,16 +634,16 @@ describe('toasterContainer', function () {
619634

620635
// removeAllToasts explicitly looks for toast.uid, which is only set
621636
// 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 });
625640

626641
rootScope.$digest();
627642

628643
expect(scope1.toasters.length).toBe(1);
629644
expect(scope2.toasters.length).toBe(2);
630645

631-
toaster.clear(2, 1);
646+
toaster.clear(2, toast2.toastId);
632647

633648
rootScope.$digest();
634649

test/toasterServiceSpec.js

+63-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('toasterService', function () {
3939
expect(scope.toasters[0].type).toBe('toast-error');
4040
});
4141

42-
it('should create an error method from info icon class', function () {
42+
it('should create an info method from info icon class', function () {
4343
var container = angular.element('<toaster-container></toaster-container>');
4444

4545
$compile(container)(rootScope);
@@ -58,7 +58,7 @@ describe('toasterService', function () {
5858
expect(scope.toasters[0].type).toBe('toast-info');
5959
});
6060

61-
it('should create an error method from wait icon class', function () {
61+
it('should create an wait method from wait icon class', function () {
6262
var container = angular.element('<toaster-container></toaster-container>');
6363

6464
$compile(container)(rootScope);
@@ -77,7 +77,7 @@ describe('toasterService', function () {
7777
expect(scope.toasters[0].type).toBe('toast-wait');
7878
});
7979

80-
it('should create an error method from success icon class', function () {
80+
it('should create an success method from success icon class', function () {
8181
var container = angular.element('<toaster-container></toaster-container>');
8282

8383
$compile(container)(rootScope);
@@ -96,7 +96,7 @@ describe('toasterService', function () {
9696
expect(scope.toasters[0].type).toBe('toast-success');
9797
});
9898

99-
it('should create an error method from warning icon class', function () {
99+
it('should create an warning method from warning icon class', function () {
100100
var container = angular.element('<toaster-container></toaster-container>');
101101

102102
$compile(container)(rootScope);
@@ -115,7 +115,7 @@ describe('toasterService', function () {
115115
expect(scope.toasters[0].type).toBe('toast-warning');
116116
});
117117

118-
it('should create a method from the icon class that takes an object', function () {
118+
it('should create a method from the icon class that takes an object', function () {
119119
var container = angular.element('<toaster-container></toaster-container>');
120120

121121
$compile(container)(rootScope);
@@ -133,4 +133,62 @@ describe('toasterService', function () {
133133
expect(scope.toasters.length).toBe(1)
134134
expect(scope.toasters[0].type).toBe('toast-error');
135135
});
136+
137+
it('should return a toast wrapper instance from pop', function () {
138+
var container = angular.element('<toaster-container></toaster-container>');
139+
140+
$compile(container)(rootScope);
141+
rootScope.$digest();
142+
143+
var toast = toaster.pop('success', 'title', 'body');
144+
expect(toast).toBeDefined();
145+
expect(angular.isObject(toast)).toBe(true);
146+
expect(angular.isUndefined(toast.toasterId)).toBe(true);
147+
expect(toast.toastId).toBe(container.scope().toasters[0].toastId);
148+
});
149+
150+
it('should return a toast wrapper instance from each helper function', function () {
151+
var container = angular.element('<toaster-container></toaster-container>');
152+
153+
$compile(container)(rootScope);
154+
rootScope.$digest();
155+
156+
var errorToast = toaster.error('title', 'body');
157+
var infoToast = toaster.info('title', 'body');
158+
var waitToast = toaster.wait('title', 'body');
159+
var successToast = toaster.success('title', 'body');
160+
var warningToast = toaster.warning('title', 'body');
161+
162+
expect(errorToast).toBeDefined();
163+
expect(infoToast).toBeDefined();
164+
expect(waitToast).toBeDefined();
165+
expect(successToast).toBeDefined();
166+
expect(warningToast).toBeDefined();
167+
});
168+
169+
it('clear should take toast wrapper returned from pop', function () {
170+
var container = angular.element('<toaster-container></toaster-container>');
171+
172+
$compile(container)(rootScope);
173+
rootScope.$digest();
174+
var scope = container.scope();
175+
176+
var toast = toaster.pop('success', 'title', 'body');
177+
expect(scope.toasters.length).toBe(1);
178+
toaster.clear(toast);
179+
expect(scope.toasters.length).toBe(0);
180+
});
181+
182+
it('clear should take individual arguments from toast wrapper returned from pop', function () {
183+
var container = angular.element('<toaster-container></toaster-container>');
184+
185+
$compile(container)(rootScope);
186+
rootScope.$digest();
187+
var scope = container.scope();
188+
189+
var toast = toaster.pop('success', 'title', 'body');
190+
expect(scope.toasters.length).toBe(1);
191+
toaster.clear(toast.toasterId, toast.toastId);
192+
expect(scope.toasters.length).toBe(0);
193+
});
136194
});

0 commit comments

Comments
 (0)