Skip to content

Commit

Permalink
Merge pull request #203 from Stabzs/master
Browse files Browse the repository at this point in the history
2.0.0 Consolidate uid/id/toasterId into single toasterId
  • Loading branch information
Stabzs committed Apr 12, 2016
2 parents 465b6a8 + e2a77aa commit 97e46f3
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 121 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ AngularJS-Toaster
**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.

[![Build Status](https://travis-ci.org/jirikavi/AngularJS-Toaster.svg)](https://travis-ci.org/jirikavi/AngularJS-Toaster)
[![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)
[![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)

### Current Version 1.2.1
### Current Version 2.0.0

## Angular Compatibility
AngularJS-Toaster requires AngularJS v1.2.6 or higher and specifically targets AngularJS, not Angular 2, although it could be used via ngUpgrade.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularjs-toaster",
"version": "1.2.1",
"version": "2.0.0",
"description": "AngularJS Toaster is a customized version of toastr non-blocking notification javascript library",
"author": "Jiri Kavulak",
"license": "MIT",
Expand Down
45 changes: 30 additions & 15 deletions test/toasterContainerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('toasterContainer', function () {
expect(scope.toasters.length).toBe(2);
});

it('should not allow subsequent duplicates if prevent-duplicates is true without toastId param', function () {
it('should not allow subsequent duplicates if prevent-duplicates is true and body matches', function () {
var container = angular.element(
'<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>');

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

expect(scope.toasters.length).toBe(1);
});

it('should not allow subsequent duplicates if prevent-duplicates is true and id matches with unique bodies', function () {
var container = angular.element(
'<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>');

$compile(container)(rootScope);
rootScope.$digest();

var scope = container.scope();

expect(scope.toasters.length).toBe(0);

var toastWrapper = toaster.pop({ type: 'info', title: 'title', body: 'body' });
toaster.pop({ type: 'info', title: 'title', body: 'body2', toastId: toastWrapper.toastId });

expect(scope.toasters.length).toBe(1);
});
it('should allow subsequent duplicates if prevent-duplicates is true with unique toastId params', function () {
it('should allow subsequent duplicates if prevent-duplicates is true with unique toastId and body params', function () {
var container = angular.element(
'<toaster-container toaster-options="{\'prevent-duplicates\': true}"></toaster-container>');

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

toaster.pop({ type: 'info', title: 'title', body: 'body', toastId: 1 });
toaster.pop({ type: 'info', title: 'title', body: 'body', toastId: 2 });
toaster.pop({ type: 'info', title: 'title', body: 'body2', toastId: 2 });

rootScope.$digest();

Expand Down Expand Up @@ -416,18 +431,18 @@ describe('toasterContainer', function () {


describe('removeToast', function () {
it('should not remove toast if id does not match a toast id', function() {
it('should not remove toast if toastId does not match a toastId', function() {
var container = compileContainer();
var scope = container.scope();

toaster.pop({ type: 'info', body: 'toast 1' });
toaster.pop({ type: 'info', body: 'toast 2' });
var toast1 = toaster.pop({ type: 'info', body: 'toast 1' });
var toast2 = toaster.pop({ type: 'info', body: 'toast 2' });

rootScope.$digest();

expect(scope.toasters.length).toBe(2);
expect(scope.toasters[0].id).toBe(2)
expect(scope.toasters[1].id).toBe(1)
expect(scope.toasters[1].toastId).toBe(toast1.toastId)
expect(scope.toasters[0].toastId).toBe(toast2.toastId)

scope.removeToast(3);

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

spyOn(mock, 'callback');

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

rootScope.$digest();
scope.removeToast(1);
scope.removeToast(toast.toastId);
rootScope.$digest();

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

// removeAllToasts explicitly looks for toast.uid, which is only set
// if toastId is passed as a parameter
toaster.pop({ type: 'info', body: 'toast 1', toasterId: 1, toastId: 1 });
toaster.pop({ type: 'info', body: 'toast 2', toasterId: 2, toastId: 1 });
toaster.pop({ type: 'info', body: 'toast 3', toasterId: 2, toastId: 2 });
var toast1 = toaster.pop({ type: 'info', body: 'toast 1', toasterId: 1, toastId: 1 });
var toast2 = toaster.pop({ type: 'info', body: 'toast 2', toasterId: 2, toastId: 1 });
var toast3 = toaster.pop({ type: 'info', body: 'toast 3', toasterId: 2, toastId: 2 });

rootScope.$digest();

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

toaster.clear(2, 1);
toaster.clear(2, toast2.toastId);

rootScope.$digest();

Expand Down
68 changes: 63 additions & 5 deletions test/toasterServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('toasterService', function () {
expect(scope.toasters[0].type).toBe('toast-error');
});

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

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

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

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

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

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

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

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

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

$compile(container)(rootScope);
Expand All @@ -133,4 +133,62 @@ describe('toasterService', function () {
expect(scope.toasters.length).toBe(1)
expect(scope.toasters[0].type).toBe('toast-error');
});

it('should return a toast wrapper instance from pop', function () {
var container = angular.element('<toaster-container></toaster-container>');

$compile(container)(rootScope);
rootScope.$digest();

var toast = toaster.pop('success', 'title', 'body');
expect(toast).toBeDefined();
expect(angular.isObject(toast)).toBe(true);
expect(angular.isUndefined(toast.toasterId)).toBe(true);
expect(toast.toastId).toBe(container.scope().toasters[0].toastId);
});

it('should return a toast wrapper instance from each helper function', function () {
var container = angular.element('<toaster-container></toaster-container>');

$compile(container)(rootScope);
rootScope.$digest();

var errorToast = toaster.error('title', 'body');
var infoToast = toaster.info('title', 'body');
var waitToast = toaster.wait('title', 'body');
var successToast = toaster.success('title', 'body');
var warningToast = toaster.warning('title', 'body');

expect(errorToast).toBeDefined();
expect(infoToast).toBeDefined();
expect(waitToast).toBeDefined();
expect(successToast).toBeDefined();
expect(warningToast).toBeDefined();
});

it('clear should take toast wrapper returned from pop', function () {
var container = angular.element('<toaster-container></toaster-container>');

$compile(container)(rootScope);
rootScope.$digest();
var scope = container.scope();

var toast = toaster.pop('success', 'title', 'body');
expect(scope.toasters.length).toBe(1);
toaster.clear(toast);
expect(scope.toasters.length).toBe(0);
});

it('clear should take individual arguments from toast wrapper returned from pop', function () {
var container = angular.element('<toaster-container></toaster-container>');

$compile(container)(rootScope);
rootScope.$digest();
var scope = container.scope();

var toast = toaster.pop('success', 'title', 'body');
expect(scope.toasters.length).toBe(1);
toaster.clear(toast.toasterId, toast.toastId);
expect(scope.toasters.length).toBe(0);
});
});
Loading

0 comments on commit 97e46f3

Please sign in to comment.