Skip to content

Commit 06b4b04

Browse files
committed
enable toast content and edit tests
1 parent ac1b086 commit 06b4b04

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<span>{{ message }}</span>
1+
<div #content><ng-content></ng-content></div>
2+
<span *ngIf="content.children.length == 0">{{ message }}</span>
3+

projects/igniteui-angular/src/lib/toast/toast.component.spec.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {async, TestBed, fakeAsync, tick} from '@angular/core/testing';
33
import {By} from '@angular/platform-browser';
44
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
55
import {IgxToastComponent, IgxToastModule, IgxToastPosition} from './toast.component';
6-
76
import { configureTestSuite } from '../test-utils/configure-suite';
87
import { 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({

projects/igniteui-angular/src/lib/toast/toast.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Output
1414
} from '@angular/core';
1515
import { IgxNavigationService, IToggleView } from '../core/navigation';
16+
import { DeprecateProperty } from '../core/deprecateDecorators';
1617

1718
let NEXT_ID = 0;
1819
/**
@@ -187,6 +188,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
187188
public isVisibleChange = new EventEmitter<boolean>();
188189

189190
/**
191+
* @deprecated Place your message in the toast content instead.
190192
* Sets/gets the message that will be shown by the toast.
191193
* ```html
192194
* <igx-toast [message] = "Notification"></igx-toast>
@@ -196,8 +198,9 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
196198
* ```
197199
* @memberof IgxToastComponent
198200
*/
201+
@DeprecateProperty(`'message' @Input property is deprecated. Place your message in the toast content instead.`)
199202
@Input()
200-
public message: string;
203+
public message = '';
201204

202205
/**
203206
* Sets/gets the position of the toast.

src/app/toast/toast.sample.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ <h4 class="sample-title">Top Position</h4>
2929
</article>
3030
</section>
3131

32-
<igx-toast #toast message="This message will self-destruct in 4 seconds." [position]="toastPosition">
32+
<igx-toast #toast [position]="toastPosition">
33+
This message will self-destruct in 4 seconds.
3334
</igx-toast>
3435
</div>

0 commit comments

Comments
 (0)