1- import { Component , ViewChild } from '@angular/core' ;
2- import { async , TestBed , fakeAsync , tick , ComponentFixture } from '@angular/core/testing' ;
3- import { By } from '@angular/platform-browser' ;
4- import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
5- import { IgxToastComponent , IgxToastModule , IgxToastPosition } from './toast.component' ;
1+ import { Component , ViewChild } from '@angular/core' ;
2+ import {
3+ async ,
4+ TestBed ,
5+ fakeAsync ,
6+ tick ,
7+ ComponentFixture ,
8+ } from '@angular/core/testing' ;
9+ import { By } from '@angular/platform-browser' ;
10+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
11+ import {
12+ IgxToastComponent ,
13+ IgxToastModule ,
14+ } from './toast.component' ;
615import { configureTestSuite } from '../test-utils/configure-suite' ;
716
817describe ( 'IgxToast' , ( ) => {
918 configureTestSuite ( ) ;
1019 beforeAll ( async ( ( ) => {
1120 TestBed . configureTestingModule ( {
12- declarations : [
13- ToastInitializeTestComponent
14- ] ,
15- imports : [
16- BrowserAnimationsModule ,
17- IgxToastModule
18- ]
21+ declarations : [ ToastInitializeTestComponent ] ,
22+ imports : [ BrowserAnimationsModule , IgxToastModule ] ,
1923 } ) . compileComponents ( ) ;
2024 } ) ) ;
2125
2226 const baseClass = 'igx-toast' ;
23- const classes = {
24- top : `${ baseClass } --top` ,
25- middle : `${ baseClass } --middle` ,
26- bottom : `${ baseClass } --bottom` ,
27- } ;
28-
27+ const activeClass = 'igx-toast--active' ;
2928 let fixture : ComponentFixture < ToastInitializeTestComponent > ;
3029 let toast : IgxToastComponent ;
3130
@@ -37,13 +36,14 @@ describe('IgxToast', () => {
3736 } ) ;
3837
3938 it ( 'should properly initialize' , ( ) => {
40- const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
39+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) )
40+ . nativeElement ;
4141 expect ( toast . id ) . toContain ( 'igx-toast-' ) ;
4242 expect ( domToast . id ) . toContain ( 'igx-toast-' ) ;
4343 expect ( toast . displayTime ) . toBe ( 4000 ) ;
4444 expect ( toast . autoHide ) . toBeTruthy ( ) ;
4545 expect ( toast . isVisible ) . toBeTruthy ( ) ;
46- expect ( domToast . classList ) . toContain ( classes . bottom ) ;
46+ expect ( domToast . classList ) . toContain ( activeClass ) ;
4747
4848 toast . id = 'customToast' ;
4949 fixture . detectChanges ( ) ;
@@ -52,45 +52,17 @@ describe('IgxToast', () => {
5252 expect ( domToast . id ) . toBe ( 'customToast' ) ;
5353 } ) ;
5454
55- it ( 'should change toast position to middle' , ( ) => {
56- toast . position = IgxToastPosition . Middle ;
57- fixture . detectChanges ( ) ;
58- const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
59-
60- expect ( domToast . classList ) . toContain ( classes . middle ) ;
61- } ) ;
62-
63- it ( 'should change toast position to top' , ( ) => {
64- toast . position = IgxToastPosition . Top ;
65- fixture . detectChanges ( ) ;
66- const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
67-
68- expect ( domToast . classList ) . toContain ( classes . top ) ;
69- } ) ;
70-
71- it ( 'should change toast position to bottom' , ( ) => {
72- toast . position = IgxToastPosition . Bottom ;
73- fixture . detectChanges ( ) ;
74- const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
75-
76- expect ( domToast . classList ) . not . toContain ( classes . top ) ;
77- expect ( domToast . classList ) . not . toContain ( classes . middle ) ;
78- expect ( domToast . classList ) . toContain ( classes . bottom ) ;
79- } ) ;
80-
8155 it ( 'should auto hide 1 second after it\'s open' , fakeAsync ( ( ) => {
8256 toast . displayTime = 1000 ;
8357
8458 toast . show ( ) ;
8559
8660 expect ( toast . isVisible ) . toBeTruthy ( ) ;
87- expect ( toast . animationState ) . toBe ( 'visible' ) ;
8861 expect ( toast . autoHide ) . toBeTruthy ( ) ;
8962
9063 tick ( 1000 ) ;
9164
9265 expect ( toast . isVisible ) . toBeFalsy ( ) ;
93- expect ( toast . animationState ) . toBe ( 'invisible' ) ;
9466 } ) ) ;
9567
9668 it ( 'should not auto hide after it\'s open' , fakeAsync ( ( ) => {
@@ -100,13 +72,11 @@ describe('IgxToast', () => {
10072 toast . show ( ) ;
10173
10274 expect ( toast . isVisible ) . toBeTruthy ( ) ;
103- expect ( toast . animationState ) . toBe ( 'visible' ) ;
10475 expect ( toast . autoHide ) . toBeFalsy ( ) ;
10576
10677 tick ( 1000 ) ;
10778
10879 expect ( toast . isVisible ) . toBeTruthy ( ) ;
109- expect ( toast . animationState ) . toBe ( 'visible' ) ;
11080 } ) ) ;
11181
11282 it ( 'visibility is updated by the toggle() method' , ( ) => {
@@ -117,7 +87,6 @@ describe('IgxToast', () => {
11787
11888 toast . show ( ) ;
11989 expect ( toast . isVisible ) . toBe ( true ) ;
120- expect ( toast . animationState ) . toBe ( 'visible' ) ;
12190
12291 expect ( toast . onShowing . emit ) . toHaveBeenCalledTimes ( 1 ) ;
12392 expect ( toast . onShown . emit ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -126,7 +95,6 @@ describe('IgxToast', () => {
12695
12796 toast . toggle ( ) ;
12897 expect ( toast . isVisible ) . toBe ( false ) ;
129- expect ( toast . animationState ) . toBe ( 'invisible' ) ;
13098
13199 expect ( toast . onShowing . emit ) . toHaveBeenCalledTimes ( 1 ) ;
132100 expect ( toast . onShown . emit ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -143,15 +111,13 @@ describe('IgxToast', () => {
143111 fixture . detectChanges ( ) ;
144112
145113 expect ( toast . isVisible ) . toBeTruthy ( ) ;
146- expect ( toast . animationState ) . toBe ( 'visible' ) ;
147114 expect ( toast . autoHide ) . toBeFalsy ( ) ;
148115 expect ( toast . toastMessage ) . toBe ( 'Custom Message' ) ;
149- expect ( fixture . nativeElement . querySelector ( 'igx-toast:first-child' ) . innerText ) . toBe ( 'Custom Message' ) ;
150116 } ) ) ;
151117} ) ;
152118
153119@Component ( {
154- template : `<igx-toast #toast></igx-toast>`
120+ template : `<igx-toast #toast></igx-toast>` ,
155121} )
156122class ToastInitializeTestComponent {
157123 @ViewChild ( IgxToastComponent , { static : true } )
0 commit comments