@@ -3,7 +3,6 @@ import {async, TestBed, fakeAsync, tick} 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' ;
87import { wait } from '../test-utils/ui-interactions.spec' ;
98
@@ -20,6 +19,13 @@ describe('IgxToast', () => {
2019 ]
2120 } ) . compileComponents ( ) ;
2221 } ) ) ;
22+ const baseClass = 'igx-toast' ;
23+
24+ const classes = {
25+ top : `${ baseClass } --top` ,
26+ middle : `${ baseClass } --middle` ,
27+ bottom : `${ baseClass } --bottom` ,
28+ } ;
2329 let fixture , toast , element ;
2430 beforeEach ( ( ) => {
2531 fixture = TestBed . createComponent ( ToastInitializeTestComponent ) ;
@@ -30,14 +36,13 @@ describe('IgxToast', () => {
3036 } ) ;
3137
3238 it ( 'should properly initialize properties' , ( ) => {
33- const domToast = fixture . debugElement . query ( By . css ( 'igx-toast' ) ) . nativeElement ;
39+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
3440 expect ( toast . id ) . toContain ( 'igx-toast-' ) ;
3541 expect ( domToast . id ) . toContain ( 'igx-toast-' ) ;
36- expect ( toast . message ) . toBeUndefined ( ) ;
3742 expect ( toast . displayTime ) . toBe ( 4000 ) ;
3843 expect ( toast . autoHide ) . toBeTruthy ( ) ;
3944 expect ( toast . isVisible ) . toBeTruthy ( ) ;
40- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_BOTTOM ] ) . toBeTruthy ( ) ;
45+ expect ( domToast . classList ) . toContain ( classes . bottom ) ;
4146
4247 toast . id = 'customToast' ;
4348 fixture . detectChanges ( ) ;
@@ -49,26 +54,29 @@ describe('IgxToast', () => {
4954 it ( 'should change toast position to middle' , ( ) => {
5055 toast . position = IgxToastPosition . Middle ;
5156 fixture . detectChanges ( ) ;
57+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
5258
5359 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
6168 element = fixture . debugElement . query ( By . css ( '.igx-toast--top' ) ) ;
62- expect ( element . classes [ toast . CSS_CLASSES . IGX_TOAST_TOP ] ) . toBeTruthy ( ) ;
69+ expect ( domToast . classList ) . toContain ( classes . top ) ;
6370 } ) ;
6471
6572 it ( 'should change toast position to bottom, the rest should be undefined' , ( ) => {
6673 toast . position = IgxToastPosition . Bottom ;
6774 fixture . detectChanges ( ) ;
75+ const domToast = fixture . debugElement . query ( By . css ( baseClass ) ) . nativeElement ;
6876
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 ) ;
77+ expect ( domToast . classList ) . not . toContain ( classes . top ) ;
78+ expect ( domToast . classList ) . not . toContain ( classes . middle ) ;
79+ expect ( domToast . classList ) . toContain ( classes . bottom ) ;
7280 } ) ;
7381
7482 it ( 'should auto hide 1 second after is open' , fakeAsync ( ( ) => {
@@ -77,11 +85,13 @@ describe('IgxToast', () => {
7785 toast . show ( ) ;
7886
7987 expect ( toast . isVisible ) . toBeTruthy ( ) ;
88+ expect ( toast . _animationState ) . toBe ( 'visible' ) ;
8089 expect ( toast . autoHide ) . toBeTruthy ( ) ;
8190
8291 tick ( 1000 ) ;
8392 fixture . detectChanges ( ) ;
8493 expect ( toast . isVisible ) . toBeFalsy ( ) ;
94+ expect ( toast . _animationState ) . toBe ( 'invisible' ) ;
8595 } ) ) ;
8696
8797 it ( 'should not auto hide seconds after is open' , fakeAsync ( ( ) => {
@@ -91,11 +101,13 @@ describe('IgxToast', () => {
91101 toast . show ( ) ;
92102
93103 expect ( toast . isVisible ) . toBeTruthy ( ) ;
104+ expect ( toast . _animationState ) . toBe ( 'visible' ) ;
94105 expect ( toast . autoHide ) . toBeFalsy ( ) ;
95106
96107 tick ( 1000 ) ;
97108 fixture . detectChanges ( ) ;
98109 expect ( toast . isVisible ) . toBeTruthy ( ) ;
110+ expect ( toast . _animationState ) . toBe ( 'visible' ) ;
99111 } ) ) ;
100112
101113 it ( 'visibility is properly toggled by its toggle() method.' , ( async ( ) => {
@@ -105,11 +117,13 @@ describe('IgxToast', () => {
105117 spyOn ( toast . onHidden , 'emit' ) ;
106118
107119 expect ( toast . isVisible ) . toBe ( true ) ;
120+ // expect(toast._animationState).toBe('visible');
108121 toast . toggle ( ) ;
109122 await wait ( ) ;
110123 fixture . detectChanges ( ) ;
111124
112125 expect ( toast . isVisible ) . toBe ( false ) ;
126+ expect ( toast . _animationState ) . toBe ( 'invisible' ) ;
113127 expect ( toast . onShowing . emit ) . toHaveBeenCalledTimes ( 0 ) ;
114128 expect ( toast . onShown . emit ) . toHaveBeenCalledTimes ( 0 ) ;
115129 expect ( toast . onHiding . emit ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -120,6 +134,7 @@ describe('IgxToast', () => {
120134 fixture . detectChanges ( ) ;
121135
122136 expect ( toast . isVisible ) . toBe ( true ) ;
137+ expect ( toast . _animationState ) . toBe ( 'visible' ) ;
123138 expect ( toast . onShowing . emit ) . toHaveBeenCalledTimes ( 1 ) ;
124139 expect ( toast . onShown . emit ) . toHaveBeenCalledTimes ( 1 ) ;
125140 expect ( toast . onHiding . emit ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -129,6 +144,7 @@ describe('IgxToast', () => {
129144 await wait ( ) ;
130145 fixture . detectChanges ( ) ;
131146 expect ( toast . isVisible ) . toBe ( false ) ;
147+ expect ( toast . _animationState ) . toBe ( 'invisible' ) ;
132148 } ) ) ;
133149} ) ;
134150@Component ( {
0 commit comments