diff --git a/.gitignore b/.gitignore index 184fc0f..6f67095 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ tests/*.js.map index.js index.d.ts index.js.map +_test-output ################# ## JetBrains diff --git a/.npmignore b/.npmignore index 80adf55..90052f5 100644 --- a/.npmignore +++ b/.npmignore @@ -19,6 +19,8 @@ typings.json karma* make.js tsconfig.json +_test-output +systemjs.config.js ################# ## JetBrains diff --git a/README.md b/README.md index ea559ec..bbf69ea 100644 --- a/README.md +++ b/README.md @@ -37,36 +37,55 @@ System.config({ }); ``` -Finally, you can use *ng2-toasty* in your Angular 2 project: -- Import and Export `ToastyModule` from `ng2-toasty` in your main application module +#### 1. Update the markup +- Import style into your web page. Choose one of the following files; + - `style-default.css` - Contains DEFAULT theme + - `style-bootstrap.css` - Contains Bootstrap 3 theme + - `style-material.css` - Contains Material Design theme +- Assign the selected theme name [`default`, `bootstrap`, `material`] to the `theme` property of the instance of ToastyConfig. +- Add `` tag in template of your application component. -```js +#### 2. Import the `ToastyModule` +Import `ToastyModule.forRoot()` in the NgModule of your application. +The `forRoot` method is a convention for modules that provide a singleton service. + +```ts +import {BrowserModule} from "@angular/platform-browser"; import {NgModule} from '@angular/core'; -import {ToastyModule} from 'ng2-translate/ng2-translate'; +import {ToastyModule} from 'ng2-toasty'; @NgModule({ imports: [ - ToastyModule + BrowserModule, + ToastyModule.forRoot() ], - bootstrap: [AppComponent], - export: [ - ToastyModule - ] + bootstrap: [AppComponent] }) export class AppModule { } ``` -- Add `` tag in template of your application component. -- Inject style into your web page. Choose one of the following files; - - `style-default.css` - Contains DEFAULT theme - - `style-bootstrap.css` - Contains Bootstrap 3 theme - - `style-material.css` - Contains Material Design theme -- Assign the selected theme name to the `theme` property of the instance of ToastyConfig. +If you have multiple NgModules and you use one as a shared NgModule (that you import in all of your other NgModules), +don't forget that you can use it to export the `ToastyModule` that you imported in order to avoid having to import it multiple times. + +```ts +@NgModule({ + imports: [ + BrowserModule, + ToastyModule.forRoot() + ], + exports: [BrowserModule, ToastyModule], +}) +export class SharedModule { +} +``` + +#### 3. Use the `ToastyService` for your application +- Import `ToastyService` from `ng2-toasty` in your application code: ```js import {Component} from '@angular/core'; -import {ToastyService, ToastyConfig, ToastyComponent, ToastOptions, ToastData} from 'ng2-toasty'; +import {ToastyService} from 'ng2-toasty'; @Component({ selector: 'app', @@ -78,11 +97,11 @@ import {ToastyService, ToastyConfig, ToastyComponent, ToastOptions, ToastData} f }) export class AppComponent { - constructor(private toastyService:ToastyService, private toastyConfig: ToastyConfig) { + constructor(private toastyService:ToastyService, private toastyConfig: ToastyConfig) { // Assign the selected theme name to the `theme` property of the instance of ToastyConfig. // Possible values: default, bootstrap, material this.toastyConfig.theme = 'material'; - } + } addToast() { // Just add default Toast with title only @@ -111,7 +130,7 @@ export class AppComponent { } ``` -## How dynamically update title and message of a toast +#### 4. How dynamically update title and message of a toast Here is an example of how to dynamically update message and title of individual toast: ```js @@ -182,7 +201,7 @@ export class AppComponent { } ``` -## How to close specific toast +#### 5. How to close specific toast Here is an example of how to close an individual toast: ```js diff --git a/bundles/ng2-toasty.js b/bundles/ng2-toasty.js index f90259d..0c31542 100644 --- a/bundles/ng2-toasty.js +++ b/bundles/ng2-toasty.js @@ -370,6 +370,7 @@ System.registerDynamic("src/toasty.component", ["@angular/core", "./toasty.utils ToastyComponent.POSITIONS = ['bottom-right', 'bottom-left', 'top-right', 'top-left', 'top-center', 'bottom-center']; __decorate([core_1.Input(), __metadata('design:type', String), __metadata('design:paramtypes', [String])], ToastyComponent.prototype, "position", null); ToastyComponent = __decorate([core_1.Component({ + moduleId: module.id, selector: 'ng2-toasty', template: "\n
\n \n
" }), __metadata('design:paramtypes', [toasty_service_1.ToastyConfig, toasty_service_1.ToastyService])], ToastyComponent); @@ -418,6 +419,7 @@ System.registerDynamic("src/toast.component", ["@angular/core"], true, function __decorate([core_1.Input(), __metadata('design:type', Object)], ToastComponent.prototype, "toast", void 0); __decorate([core_1.Output('closeToast'), __metadata('design:type', Object)], ToastComponent.prototype, "closeToastEvent", void 0); ToastComponent = __decorate([core_1.Component({ + moduleId: module.id, selector: 'ng2-toast', template: "\n
\n
\n
\n {{toast.title}}\n
\n {{toast.msg}}\n
\n
" }), __metadata('design:paramtypes', [])], ToastComponent); @@ -464,11 +466,16 @@ System.registerDynamic("index", ["@angular/core", "@angular/common", "./src/toas }; var ToastyModule = function () { function ToastyModule() {} + ToastyModule.forRoot = function () { + return { + ngModule: ToastyModule, + providers: [toasty_service_2.ToastyConfig, toasty_service_2.ToastyService] + }; + }; ToastyModule = __decorate([core_1.NgModule({ imports: [common_1.CommonModule], declarations: [toast_component_1.ToastComponent, toasty_component_2.ToastyComponent], - providers: [toasty_service_2.ToastyConfig, toasty_service_2.ToastyService], - exports: [toasty_component_2.ToastyComponent] + exports: [toast_component_1.ToastComponent, toasty_component_2.ToastyComponent] }), __metadata('design:paramtypes', [])], ToastyModule); return ToastyModule; }(); diff --git a/bundles/ng2-toasty.min.js b/bundles/ng2-toasty.min.js index 4dc94bf..8387527 100644 --- a/bundles/ng2-toasty.min.js +++ b/bundles/ng2-toasty.min.js @@ -1,2 +1,2 @@ -System.registerDynamic("src/toasty.utils",[],!0,function(t,e,o){"use strict";function n(t){return"string"==typeof t}function s(t){return"number"==typeof t}function i(t){return"function"==typeof t}this||self;return e.isString=n,e.isNumber=s,e.isFunction=i,o.exports}),System.registerDynamic("src/toasty.service",["@angular/core","./toasty.utils","rxjs/Observable"],!0,function(t,e,o){"use strict";var n=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),s=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},i=t("@angular/core"),r=t("./toasty.utils"),a=t("rxjs/Observable"),c=function(){function t(){this.limit=5,this.showClose=!0,this.position="bottom-right",this.timeout=5e3,this.theme="default"}return t=n([i.Injectable(),s("design:paramtypes",[])],t)}();e.ToastyConfig=c;var l=function(){function t(t){var e=this;this.config=t,this.uniqueCounter=0,this.toastsObservable=new a.Observable(function(t){e.toastsSubscriber=t}),this.clearObservable=new a.Observable(function(t){e.clearSubscriber=t})}return t.prototype.getToasts=function(){return this.toastsObservable},t.prototype.getClear=function(){return this.clearObservable},t.prototype.default=function(t){this.add(t,"default")},t.prototype.info=function(t){this.add(t,"info")},t.prototype.success=function(t){this.add(t,"success")},t.prototype.wait=function(t){this.add(t,"wait")},t.prototype.error=function(t){this.add(t,"error")},t.prototype.warning=function(t){this.add(t,"warning")},t.prototype.add=function(e,o){var n;if(n=r.isString(e)&&""!==e||r.isNumber(e)?{title:e.toString()}:e,!n||!n.title&&!n.msg)throw new Error("ng2-toasty: No toast title or message specified!");o=o||"default",this.uniqueCounter++;var s,i=this._checkConfigItem(this.config,n,"showClose");s=n.theme&&t.THEMES.indexOf(n.theme)>-1?n.theme:this.config.theme;var a={id:this.uniqueCounter,title:n.title,msg:n.msg,showClose:i,type:"toasty-type-"+o,theme:"toasty-theme-"+s,onAdd:n.onAdd&&r.isFunction(n.onAdd)?n.onAdd:null,onRemove:n.onRemove&&r.isFunction(n.onRemove)?n.onRemove:null};a.timeout=n.hasOwnProperty("timeout")?n.timeout:this.config.timeout;try{this.toastsSubscriber.next(a),n.onAdd&&r.isFunction(n.onAdd)&&n.onAdd.call(this,a)}catch(t){console.log(t),console.log("!!! Suggestion: Seems you forget add into your html?")}},t.prototype.clearAll=function(){this.clearSubscriber.next(null)},t.prototype.clear=function(t){this.clearSubscriber.next(t)},t.prototype._checkConfigItem=function(t,e,o){return e[o]!==!1&&(!!e[o]||t[o])},t.THEMES=["default","material","bootstrap"],t=n([i.Injectable(),s("design:paramtypes",[c])],t)}();return e.ToastyService=l,o.exports}),System.registerDynamic("src/toasty.component",["@angular/core","./toasty.utils","./toasty.service"],!0,function(t,e,o){"use strict";var n=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),s=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},i=t("@angular/core"),r=t("./toasty.utils"),a=t("./toasty.service"),c=function(){function t(t,e){this.config=t,this.toastyService=e,this._position="",this.toasts=[],this.position=""}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(e){if(e){for(var o=!0,n=0;n=t.config.limit&&t.toasts.shift(),t.toasts.push(e),e.timeout&&t._setTimeout(e)}),this.toastyService.getClear().subscribe(function(e){e&&t.clear(e),t.clearAll()})},t.prototype.closeToast=function(t){this.clear(t.id)},t.prototype.clear=function(t){var e=this;if(!t)throw new Error("Please provide id of Toast to close");this.toasts.forEach(function(o,n){o.id===t&&(o.onRemove&&r.isFunction(o.onRemove)&&o.onRemove.call(e,o),e.toasts.splice(n,1))})},t.prototype.clearAll=function(){var t=this;this.toasts.forEach(function(e,o){e.onRemove&&r.isFunction(e.onRemove)&&e.onRemove.call(t,e)}),this.toasts=[]},t.prototype._setTimeout=function(t){var e=this;window.setTimeout(function(){e.clear(t.id)},t.timeout)},t.POSITIONS=["bottom-right","bottom-left","top-right","top-left","top-center","bottom-center"],n([i.Input(),s("design:type",String),s("design:paramtypes",[String])],t.prototype,"position",null),t=n([i.Component({selector:"ng2-toasty",template:'\n
\n \n
'}),s("design:paramtypes",[a.ToastyConfig,a.ToastyService])],t)}();return e.ToastyComponent=c,o.exports}),System.registerDynamic("src/toast.component",["@angular/core"],!0,function(t,e,o){"use strict";var n=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),s=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},i=t("@angular/core"),r=function(){function t(){this.closeToastEvent=new i.EventEmitter}return t.prototype.close=function(t){t.preventDefault(),this.closeToastEvent.next(this.toast)},n([i.Input(),s("design:type",Object)],t.prototype,"toast",void 0),n([i.Output("closeToast"),s("design:type",Object)],t.prototype,"closeToastEvent",void 0),t=n([i.Component({selector:"ng2-toast",template:'\n
\n
\n
\n {{toast.title}}\n
\n {{toast.msg}}\n
\n
'}),s("design:paramtypes",[])],t)}();return e.ToastComponent=r,o.exports}),System.registerDynamic("index",["@angular/core","@angular/common","./src/toasty.service","./src/toasty.component","./src/toast.component"],!0,function(t,e,o){"use strict";function n(t){for(var o in t)e.hasOwnProperty(o)||(e[o]=t[o])}var s=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),i=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},r=t("@angular/core"),a=t("@angular/common");n(t("./src/toasty.service")),n(t("./src/toasty.component"));var c=t("./src/toasty.component"),l=t("./src/toast.component"),u=t("./src/toasty.service");Object.defineProperty(e,"__esModule",{value:!0}),e.default={providers:[u.ToastyConfig,u.ToastyService],directives:[c.ToastyComponent,l.ToastComponent]};var f=function(){function t(){}return t=s([r.NgModule({imports:[a.CommonModule],declarations:[l.ToastComponent,c.ToastyComponent],providers:[u.ToastyConfig,u.ToastyService],exports:[c.ToastyComponent]}),i("design:paramtypes",[])],t)}();return e.ToastyModule=f,o.exports}); +System.registerDynamic("src/toasty.utils",[],!0,function(t,e,o){"use strict";function n(t){return"string"==typeof t}function s(t){return"number"==typeof t}function i(t){return"function"==typeof t}this||self;return e.isString=n,e.isNumber=s,e.isFunction=i,o.exports}),System.registerDynamic("src/toasty.service",["@angular/core","./toasty.utils","rxjs/Observable"],!0,function(t,e,o){"use strict";var n=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),s=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},i=t("@angular/core"),r=t("./toasty.utils"),a=t("rxjs/Observable"),c=function(){function t(){this.limit=5,this.showClose=!0,this.position="bottom-right",this.timeout=5e3,this.theme="default"}return t=n([i.Injectable(),s("design:paramtypes",[])],t)}();e.ToastyConfig=c;var u=function(){function t(t){var e=this;this.config=t,this.uniqueCounter=0,this.toastsObservable=new a.Observable(function(t){e.toastsSubscriber=t}),this.clearObservable=new a.Observable(function(t){e.clearSubscriber=t})}return t.prototype.getToasts=function(){return this.toastsObservable},t.prototype.getClear=function(){return this.clearObservable},t.prototype.default=function(t){this.add(t,"default")},t.prototype.info=function(t){this.add(t,"info")},t.prototype.success=function(t){this.add(t,"success")},t.prototype.wait=function(t){this.add(t,"wait")},t.prototype.error=function(t){this.add(t,"error")},t.prototype.warning=function(t){this.add(t,"warning")},t.prototype.add=function(e,o){var n;if(n=r.isString(e)&&""!==e||r.isNumber(e)?{title:e.toString()}:e,!n||!n.title&&!n.msg)throw new Error("ng2-toasty: No toast title or message specified!");o=o||"default",this.uniqueCounter++;var s,i=this._checkConfigItem(this.config,n,"showClose");s=n.theme&&t.THEMES.indexOf(n.theme)>-1?n.theme:this.config.theme;var a={id:this.uniqueCounter,title:n.title,msg:n.msg,showClose:i,type:"toasty-type-"+o,theme:"toasty-theme-"+s,onAdd:n.onAdd&&r.isFunction(n.onAdd)?n.onAdd:null,onRemove:n.onRemove&&r.isFunction(n.onRemove)?n.onRemove:null};a.timeout=n.hasOwnProperty("timeout")?n.timeout:this.config.timeout;try{this.toastsSubscriber.next(a),n.onAdd&&r.isFunction(n.onAdd)&&n.onAdd.call(this,a)}catch(t){console.log(t),console.log("!!! Suggestion: Seems you forget add into your html?")}},t.prototype.clearAll=function(){this.clearSubscriber.next(null)},t.prototype.clear=function(t){this.clearSubscriber.next(t)},t.prototype._checkConfigItem=function(t,e,o){return e[o]!==!1&&(!!e[o]||t[o])},t.THEMES=["default","material","bootstrap"],t=n([i.Injectable(),s("design:paramtypes",[c])],t)}();return e.ToastyService=u,o.exports}),System.registerDynamic("src/toasty.component",["@angular/core","./toasty.utils","./toasty.service"],!0,function(t,e,o){"use strict";var n=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),s=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},i=t("@angular/core"),r=t("./toasty.utils"),a=t("./toasty.service"),c=function(){function t(t,e){this.config=t,this.toastyService=e,this._position="",this.toasts=[],this.position=""}return Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(e){if(e){for(var o=!0,n=0;n=t.config.limit&&t.toasts.shift(),t.toasts.push(e),e.timeout&&t._setTimeout(e)}),this.toastyService.getClear().subscribe(function(e){e&&t.clear(e),t.clearAll()})},t.prototype.closeToast=function(t){this.clear(t.id)},t.prototype.clear=function(t){var e=this;if(!t)throw new Error("Please provide id of Toast to close");this.toasts.forEach(function(o,n){o.id===t&&(o.onRemove&&r.isFunction(o.onRemove)&&o.onRemove.call(e,o),e.toasts.splice(n,1))})},t.prototype.clearAll=function(){var t=this;this.toasts.forEach(function(e,o){e.onRemove&&r.isFunction(e.onRemove)&&e.onRemove.call(t,e)}),this.toasts=[]},t.prototype._setTimeout=function(t){var e=this;window.setTimeout(function(){e.clear(t.id)},t.timeout)},t.POSITIONS=["bottom-right","bottom-left","top-right","top-left","top-center","bottom-center"],n([i.Input(),s("design:type",String),s("design:paramtypes",[String])],t.prototype,"position",null),t=n([i.Component({moduleId:o.id,selector:"ng2-toasty",template:'\n
\n \n
'}),s("design:paramtypes",[a.ToastyConfig,a.ToastyService])],t)}();return e.ToastyComponent=c,o.exports}),System.registerDynamic("src/toast.component",["@angular/core"],!0,function(t,e,o){"use strict";var n=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),s=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},i=t("@angular/core"),r=function(){function t(){this.closeToastEvent=new i.EventEmitter}return t.prototype.close=function(t){t.preventDefault(),this.closeToastEvent.next(this.toast)},n([i.Input(),s("design:type",Object)],t.prototype,"toast",void 0),n([i.Output("closeToast"),s("design:type",Object)],t.prototype,"closeToastEvent",void 0),t=n([i.Component({moduleId:o.id,selector:"ng2-toast",template:'\n
\n
\n
\n {{toast.title}}\n
\n {{toast.msg}}\n
\n
'}),s("design:paramtypes",[])],t)}();return e.ToastComponent=r,o.exports}),System.registerDynamic("index",["@angular/core","@angular/common","./src/toasty.service","./src/toasty.component","./src/toast.component"],!0,function(t,e,o){"use strict";function n(t){for(var o in t)e.hasOwnProperty(o)||(e[o]=t[o])}var s=(this||self,this&&this.__decorate||function(t,e,o,n){var s,i=arguments.length,r=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(i<3?s(r):i>3?s(e,o,r):s(e,o))||r);return i>3&&r&&Object.defineProperty(e,o,r),r}),i=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},r=t("@angular/core"),a=t("@angular/common");n(t("./src/toasty.service")),n(t("./src/toasty.component"));var c=t("./src/toasty.component"),u=t("./src/toast.component"),l=t("./src/toasty.service");Object.defineProperty(e,"__esModule",{value:!0}),e.default={providers:[l.ToastyConfig,l.ToastyService],directives:[c.ToastyComponent,u.ToastComponent]};var f=function(){function t(){}return t.forRoot=function(){return{ngModule:t,providers:[l.ToastyConfig,l.ToastyService]}},t=s([r.NgModule({imports:[a.CommonModule],declarations:[u.ToastComponent,c.ToastyComponent],exports:[u.ToastComponent,c.ToastyComponent]}),i("design:paramtypes",[])],t)}();return e.ToastyModule=f,o.exports}); //# sourceMappingURL=bundles/ng2-toasty.min.js.map \ No newline at end of file diff --git a/index.ts b/index.ts index 78ab1e7..563d1c0 100644 --- a/index.ts +++ b/index.ts @@ -20,18 +20,15 @@ export default { }; @NgModule({ - imports : [CommonModule], - declarations: [ - ToastComponent, - ToastyComponent - ], - providers : [ - ToastyConfig, - ToastyService - ], - exports : [ - ToastyComponent - ] + imports: [CommonModule], + declarations: [ToastComponent, ToastyComponent], + exports : [ToastComponent, ToastyComponent] }) export class ToastyModule { + static forRoot(): ModuleWithProviders { + return { + ngModule: ToastyModule, + providers: [ToastyConfig, ToastyService] + }; + } } \ No newline at end of file diff --git a/karma-test-shim.js b/karma-test-shim.js index 43369c5..9952664 100644 --- a/karma-test-shim.js +++ b/karma-test-shim.js @@ -1,64 +1,85 @@ -// Turn on full stack traces in errors to help debugging -Error.stackTraceLimit=Infinity; +// #docregion +// /*global jasmine, __karma__, window*/ +Error.stackTraceLimit = Infinity; // -jasmine.DEFAULT_TIMEOUT_INTERVAL = 500; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; -// Cancel Karma's synchronous start, -// we will call `__karma__.start()` later, once all the specs are loaded. -__karma__.loaded = function() {}; +var builtPath = '/base/tests/'; + +__karma__.loaded = function () { }; + +function isJsFile(path) { + return path.slice(-3) == '.js'; +} + +function isSpecFile(path) { + return /\.spec\.(.*\.)?js$/.test(path); +} + +function isBuiltFile(path) { + return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath); +} + +var allSpecFiles = Object.keys(window.__karma__.files) + .filter(isSpecFile) + .filter(isBuiltFile); System.config({ - baseURL: '/base/', - defaultJSExtensions: true, - map: { - '@angular/core/testing': 'node_modules/@angular/core/bundles/core-testing.umd.js', - '@angular/core': 'node_modules/@angular/core/index.js', - '@angular/compiler/testing': 'node_modules/@angular/compiler/bundles/compiler-testing.umd.js', - '@angular/compiler': 'node_modules/@angular/compiler/index.js', - '@angular/common/testing': 'node_modules/@angular/common/testing.js', - '@angular/common': 'node_modules/@angular/common/bundles/common-testing.umd.js', - '@angular/common/src/facade/lang': 'node_modules/@angular/common/src/facade/lang.js', - '@angular/platform-browser-dynamic/testing': 'node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', - '@angular/platform-browser/testing': 'node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js', - '@angular/platform-browser': 'node_modules/@angular/platform-browser/index.js', - '@angular': 'node_modules/@angular', - 'browser_adapter': 'node_modules/@angular/platform-browser/src/browser/browser_adapter', - 'rxjs': 'node_modules/rxjs' - } + baseURL: '/base/', + defaultJSExtensions: true, + + // Assume npm: is set in `paths` in systemjs.config + // Map the angular testing umd bundles + map: { + '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js', + '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js', + '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js', + '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js', + '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', + '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js', + '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js', + '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js', + }, }); -System.import('browser_adapter').then(function(browser_adapter) { - browser_adapter.BrowserDomAdapter.makeCurrent(); -}).then(function() { - return Promise.all( - Object.keys(window.__karma__.files) // All files served by Karma. - .filter(onlySpecFiles) - .map(file2moduleName) - .map(function(path) { - return System.import(path).then(function(module) { - if (module.hasOwnProperty('main')) { - module.main(); - } else { - throw new Error('Module ' + path + ' does not implement main() method.'); - } - }); - })); - }) - .then(function() { - __karma__.start(); - }, function(error) { - console.error(error.stack || error); - __karma__.start(); - }); +System.import('systemjs.config.js') +// .then(importSystemJsExtras) + .then(initTestBed) + .then(initTesting); +/** Optional SystemJS configuration extras. Keep going w/o it */ +// function importSystemJsExtras(){ +// return System.import('systemjs.config.extras.js') +// .catch(function(reason) { +// console.log( +// 'WARNING: System.import could not load "systemjs.config.extras.js"; continuing without it.' +// ); +// console.log(reason); +// }); +// } -function onlySpecFiles(path) { - return /[\.|_]spec\.js$/.test(path); -} +function initTestBed(){ + return Promise.all([ + System.import('@angular/core/testing'), + System.import('@angular/platform-browser-dynamic/testing') + ]) -// Normalize paths to module names. -function file2moduleName(filePath) { - return filePath.replace(/\\/g, '/') - .replace(/^\/base\//, '') - .replace(/\.js/, ''); + .then(function (providers) { + var coreTesting = providers[0]; + var browserTesting = providers[1]; + + coreTesting.TestBed.initTestEnvironment( + browserTesting.BrowserDynamicTestingModule, + browserTesting.platformBrowserDynamicTesting()); + }) +}; + +// Import all spec files and start karma +function initTesting () { + return Promise.all( + allSpecFiles.map(function (moduleName) { + return System.import(moduleName); + }) + ) + .then(__karma__.start, __karma__.error); } \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index f86fd8e..95506e4 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,93 +1,82 @@ -// Karma configuration - -module.exports = function(config) { - config.set({ - - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: './', - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine'], - - // list of files / patterns to load in the browser - files: [ - // System.js for module loading - 'node_modules/systemjs/dist/system.src.js', - - // Polyfills - 'node_modules/core-js/client/shim.js', - - // Reflect and Zone.js - 'node_modules/reflect-metadata/Reflect.js', - 'node_modules/zone.js/dist/zone.js', - 'node_modules/zone.js/dist/long-stack-trace-zone.js', - 'node_modules/zone.js/dist/proxy.js', - 'node_modules/zone.js/dist/sync-test.js', - 'node_modules/zone.js/dist/jasmine-patch.js', - 'node_modules/zone.js/dist/async-test.js', - 'node_modules/zone.js/dist/fake-async-test.js', - - // RxJs. - { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, - { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, - - // Angular 2 itself and the testing library - { pattern: 'node_modules/@angular/**/*.js', included: false, watched: false }, - { pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false }, - - { pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: false, watched: false, served: true }, // PhantomJS2 (and possibly others) might require it - - { pattern: 'src/**/*.ts', included: false, watched: true }, // source files - { pattern: 'tests/**/*.spec.ts', included: false, watched: true }, // test files - 'karma-test-shim.js' - ], - - // list of files to exclude - exclude: [ - 'node_modules/@angular/**/*_spec.js' - ], - - preprocessors: { - '**/*.ts': ['typescript'] - }, - - typescriptPreprocessor: { - options: require('./tsconfig.json').compilerOptions, - typings: [ - "typings/index.d.ts" - ] - }, - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress'], - - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'], - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - - // Concurrency level - // how many browser should be started simultanous - concurrency: Infinity - }) -}; +// #docregion +module.exports = function (config) { + // transpiled src JS and map files + var appBase = 'src/'; + // transpiled test JS and map files + var testBase = 'tests/'; + + config.set({ + basePath: './', + frameworks: ['jasmine'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-firefox-launcher'), + require('karma-htmlfile-reporter') + ], + + customLaunchers: { + // From the CLI. + // Chrome setup for travis CI using chromium + Chrome_travis_ci: { + base: 'Chrome', + flags: ['--no-sandbox'] + } + }, + files: [ + // System.js for module loading + 'node_modules/systemjs/dist/system.src.js', + + // Polyfills + 'node_modules/core-js/client/shim.js', + 'node_modules/reflect-metadata/Reflect.js', + + // zone.js + 'node_modules/zone.js/dist/zone.js', + 'node_modules/zone.js/dist/long-stack-trace-zone.js', + 'node_modules/zone.js/dist/proxy.js', + 'node_modules/zone.js/dist/sync-test.js', + 'node_modules/zone.js/dist/jasmine-patch.js', + 'node_modules/zone.js/dist/async-test.js', + 'node_modules/zone.js/dist/fake-async-test.js', + + // RxJs + { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, + { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, + + // Paths loaded via module imports: + // Angular itself + { pattern: 'node_modules/@angular/**/*.js', included: false, watched: false }, + { pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false }, + + { pattern: 'systemjs.config.js', included: false, watched: false }, + { pattern: 'systemjs.config.extras.js', included: false, watched: false }, + 'karma-test-shim.js', + + // transpiled application & spec code paths loaded via module imports + { pattern: appBase + '**/*.js', included: false, watched: true }, + { pattern: testBase + '**/*.js', included: false, watched: true }, + ], + + exclude: [], + preprocessors: {}, + reporters: ['progress', 'html'], + + // HtmlReporter configuration + htmlReporter: { + // Open this file to see results in browser + outputFile: '_test-output/tests.html', + + // Optional + pageTitle: 'Unit Tests', + subPageTitle: __dirname + }, + + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: false, + browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'], + singleRun: true + }) +} \ No newline at end of file diff --git a/package.json b/package.json index 246393a..3a28b94 100644 --- a/package.json +++ b/package.json @@ -30,28 +30,28 @@ "dependencies": { "core-js": "^2.4.1", "reflect-metadata": "^0.1.3", - "rxjs": "5.0.0-beta.11", - "zone.js": "^0.6.17" + "rxjs": "5.0.0-beta.12", + "zone.js": "^0.6.23" }, "devDependencies": { - "@angular/common": "2.0.0-rc.6", - "@angular/compiler": "2.0.0-rc.6", - "@angular/core": "2.0.0-rc.6", - "@angular/platform-browser": "2.0.0-rc.6", - "@angular/platform-browser-dynamic": "2.0.0-rc.6", + "@angular/common": "2.0.0", + "@angular/compiler": "2.0.0", + "@angular/core": "2.0.0", + "@angular/platform-browser": "2.0.0", + "@angular/platform-browser-dynamic": "2.0.0", "commitizen": "^2.7.6", "cz-conventional-changelog": "^1.1.5", - "jasmine-core": "~2.3.4", - "karma": "~0.13.20", - "karma-chrome-launcher": "~0.2.2", - "karma-firefox-launcher": "~0.1.7", - "karma-jasmine": "~0.3.6", - "karma-typescript-preprocessor": "0.0.21", + "jasmine-core": "~2.5.1", + "karma": "~1.3.0", + "karma-chrome-launcher": "~2.0.0", + "karma-firefox-launcher": "~1.0.0", + "karma-htmlfile-reporter": "^0.3.4", + "karma-jasmine": "~1.0.2", "semantic-release": "^4.3.5", "systemjs": "~0.19.27", "systemjs-builder": "^0.15.6", - "typescript": "^1.8.10", - "typings": "^1.3.2", + "typescript": "^2.0.2", + "typings": "^1.3.3", "uglify-js": "^2.6.2" }, "config": { diff --git a/src/toast.component.ts b/src/toast.component.ts index 1f3aca0..9416f5b 100644 --- a/src/toast.component.ts +++ b/src/toast.component.ts @@ -10,7 +10,7 @@ import { ToastData } from './toasty.service'; * A Toast component shows message with title and close button. */ @Component({ - moduleId: module.id, + moduleId: module.id.toString(), selector: 'ng2-toast', template: `
diff --git a/src/toasty.component.ts b/src/toasty.component.ts index 7a600f5..b4fa8d9 100644 --- a/src/toasty.component.ts +++ b/src/toasty.component.ts @@ -11,7 +11,7 @@ import { ToastyService, ToastData, ToastyConfig } from './toasty.service'; * Toasty is container for Toast components */ @Component({ - moduleId: module.id, + moduleId: module.id.toString(), selector: 'ng2-toasty', template: `
diff --git a/systemjs.config.js b/systemjs.config.js new file mode 100644 index 0000000..7e535ac --- /dev/null +++ b/systemjs.config.js @@ -0,0 +1,39 @@ +/** + * System configuration for Angular 2. + */ +(function (global) { + System.config({ + paths: { + // paths serve as alias + 'npm:': 'node_modules/' + }, + // map tells the System loader where to look for things + map: { + // our app is within the app folder + app: '.', + + // angular bundles + '@angular/core': 'npm:@angular/core/bundles/core.umd.js', + '@angular/common': 'npm:@angular/common/bundles/common.umd.js', + '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', + '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', + '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', + '@angular/http': 'npm:@angular/http/bundles/http.umd.js', + '@angular/router': 'npm:@angular/router/bundles/router.umd.js', + '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', + + // other libraries + 'rxjs': 'npm:rxjs' + }, + // packages tells the System loader how to load when no filename and/or no extension + packages: { + app: { + main: './index.js', + defaultExtension: 'js' + }, + rxjs: { + defaultExtension: 'js' + } + } + }); +})(this); \ No newline at end of file diff --git a/tests/toast.component.spec.ts b/tests/toast.component.spec.ts index 0b1771b..1ee0e14 100644 --- a/tests/toast.component.spec.ts +++ b/tests/toast.component.spec.ts @@ -1,121 +1,111 @@ -import { inject, async, tick, TestBed, ComponentFixture } +import { TestBed, ComponentFixture } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; - import {ToastData} from '../src/toasty.service'; import {ToastComponent} from '../src/toast.component'; -TestBed.resetTestEnvironment(); -TestBed.initTestEnvironment( - BrowserDynamicTestingModule, platformBrowserDynamicTesting()); - -export function main() { - describe('ToastComponent', () => { - - let componentFixture:ComponentFixture; - - const toast:ToastData = { - id:1, - title:null, - msg:null, - showClose:false, - type: 'toasty-type-default', - theme:'toasty-theme-default', - timeout: null, - onAdd: null, - onRemove:null, - onClick:null - }; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [ToastComponent] - }); - TestBed.compileComponents(); +describe('ToastComponent', () => { + + let componentFixture:ComponentFixture; + + const toast:ToastData = { + id:1, + title:null, + msg:null, + showClose:false, + type: 'toasty-type-default', + theme:'toasty-theme-default', + timeout: null, + onAdd: null, + onRemove:null, + onClick:null + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ToastComponent] }); + TestBed.compileComponents(); + }); - beforeEach(() => { - componentFixture = TestBed.createComponent(ToastComponent); - componentFixture.componentInstance.toast = toast; - componentFixture.detectChanges(); - }); + beforeEach(() => { + componentFixture = TestBed.createComponent(ToastComponent); + componentFixture.componentInstance.toast = toast; + componentFixture.detectChanges(); + }); - it('should be defined', () => { - const element = componentFixture.elementRef.nativeElement; - expect(element.querySelector('.toast')).toBeDefined(); - }); + it('should be defined', () => { + const element = componentFixture.elementRef.nativeElement; + expect(element.querySelector('.toast')).toBeDefined(); + }); - it('should has all classes', () => { - const element = componentFixture.nativeElement; - let className:string = element.querySelector('.toast').className; - expect(className.indexOf('toast')).toBeGreaterThan(-1); - expect(className.indexOf('toasty-type-default')).toBeGreaterThan(-1); - expect(className.indexOf('toasty-theme-default')).toBeGreaterThan(-1); - }); + it('should has all classes', () => { + const element = componentFixture.nativeElement; + let className:string = element.querySelector('.toast').className; + expect(className.indexOf('toast')).toBeGreaterThan(-1); + expect(className.indexOf('toasty-type-default')).toBeGreaterThan(-1); + expect(className.indexOf('toasty-theme-default')).toBeGreaterThan(-1); + }); - it('should show close button', () => { - const element = componentFixture.nativeElement; - expect(element.querySelector('.close-button')).toBeNull(); + it('should show close button', () => { + const element = componentFixture.nativeElement; + expect(element.querySelector('.close-button')).toBeNull(); - componentFixture.componentInstance.toast.showClose = true; - componentFixture.detectChanges(); - expect(element.querySelector('.close-button')).not.toBeNull(); - }); + componentFixture.componentInstance.toast.showClose = true; + componentFixture.detectChanges(); + expect(element.querySelector('.close-button')).not.toBeNull(); + }); - it('should show only title', () => { - const element = componentFixture.nativeElement; - expect(element.querySelector('.toast-text')).toBeNull(); + it('should show only title', () => { + const element = componentFixture.nativeElement; + expect(element.querySelector('.toast-text')).toBeNull(); - componentFixture.componentInstance.toast.title = 'title'; - componentFixture.detectChanges(); - expect(element.querySelector('.toast-text')).not.toBeNull(); + componentFixture.componentInstance.toast.title = 'title'; + componentFixture.detectChanges(); + expect(element.querySelector('.toast-text')).not.toBeNull(); - expect(element.querySelector('.toast-title')).not.toBeNull(); - expect(element.querySelector('.toast-title').innerHTML).toBe('title'); + expect(element.querySelector('.toast-title')).not.toBeNull(); + expect(element.querySelector('.toast-title').innerHTML).toBe('title'); - expect(element.querySelector('.toast-msg')).toBeNull(); + expect(element.querySelector('.toast-msg')).toBeNull(); - componentFixture.componentInstance.toast.title = null; - componentFixture.componentInstance.toast.msg = null; - }); + componentFixture.componentInstance.toast.title = null; + componentFixture.componentInstance.toast.msg = null; + }); - it('should show only message', () => { - const element = componentFixture.nativeElement; - expect(element.querySelector('.toast-text')).toBeNull(); + it('should show only message', () => { + const element = componentFixture.nativeElement; + expect(element.querySelector('.toast-text')).toBeNull(); - componentFixture.componentInstance.toast.msg = 'msg'; - componentFixture.detectChanges(); - expect(element.querySelector('.toast-text')).not.toBeNull(); + componentFixture.componentInstance.toast.msg = 'msg'; + componentFixture.detectChanges(); + expect(element.querySelector('.toast-text')).not.toBeNull(); - expect(element.querySelector('.toast-title')).toBeNull(); + expect(element.querySelector('.toast-title')).toBeNull(); - expect(element.querySelector('.toast-msg')).not.toBeNull(); - expect(element.querySelector('.toast-msg').innerHTML).toBe('msg'); + expect(element.querySelector('.toast-msg')).not.toBeNull(); + expect(element.querySelector('.toast-msg').innerHTML).toBe('msg'); - componentFixture.componentInstance.toast.title = null; - componentFixture.componentInstance.toast.msg = null; - }); + componentFixture.componentInstance.toast.title = null; + componentFixture.componentInstance.toast.msg = null; + }); - it('should show title and message', () => { - const element = componentFixture.nativeElement; - expect(element.querySelector('.toast-text')).toBeNull(); + it('should show title and message', () => { + const element = componentFixture.nativeElement; + expect(element.querySelector('.toast-text')).toBeNull(); - componentFixture.componentInstance.toast.title = 'title'; - componentFixture.componentInstance.toast.msg = 'msg'; - componentFixture.detectChanges(); - expect(element.querySelector('.toast-text')).not.toBeNull(); + componentFixture.componentInstance.toast.title = 'title'; + componentFixture.componentInstance.toast.msg = 'msg'; + componentFixture.detectChanges(); + expect(element.querySelector('.toast-text')).not.toBeNull(); - expect(element.querySelector('.toast-title')).not.toBeNull(); - expect(element.querySelector('.toast-title').innerHTML).toBe('title'); + expect(element.querySelector('.toast-title')).not.toBeNull(); + expect(element.querySelector('.toast-title').innerHTML).toBe('title'); - expect(element.querySelector('.toast-msg')).not.toBeNull(); - expect(element.querySelector('.toast-msg').innerHTML).toBe('msg'); + expect(element.querySelector('.toast-msg')).not.toBeNull(); + expect(element.querySelector('.toast-msg').innerHTML).toBe('msg'); - componentFixture.componentInstance.toast.title = null; - componentFixture.componentInstance.toast.msg = null; - }); + componentFixture.componentInstance.toast.title = null; + componentFixture.componentInstance.toast.msg = null; }); -} \ No newline at end of file +}); diff --git a/tests/toasty.component.spec.ts b/tests/toasty.component.spec.ts index dfe79db..6aa6684 100644 --- a/tests/toasty.component.spec.ts +++ b/tests/toasty.component.spec.ts @@ -1,180 +1,171 @@ -import { inject, async, tick, TestBed, ComponentFixture } +import { TestBed, ComponentFixture } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; - import {ToastyService, ToastData, ToastOptions, ToastyConfig} from '../src/toasty.service'; import {ToastyComponent} from '../src/toasty.component'; - -TestBed.resetTestEnvironment(); -TestBed.initTestEnvironment( - BrowserDynamicTestingModule, platformBrowserDynamicTesting()); - -export function main() { - describe('ToastyComponent', () => { - - let componentFixture:ComponentFixture; - - const toast1:ToastData = { - id:1, - title:'title1', - msg:'message1', - showClose:false, - type: 'toasty-type-default', - theme:'toasty-theme-default', - timeout: null, - onAdd: null, - onRemove:null, - onClick:null - }; - - const toast2:ToastData = { - id:2, - title:'title2', - msg:'message2', - showClose:false, - type: 'toasty-type-default', - theme:'toasty-theme-default', - timeout: null, - onAdd: null, - onRemove:null, - onClick:null - }; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [ToastyComponent], - providers: [ToastyService, ToastyConfig] - }); - TestBed.compileComponents(); +import {ToastComponent} from '../src/toast.component'; + +describe('ToastyComponent', () => { + + let componentFixture:ComponentFixture; + + const toast1:ToastData = { + id:1, + title:'title1', + msg:'message1', + showClose:false, + type: 'toasty-type-default', + theme:'toasty-theme-default', + timeout: null, + onAdd: null, + onRemove:null, + onClick:null + }; + + const toast2:ToastData = { + id:2, + title:'title2', + msg:'message2', + showClose:false, + type: 'toasty-type-default', + theme:'toasty-theme-default', + timeout: null, + onAdd: null, + onRemove:null, + onClick:null + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ToastComponent, ToastyComponent], + providers: [ToastyService, ToastyConfig] }); + TestBed.compileComponents(); + }); - beforeEach(() => { - componentFixture = TestBed.createComponent(ToastyComponent); - componentFixture.detectChanges(); - }); - - it('should be defined', () => { - const element = componentFixture.elementRef.nativeElement; - expect(element.querySelector('#toasty')).toBeDefined(); - }); + beforeEach(() => { + componentFixture = TestBed.createComponent(ToastyComponent); + componentFixture.detectChanges(); + }); - it('should update class if position property was not defined', () => { - const element = componentFixture.nativeElement; - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').className).toBe('toasty-position-bottom-right'); - }); + it('should be defined', () => { + const element = componentFixture.elementRef.nativeElement; + expect(element.querySelector('#toasty')).toBeDefined(); + }); - it('should update class if position property was defined with wrong value', () => { - const element = componentFixture.nativeElement; - componentFixture.componentInstance.position = 'left'; - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').className).toBe('toasty-position-bottom-right'); - }); + it('should update class if position property was not defined', () => { + const element = componentFixture.nativeElement; + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').className).toBe('toasty-position-bottom-right'); + }); - it('should update class if position property was defined with right value', () => { - const element = componentFixture.nativeElement; - componentFixture.componentInstance.position = 'bottom-center'; - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').className).toBe('toasty-position-bottom-center'); - }); + it('should update class if position property was defined with wrong value', () => { + const element = componentFixture.nativeElement; + componentFixture.componentInstance.position = 'left'; + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').className).toBe('toasty-position-bottom-right'); + }); - it('should provide the child toast component if it was created via service', () => { - const element = componentFixture.nativeElement; - expect(componentFixture.componentInstance.toasts.length).toBe(0); - expect(element.querySelector('#toasty').children.length).toBe(0); + it('should update class if position property was defined with right value', () => { + const element = componentFixture.nativeElement; + componentFixture.componentInstance.position = 'bottom-center'; + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').className).toBe('toasty-position-bottom-center'); + }); - componentFixture.componentInstance.toasts.push(toast1); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(1); - expect(element.querySelector('#toasty').children[0].tagName).toBe('NG2-TOAST'); - }); + it('should provide the child toast component if it was created via service', () => { + const element = componentFixture.nativeElement; + expect(componentFixture.componentInstance.toasts.length).toBe(0); + expect(element.querySelector('#toasty').children.length).toBe(0); - it('should clear specific toast by id', () => { - const element = componentFixture.nativeElement; - componentFixture.componentInstance.toasts.push(toast1); - componentFixture.componentInstance.toasts.push(toast2); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(2); + componentFixture.componentInstance.toasts.push(toast1); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(1); + expect(element.querySelector('#toasty').children[0].tagName).toBe('NG2-TOAST'); + }); - componentFixture.componentInstance.clear(1); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(1); - }); + it('should clear specific toast by id', () => { + const element = componentFixture.nativeElement; + componentFixture.componentInstance.toasts.push(toast1); + componentFixture.componentInstance.toasts.push(toast2); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(2); - it('should clear all toasts', () => { - const element = componentFixture.nativeElement; - componentFixture.componentInstance.toasts.push(toast1); - componentFixture.componentInstance.toasts.push(toast2); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(2); + componentFixture.componentInstance.clear(1); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(1); + }); - componentFixture.componentInstance.clearAll(); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(0); - }); + it('should clear all toasts', () => { + const element = componentFixture.nativeElement; + componentFixture.componentInstance.toasts.push(toast1); + componentFixture.componentInstance.toasts.push(toast2); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(2); - it('should call onRemove when clear specific toast by id', () => { - const element = componentFixture.nativeElement; - toast1.onRemove = (toast:ToastData) => { - expect(toast).toBe(toast1); - }; - componentFixture.componentInstance.toasts.push(toast1); - componentFixture.componentInstance.toasts.push(toast2); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(2); - - componentFixture.componentInstance.clear(1); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(1); - }); + componentFixture.componentInstance.clearAll(); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(0); + }); - it('should clear toast by closeToast method', () => { - const element = componentFixture.nativeElement; - toast1.onRemove = (toast:ToastData) => { - expect(toast).toBe(toast1); - }; - componentFixture.componentInstance.toasts.push(toast1); - componentFixture.componentInstance.toasts.push(toast2); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(2); - - componentFixture.componentInstance.closeToast(toast1); - componentFixture.detectChanges(); - expect(element.querySelector('#toasty').children.length).toBe(1); - }); + it('should call onRemove when clear specific toast by id', () => { + const element = componentFixture.nativeElement; + toast1.onRemove = (toast:ToastData) => { + expect(toast).toBe(toast1); + }; + componentFixture.componentInstance.toasts.push(toast1); + componentFixture.componentInstance.toasts.push(toast2); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(2); + + componentFixture.componentInstance.clear(1); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(1); + }); - // describe('work with timeout', () => { - - // function createComponent(tcb: TestComponentBuilder): Promise { - // return tcb.createAsync(ToastyContainer).then((cf:ComponentFixture) => { - // cf.detectChanges(); - // return cf; - // }); - // } - - // it('should close toast after timeout', inject([TestComponentBuilder], - // fakeAsync((tcb:TestComponentBuilder) => { - // createComponent(tcb).then((fixture:ComponentFixture) => { - // const element = fixture.nativeElement; - // toast1.onRemove = (toast:Toast) => { - // expect(toast).toBe(toast1); - // }; - // toast1.timeout = 1000; - // fixture.componentInstance.toasts.push(toast1); - // fixture.componentInstance.toasts.push(toast2); - // fixture.detectChanges(); - // expect(element.querySelector('#toasty').children.length).toBe(2); - // tick(); - - // fixture.detectChanges(); - // expect(element.querySelector('#toasty').children.length).toBe(1); - // }); - // }) - // )); - // }); + it('should clear toast by closeToast method', () => { + const element = componentFixture.nativeElement; + toast1.onRemove = (toast:ToastData) => { + expect(toast).toBe(toast1); + }; + componentFixture.componentInstance.toasts.push(toast1); + componentFixture.componentInstance.toasts.push(toast2); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(2); + + componentFixture.componentInstance.closeToast(toast1); + componentFixture.detectChanges(); + expect(element.querySelector('#toasty').children.length).toBe(1); }); -} \ No newline at end of file + + // describe('work with timeout', () => { + + // function createComponent(tcb: TestComponentBuilder): Promise { + // return tcb.createAsync(ToastyContainer).then((cf:ComponentFixture) => { + // cf.detectChanges(); + // return cf; + // }); + // } + + // it('should close toast after timeout', inject([TestComponentBuilder], + // fakeAsync((tcb:TestComponentBuilder) => { + // createComponent(tcb).then((fixture:ComponentFixture) => { + // const element = fixture.nativeElement; + // toast1.onRemove = (toast:Toast) => { + // expect(toast).toBe(toast1); + // }; + // toast1.timeout = 1000; + // fixture.componentInstance.toasts.push(toast1); + // fixture.componentInstance.toasts.push(toast2); + // fixture.detectChanges(); + // expect(element.querySelector('#toasty').children.length).toBe(2); + // tick(); + + // fixture.detectChanges(); + // expect(element.querySelector('#toasty').children.length).toBe(1); + // }); + // }) + // )); + // }); +}); diff --git a/tests/toasty.service.spec.ts b/tests/toasty.service.spec.ts index 27c74df..55c2d67 100644 --- a/tests/toasty.service.spec.ts +++ b/tests/toasty.service.spec.ts @@ -1,264 +1,255 @@ import { inject, fakeAsync, tick, TestBed } from '@angular/core/testing'; -import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } - from '@angular/platform-browser-dynamic/testing'; - import {Observable} from 'rxjs/Observable'; import {ToastyService, ToastData, ToastOptions, ToastyConfig} from '../src/toasty.service'; -TestBed.resetTestEnvironment(); -TestBed.initTestEnvironment( - BrowserDynamicTestingModule, platformBrowserDynamicTesting()); - -export function main() { - describe('ToastyService', () => { +describe('ToastyService', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [ToastyService, ToastyConfig] - }); + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ToastyService, ToastyConfig] }); + }); + + it('is defined', + inject([ToastyService], (service:ToastyService) => { + expect(ToastyService).toBeDefined(); + expect(service instanceof ToastyService).toBeTruthy(); + }) + ); + + it('should return Observable from getToasts method', + inject([ToastyService], (service:ToastyService) => { + expect(service.getToasts instanceof Observable); + }) + ); + + describe('create default toasty', () => { - it('is defined', + it('with string title', inject([ToastyService], (service:ToastyService) => { - expect(ToastyService).toBeDefined(); - expect(service instanceof ToastyService).toBeTruthy(); + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe('Hi'); + expect(toast.msg).not.toBeDefined(); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-default'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.default('Hi'); }) ); - it('should return Observable from getToasts method', + it('with number title', inject([ToastyService], (service:ToastyService) => { - expect(service.getToasts instanceof Observable); + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe('1000'); + expect(toast.msg).not.toBeDefined(); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-default'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.default(1000); }) ); - describe('create default toasty', () => { - - it('with string title', - inject([ToastyService], (service:ToastyService) => { - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe('Hi'); - expect(toast.msg).not.toBeDefined(); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-default'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.default('Hi'); - }) - ); - - it('with number title', - inject([ToastyService], (service:ToastyService) => { - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe('1000'); - expect(toast.msg).not.toBeDefined(); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-default'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.default(1000); - }) - ); + it('with ToastyOptions', + inject([ToastyService], (service:ToastyService) => { + // Create options + var options:ToastOptions = { + title: 'Title', + msg: 'message', + }; + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe(options.title); + expect(toast.msg).toBe(options.msg); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-default'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.default(options); + }) + ); - it('with ToastyOptions', - inject([ToastyService], (service:ToastyService) => { - // Create options - var options:ToastOptions = { - title: 'Title', - msg: 'message', - }; - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); + it('and call onAdd function', + inject([ToastyService], (service:ToastyService) => { + // Create options + var options:ToastOptions = { + title: 'Title', + msg: 'message', + onAdd: (toast:ToastData) => { + expect(toast).toBeDefined(); expect(toast.id).not.toBeNull(); expect(toast.title).toBe(options.title); expect(toast.msg).toBe(options.msg); expect(toast.showClose).toBe(true); expect(toast.type).toBe('toasty-type-default'); expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); + expect(toast.onAdd).not.toBeNull(); expect(toast.onRemove).toBeNull(); - }); - service.default(options); - }) - ); - - it('and call onAdd function', - inject([ToastyService], (service:ToastyService) => { - // Create options - var options:ToastOptions = { - title: 'Title', - msg: 'message', - onAdd: (toast:ToastData) => { - expect(toast).toBeDefined(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe(options.title); - expect(toast.msg).toBe(options.msg); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-default'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).not.toBeNull(); - expect(toast.onRemove).toBeNull(); - } - }; - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => {}); - service.default(options); - }) - ); - }); + } + }; + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => {}); + service.default(options); + }) + ); + }); - describe('create toasty', () => { - it('of info type', - inject([ToastyService], (service:ToastyService) => { - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe('Hi'); - expect(toast.msg).not.toBeDefined(); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-info'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.info('Hi'); - }) - ); + describe('create toasty', () => { + it('of info type', + inject([ToastyService], (service:ToastyService) => { + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe('Hi'); + expect(toast.msg).not.toBeDefined(); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-info'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.info('Hi'); + }) + ); - it('of success type', - inject([ToastyService], (service:ToastyService) => { - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe('Hi'); - expect(toast.msg).not.toBeDefined(); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-success'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.success('Hi'); - }) - ); + it('of success type', + inject([ToastyService], (service:ToastyService) => { + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe('Hi'); + expect(toast.msg).not.toBeDefined(); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-success'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.success('Hi'); + }) + ); - it('of wait type', - inject([ToastyService], (service:ToastyService) => { - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe('Hi'); - expect(toast.msg).not.toBeDefined(); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-wait'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.wait('Hi'); - }) - ); + it('of wait type', + inject([ToastyService], (service:ToastyService) => { + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe('Hi'); + expect(toast.msg).not.toBeDefined(); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-wait'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.wait('Hi'); + }) + ); - it('of error type', - inject([ToastyService], (service:ToastyService) => { - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe('Hi'); - expect(toast.msg).not.toBeDefined(); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-error'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.error('Hi'); - }) - ); + it('of error type', + inject([ToastyService], (service:ToastyService) => { + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe('Hi'); + expect(toast.msg).not.toBeDefined(); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-error'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.error('Hi'); + }) + ); - it('of warning type', - inject([ToastyService], (service:ToastyService) => { - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe('Hi'); - expect(toast.msg).not.toBeDefined(); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-warning'); - expect(toast.theme).toBe('toasty-theme-default'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.warning('Hi'); - }) - ); - }); + it('of warning type', + inject([ToastyService], (service:ToastyService) => { + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe('Hi'); + expect(toast.msg).not.toBeDefined(); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-warning'); + expect(toast.theme).toBe('toasty-theme-default'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.warning('Hi'); + }) + ); + }); - describe('create toasty', () => { - it('of material theme', - inject([ToastyService], (service:ToastyService) => { - var options:ToastOptions = { - title: 'Title', - msg: 'message', - theme: 'material' - } - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe(options.title); - expect(toast.msg).toBe(options.msg); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-default'); - expect(toast.theme).toBe('toasty-theme-material'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.default(options); - }) - ); + describe('create toasty', () => { + it('of material theme', + inject([ToastyService], (service:ToastyService) => { + var options:ToastOptions = { + title: 'Title', + msg: 'message', + theme: 'material' + } + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe(options.title); + expect(toast.msg).toBe(options.msg); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-default'); + expect(toast.theme).toBe('toasty-theme-material'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.default(options); + }) + ); - it('of bootstrap theme', - inject([ToastyService], (service:ToastyService) => { - var options:ToastOptions = { - title: 'Title', - msg: 'message', - theme: 'bootstrap' - } - // We listen our service to recieve new toasts from it - service.getToasts().subscribe((toast:ToastData) => { - expect(toast).not.toBeNull(); - expect(toast.id).not.toBeNull(); - expect(toast.title).toBe(options.title); - expect(toast.msg).toBe(options.msg); - expect(toast.showClose).toBe(true); - expect(toast.type).toBe('toasty-type-default'); - expect(toast.theme).toBe('toasty-theme-bootstrap'); - expect(toast.onAdd).toBeNull(); - expect(toast.onRemove).toBeNull(); - }); - service.default(options); - }) - ); - }); + it('of bootstrap theme', + inject([ToastyService], (service:ToastyService) => { + var options:ToastOptions = { + title: 'Title', + msg: 'message', + theme: 'bootstrap' + } + // We listen our service to recieve new toasts from it + service.getToasts().subscribe((toast:ToastData) => { + expect(toast).not.toBeNull(); + expect(toast.id).not.toBeNull(); + expect(toast.title).toBe(options.title); + expect(toast.msg).toBe(options.msg); + expect(toast.showClose).toBe(true); + expect(toast.type).toBe('toasty-type-default'); + expect(toast.theme).toBe('toasty-theme-bootstrap'); + expect(toast.onAdd).toBeNull(); + expect(toast.onRemove).toBeNull(); + }); + service.default(options); + }) + ); }); -} \ No newline at end of file +}); diff --git a/tsconfig.json b/tsconfig.json index 57e9c0b..9704972 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,10 +8,5 @@ "declaration": true, "moduleResolution": "node", "sourceMap": true - }, - "exclude": [ - "node_modules", - "typings/index.d.ts", - "typings/index" - ] + } } \ No newline at end of file diff --git a/typings.json b/typings.json index 32d1554..7da31ca 100644 --- a/typings.json +++ b/typings.json @@ -1,9 +1,7 @@ { - "globalDevDependencies": { - "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4" - }, "globalDependencies": { - "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2", - "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#aee0039a2d6686ec78352125010ebb38a7a7d743" + "core-js": "registry:dt/core-js#0.0.0+20160725163759", + "jasmine": "registry:dt/jasmine#2.2.0+20160621224255", + "node": "registry:dt/node#6.0.0+20160909174046" } }