Skip to content

Commit daf06d8

Browse files
committed
test(toast): update spec
1 parent 06b4b04 commit daf06d8

File tree

3 files changed

+31
-42
lines changed

3 files changed

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

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {Component, ViewChild} from '@angular/core';
2-
import {async, TestBed, fakeAsync, tick} from '@angular/core/testing';
1+
import {Component, ViewChild, ElementRef} from '@angular/core';
2+
import {async, TestBed, fakeAsync, tick, ComponentFixture} 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';
66
import { configureTestSuite } from '../test-utils/configure-suite';
7-
import { wait } from '../test-utils/ui-interactions.spec';
87

98
describe('IgxToast', () => {
109
configureTestSuite();
@@ -19,23 +18,25 @@ describe('IgxToast', () => {
1918
]
2019
}).compileComponents();
2120
}));
22-
const baseClass = 'igx-toast';
2321

22+
const baseClass = 'igx-toast';
2423
const classes = {
2524
top: `${baseClass}--top`,
2625
middle: `${baseClass}--middle`,
2726
bottom: `${baseClass}--bottom`,
2827
};
29-
let fixture, toast, element;
28+
29+
let fixture: ComponentFixture<ToastInitializeTestComponent>;
30+
let toast: IgxToastComponent;
31+
3032
beforeEach(() => {
3133
fixture = TestBed.createComponent(ToastInitializeTestComponent);
3234
toast = fixture.componentInstance.toast;
3335
toast.isVisible = true;
3436
fixture.detectChanges();
35-
element = fixture.debugElement.query(By.css('.igx-toast--bottom'));
3637
});
3738

38-
it('should properly initialize properties', () => {
39+
it('should properly initialize', () => {
3940
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
4041
expect(toast.id).toContain('igx-toast-');
4142
expect(domToast.id).toContain('igx-toast-');
@@ -56,7 +57,6 @@ describe('IgxToast', () => {
5657
fixture.detectChanges();
5758
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
5859

59-
element = fixture.debugElement.query(By.css('.igx-toast--middle'));
6060
expect(domToast.classList).toContain(classes.middle);
6161
});
6262

@@ -65,11 +65,10 @@ describe('IgxToast', () => {
6565
fixture.detectChanges();
6666
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
6767

68-
element = fixture.debugElement.query(By.css('.igx-toast--top'));
6968
expect(domToast.classList).toContain(classes.top);
7069
});
7170

72-
it('should change toast position to bottom, the rest should be undefined', () => {
71+
it('should change toast position to bottom', () => {
7372
toast.position = IgxToastPosition.Bottom;
7473
fixture.detectChanges();
7574
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
@@ -79,7 +78,7 @@ describe('IgxToast', () => {
7978
expect(domToast.classList).toContain(classes.bottom);
8079
});
8180

82-
it('should auto hide 1 second after is open', fakeAsync(() => {
81+
it('should auto hide 1 second after it\'s open', fakeAsync(() => {
8382
toast.displayTime = 1000;
8483

8584
toast.show();
@@ -89,12 +88,12 @@ describe('IgxToast', () => {
8988
expect(toast.autoHide).toBeTruthy();
9089

9190
tick(1000);
92-
fixture.detectChanges();
91+
9392
expect(toast.isVisible).toBeFalsy();
9493
expect(toast._animationState).toBe('invisible');
9594
}));
9695

97-
it('should not auto hide seconds after is open', fakeAsync(() => {
96+
it('should not auto hide after it\'s open', fakeAsync(() => {
9897
toast.displayTime = 1000;
9998
toast.autoHide = false;
10099

@@ -105,52 +104,41 @@ describe('IgxToast', () => {
105104
expect(toast.autoHide).toBeFalsy();
106105

107106
tick(1000);
108-
fixture.detectChanges();
107+
109108
expect(toast.isVisible).toBeTruthy();
110109
expect(toast._animationState).toBe('visible');
111110
}));
112111

113-
it('visibility is properly toggled by its toggle() method.', (async() => {
112+
it('visibility is updated by the toggle() method', () => {
114113
spyOn(toast.onShowing, 'emit');
115114
spyOn(toast.onShown, 'emit');
116115
spyOn(toast.onHiding, 'emit');
117116
spyOn(toast.onHidden, 'emit');
118117

118+
toast.show();
119119
expect(toast.isVisible).toBe(true);
120-
// expect(toast._animationState).toBe('visible');
121-
toast.toggle();
122-
await wait();
123-
fixture.detectChanges();
120+
expect(toast._animationState).toBe('visible');
124121

125-
expect(toast.isVisible).toBe(false);
126-
expect(toast._animationState).toBe('invisible');
127-
expect(toast.onShowing.emit).toHaveBeenCalledTimes(0);
128-
expect(toast.onShown.emit).toHaveBeenCalledTimes(0);
129-
expect(toast.onHiding.emit).toHaveBeenCalledTimes(1);
130-
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);
131126

132127
toast.toggle();
133-
await wait();
134-
fixture.detectChanges();
128+
expect(toast.isVisible).toBe(false);
129+
expect(toast._animationState).toBe('invisible');
135130

136-
expect(toast.isVisible).toBe(true);
137-
expect(toast._animationState).toBe('visible');
138131
expect(toast.onShowing.emit).toHaveBeenCalledTimes(1);
139132
expect(toast.onShown.emit).toHaveBeenCalledTimes(1);
140133
expect(toast.onHiding.emit).toHaveBeenCalledTimes(1);
141134
expect(toast.onHidden.emit).toHaveBeenCalledTimes(1);
142-
143-
toast.toggle();
144-
await wait();
145-
fixture.detectChanges();
146-
expect(toast.isVisible).toBe(false);
147-
expect(toast._animationState).toBe('invisible');
148-
}));
135+
});
149136
});
137+
150138
@Component({
151-
template: `<igx-toast #toast>
152-
</igx-toast>`
139+
template: `<igx-toast #toast></igx-toast>`
153140
})
154141
class ToastInitializeTestComponent {
155-
@ViewChild(IgxToastComponent, { static: true }) public toast: IgxToastComponent;
142+
@ViewChild(IgxToastComponent, { static: true })
143+
public toast: IgxToastComponent;
156144
}

src/app/toast/toast.sample.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ <h4 class="sample-title">Middle Position</h4>
2323
<h4 class="sample-title">Top Position</h4>
2424
<div class="preview top"></div>
2525
<div class="btn-group">
26-
<button igxButton="raised" igxRipple="white" (click)="showToast(toast, 'top')" [disabled]="toast.isVisible">Show Toast</button>
27-
<button igxButton="raised" igxRipple="white" (click)="toast.hide()" [disabled]="!toast.isVisible">Hide Toast</button>
26+
<button igxButton="raised" igxRipple="white" (click)="toast.toggle()">Toggle Toast</button>
2827
</div>
2928
</article>
3029
</section>

0 commit comments

Comments
 (0)