1- import { Component , ViewChild } from '@angular/core' ;
2- import { async , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
1+ import { Component , ViewChild } from '@angular/core' ;
2+ import { async , TestBed , fakeAsync , tick , ComponentFixture } from '@angular/core/testing' ;
33import { By } from '@angular/platform-browser' ;
44import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
55import { IgxToastComponent , IgxToastModule , IgxToastPosition } from './toast.component' ;
6-
76import { configureTestSuite } from '../test-utils/configure-suite' ;
8- import { wait } from '../test-utils/ui-interactions.spec' ;
97
108describe ( 'IgxToast' , ( ) => {
119 configureTestSuite ( ) ;
@@ -20,24 +18,32 @@ describe('IgxToast', () => {
2018 ]
2119 } ) . compileComponents ( ) ;
2220 } ) ) ;
23- let fixture , toast , element ;
21+
22+ const baseClass = 'igx-toast' ;
23+ const classes = {
24+ top : `${ baseClass } --top` ,
25+ middle : `${ baseClass } --middle` ,
26+ bottom : `${ baseClass } --bottom` ,
27+ } ;
28+
29+ let fixture : ComponentFixture < ToastInitializeTestComponent > ;
30+ let toast : IgxToastComponent ;
31+
2432 beforeEach ( ( ) => {
2533 fixture = TestBed . createComponent ( ToastInitializeTestComponent ) ;
2634 toast = fixture . componentInstance . toast ;
2735 toast . isVisible = true ;
2836 fixture . detectChanges ( ) ;
29- element = fixture . debugElement . query ( By . css ( '.igx-toast--bottom' ) ) ;
3037 } ) ;
3138
32- it ( 'should properly initialize properties ' , ( ) => {
33- const domToast = fixture . debugElement . query ( By . css ( 'igx-toast' ) ) . nativeElement ;
39+ it ( 'should properly initialize' , ( ) => {
40+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
3441 expect ( toast . id ) . toContain ( 'igx-toast-' ) ;
3542 expect ( domToast . id ) . toContain ( 'igx-toast-' ) ;
36- expect ( toast . message ) . toBeUndefined ( ) ;
3743 expect ( toast . displayTime ) . toBe ( 4000 ) ;
3844 expect ( toast . autoHide ) . toBeTruthy ( ) ;
3945 expect ( toast . isVisible ) . toBeTruthy ( ) ;
40- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_BOTTOM ] ) . toBeTruthy ( ) ;
46+ expect ( domToast . classList ) . toContain ( classes . bottom ) ;
4147
4248 toast . id = 'customToast' ;
4349 fixture . detectChanges ( ) ;
@@ -49,92 +55,91 @@ describe('IgxToast', () => {
4955 it ( 'should change toast position to middle' , ( ) => {
5056 toast . position = IgxToastPosition . Middle ;
5157 fixture . detectChanges ( ) ;
58+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
5259
53- element = fixture . debugElement . query ( By . css ( '.igx-toast--middle' ) ) ;
54- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_MIDDLE ] ) . toBeTruthy ( ) ;
60+ expect ( domToast . classList ) . toContain ( classes . middle ) ;
5561 } ) ;
5662
5763 it ( 'should change toast position to top' , ( ) => {
5864 toast . position = IgxToastPosition . Top ;
5965 fixture . detectChanges ( ) ;
66+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
6067
61- element = fixture . debugElement . query ( By . css ( '.igx-toast--top' ) ) ;
62- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_TOP ] ) . toBeTruthy ( ) ;
68+ expect ( domToast . classList ) . toContain ( classes . top ) ;
6369 } ) ;
6470
65- it ( 'should change toast position to bottom, the rest should be undefined ' , ( ) => {
71+ it ( 'should change toast position to bottom' , ( ) => {
6672 toast . position = IgxToastPosition . Bottom ;
6773 fixture . detectChanges ( ) ;
74+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
6875
69- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_TOP ] ) . toBeUndefined ( ) ;
70- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_MIDDLE ] ) . toBeUndefined ( ) ;
71- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_BOTTOM ] ) . toBe ( true ) ;
76+ expect ( domToast . classList ) . not . toContain ( classes . top ) ;
77+ expect ( domToast . classList ) . not . toContain ( classes . middle ) ;
78+ expect ( domToast . classList ) . toContain ( classes . bottom ) ;
7279 } ) ;
7380
74- it ( 'should auto hide 1 second after is open' , fakeAsync ( ( ) => {
81+ it ( 'should auto hide 1 second after it\'s open' , fakeAsync ( ( ) => {
7582 toast . displayTime = 1000 ;
7683
7784 toast . show ( ) ;
7885
7986 expect ( toast . isVisible ) . toBeTruthy ( ) ;
87+ expect ( toast . animationState ) . toBe ( 'visible' ) ;
8088 expect ( toast . autoHide ) . toBeTruthy ( ) ;
8189
8290 tick ( 1000 ) ;
83- fixture . detectChanges ( ) ;
91+
8492 expect ( toast . isVisible ) . toBeFalsy ( ) ;
93+ expect ( toast . animationState ) . toBe ( 'invisible' ) ;
8594 } ) ) ;
8695
87- it ( 'should not auto hide seconds after is open' , fakeAsync ( ( ) => {
96+ it ( 'should not auto hide after it\'s open' , fakeAsync ( ( ) => {
8897 toast . displayTime = 1000 ;
8998 toast . autoHide = false ;
9099
91100 toast . show ( ) ;
92101
93102 expect ( toast . isVisible ) . toBeTruthy ( ) ;
103+ expect ( toast . animationState ) . toBe ( 'visible' ) ;
94104 expect ( toast . autoHide ) . toBeFalsy ( ) ;
95105
96106 tick ( 1000 ) ;
97- fixture . detectChanges ( ) ;
107+
98108 expect ( toast . isVisible ) . toBeTruthy ( ) ;
109+ expect ( toast . animationState ) . toBe ( 'visible' ) ;
99110 } ) ) ;
100111
101- it ( 'visibility is properly toggled by its toggle() method. ' , ( async ( ) => {
112+ it ( 'visibility is updated by the toggle() method' , ( ) => {
102113 spyOn ( toast . onShowing , 'emit' ) ;
103114 spyOn ( toast . onShown , 'emit' ) ;
104115 spyOn ( toast . onHiding , 'emit' ) ;
105116 spyOn ( toast . onHidden , 'emit' ) ;
106117
118+ toast . show ( ) ;
107119 expect ( toast . isVisible ) . toBe ( true ) ;
108- toast . toggle ( ) ;
109- await wait ( ) ;
110- fixture . detectChanges ( ) ;
120+ expect ( toast . animationState ) . toBe ( 'visible' ) ;
111121
112- expect ( toast . isVisible ) . toBe ( false ) ;
113- expect ( toast . onShowing . emit ) . toHaveBeenCalledTimes ( 0 ) ;
114- expect ( toast . onShown . emit ) . toHaveBeenCalledTimes ( 0 ) ;
115- expect ( toast . onHiding . emit ) . toHaveBeenCalledTimes ( 1 ) ;
116- expect ( toast . onHidden . emit ) . toHaveBeenCalledTimes ( 1 ) ;
122+ expect ( toast . onShowing . emit ) . toHaveBeenCalledTimes ( 1 ) ;
123+ expect ( toast . onShown . emit ) . toHaveBeenCalledTimes ( 1 ) ;
124+ expect ( toast . onHiding . emit ) . toHaveBeenCalledTimes ( 0 ) ;
125+ expect ( toast . onHidden . emit ) . toHaveBeenCalledTimes ( 0 ) ;
117126
118127 toast . toggle ( ) ;
119- await wait ( ) ;
120- fixture . detectChanges ( ) ;
128+ expect ( toast . isVisible ) . toBe ( false ) ;
129+ expect ( toast . animationState ) . toBe ( 'invisible' ) ;
121130
122- expect ( toast . isVisible ) . toBe ( true ) ;
123131 expect ( toast . onShowing . emit ) . toHaveBeenCalledTimes ( 1 ) ;
124132 expect ( toast . onShown . emit ) . toHaveBeenCalledTimes ( 1 ) ;
125133 expect ( toast . onHiding . emit ) . toHaveBeenCalledTimes ( 1 ) ;
126134 expect ( toast . onHidden . emit ) . toHaveBeenCalledTimes ( 1 ) ;
127135
128- toast . toggle ( ) ;
129- await wait ( ) ;
130- fixture . detectChanges ( ) ;
131- expect ( toast . isVisible ) . toBe ( false ) ;
132- } ) ) ;
136+ } ) ;
133137} ) ;
138+
134139@Component ( {
135- template : `<igx-toast #toast>
136- </igx-toast>`
140+ template : `<igx-toast #toast></igx-toast>`
137141} )
138142class ToastInitializeTestComponent {
139- @ViewChild ( IgxToastComponent , { static : true } ) public toast : IgxToastComponent ;
143+ @ViewChild ( IgxToastComponent , { static : true } )
144+ public toast : IgxToastComponent ;
140145}
0 commit comments