Skip to content

Commit f14bacb

Browse files
committed
fix(dialog): Adding tests #5576
1 parent 8f38ea1 commit f14bacb

File tree

4 files changed

+132
-6
lines changed

4 files changed

+132
-6
lines changed

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

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import { Component, DebugElement, ElementRef, ViewChild } from '@angular/core';
2-
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
1+
import { Component, ViewChild } from '@angular/core';
2+
import { async, TestBed, fakeAsync, tick } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
66
import { IDialogEventArgs, IgxDialogComponent, IgxDialogModule } from './dialog.component';
77
import { configureTestSuite } from '../test-utils/configure-suite';
8+
import { PositionSettings, slideInTop, slideOutBottom, HorizontalAlignment, VerticalAlignment } from 'igniteui-angular';
9+
import { useAnimation } from '@angular/animations';
810

911
const OVERLAY_MAIN_CLASS = 'igx-overlay';
1012
const OVERLAY_WRAPPER_CLASS = `${OVERLAY_MAIN_CLASS}__wrapper`;
1113
const OVERLAY_MODAL_WRAPPER_CLASS = `${OVERLAY_WRAPPER_CLASS}--modal`;
14+
const CLASS_OVERLAY_CONTENT_MODAL = `${OVERLAY_MAIN_CLASS}__content--modal`;
1215

1316
describe('Dialog', () => {
1417
configureTestSuite();
@@ -21,7 +24,8 @@ describe('Dialog', () => {
2124
NestedDialogsComponent,
2225
CustomTemplates1DialogComponent,
2326
CustomTemplates2DialogComponent,
24-
DialogSampleComponent
27+
DialogSampleComponent,
28+
PositionSettingsDialogComponent
2529
],
2630
imports: [BrowserAnimationsModule, NoopAnimationsModule, IgxDialogModule]
2731
}).compileComponents();
@@ -322,6 +326,88 @@ describe('Dialog', () => {
322326
expect(dialog.isOpen).toEqual(false);
323327
}));
324328

329+
fdescribe('Position settings', () => {
330+
let fix;
331+
let dialog;
332+
let detect;
333+
const positionSettings: PositionSettings = {
334+
horizontalDirection: HorizontalAlignment.Center,
335+
verticalDirection: VerticalAlignment.Top
336+
};
337+
338+
beforeEach( fakeAsync(() => {
339+
fix = TestBed.createComponent(PositionSettingsDialogComponent);
340+
fix.detectChanges();
341+
dialog = fix.componentInstance.dialog;
342+
detect = () => dialog.cdr.detectChanges();
343+
}));
344+
345+
it('Define different position settings ', (async() => {
346+
dialog.open();
347+
fix.detectChanges();
348+
await wait(16);
349+
350+
expect(dialog.isOpen).toEqual(true);
351+
const firstContentRect = document.getElementsByClassName(CLASS_OVERLAY_CONTENT_MODAL)[0].getBoundingClientRect();
352+
const middleDialogPosition = document.documentElement.offsetHeight / 2 - firstContentRect.height / 2;
353+
expect(firstContentRect.left).toEqual(0, 'OffsetLeft position check');
354+
expect(firstContentRect.top).toBeGreaterThanOrEqual(middleDialogPosition - 2, 'OffsetTop position check');
355+
expect(firstContentRect.top).toBeLessThanOrEqual(middleDialogPosition + 2, 'OffsetTop position check');
356+
357+
dialog.close();
358+
fix.detectChanges();
359+
await wait(16);
360+
361+
expect(dialog.isOpen).toEqual(false);
362+
dialog.positionSettings = positionSettings;
363+
fix.detectChanges();
364+
await wait(16);
365+
366+
dialog.open();
367+
fix.detectChanges();
368+
await wait(16);
369+
370+
expect(dialog.isOpen).toEqual(true);
371+
const secondContentRect = document.getElementsByClassName(CLASS_OVERLAY_CONTENT_MODAL)[0].getBoundingClientRect();
372+
const topDialogPosition = document.documentElement.offsetWidth / 2 - secondContentRect.width / 2;
373+
expect(secondContentRect.top).toEqual(0, 'OffsetTop position check');
374+
expect(secondContentRect.left).toBeGreaterThanOrEqual(topDialogPosition - 2, 'OffsetLeft position check');
375+
expect(secondContentRect.left).toBeLessThanOrEqual(topDialogPosition + 2, 'OffsetLeft position check');
376+
377+
dialog.close();
378+
fix.detectChanges();
379+
await wait(16);
380+
381+
expect(dialog.isOpen).toEqual(false);
382+
}));
383+
384+
it('Set animation settings', (async() => {
385+
const currentElement = fix.componentInstance;
386+
dialog.positionSettings = currentElement.animationSettings;
387+
fix.detectChanges();
388+
await wait(16);
389+
390+
// Check the new animation settings
391+
expect(dialog.positionSettings.openAnimation.animation.type).toEqual(8, 'Animation type is set');
392+
expect(dialog.positionSettings.openAnimation.options.params.duration).toEqual('800ms', 'Animation duration is set to 800ms');
393+
394+
expect(dialog.positionSettings.closeAnimation.animation.type).toEqual(8, 'Animation type is set');
395+
expect(dialog.positionSettings.closeAnimation.options.params.duration).toEqual('700ms', 'Animation duration is set to 700ms');
396+
397+
dialog.open();
398+
fix.detectChanges();
399+
400+
await wait(16);
401+
expect(dialog.isOpen).toEqual(true);
402+
403+
dialog.close();
404+
fix.detectChanges();
405+
await wait(16);
406+
407+
expect(dialog.isOpen).toEqual(false);
408+
}));
409+
});
410+
325411
function dispatchEvent(element: HTMLElement, eventType: string) {
326412
const event = new Event(eventType);
327413
element.dispatchEvent(event);
@@ -436,3 +522,24 @@ class CustomTemplates1DialogComponent {
436522
class CustomTemplates2DialogComponent {
437523
@ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
438524
}
525+
526+
527+
@Component({
528+
template: `<igx-dialog #dialog title="Notification" message="Your email has been sent successfully!" leftButtonLabel="OK"
529+
[positionSettings]="positionSettings" >
530+
</igx-dialog>` })
531+
class PositionSettingsDialogComponent {
532+
@ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
533+
534+
public positionSettings: PositionSettings = {
535+
horizontalDirection: HorizontalAlignment.Left,
536+
verticalDirection: VerticalAlignment.Middle,
537+
horizontalStartPoint: HorizontalAlignment.Left,
538+
verticalStartPoint: VerticalAlignment.Middle
539+
};
540+
541+
public animationSettings: PositionSettings = {
542+
openAnimation: useAnimation(slideInTop, { params: { duration: '800ms' } }),
543+
closeAnimation: useAnimation(slideOutBottom, { params: { duration: '700ms'} })
544+
};
545+
}

src/app/dialog/dialog.sample.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@
1313
igx-input-group+igx-input-group {
1414
margin-top: 24px;
1515
}
16+
17+
.alertSection button {
18+
width: 140px;
19+
margin-right: 5px;
20+
}

src/app/dialog/dialog.sample.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
<h4 class="sample-title">Alert</h4>
66
<p class="sample-description">Detailed description to be added.</p>
77
<br>
8-
<button igxButton="raised" igxRipple (click)="alert.open()">Trigger Alert</button>
8+
<div class="alertSection">
9+
<button igxButton="raised" igxRipple (click)="alert.open()">Open Alert</button>
10+
<button igxButton="flat" (click)="togglePosition()">Toggle position</button>
11+
</div>
12+
913
<igx-dialog #alert title="Notification" message="Your email has been sent successfully!" leftButtonLabel="OK" (onLeftButtonSelect)="alert.close()"
1014
[positionSettings]="positionSettings" >
1115
</igx-dialog>

src/app/dialog/dialog.sample.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,28 @@ export class DialogSampleComponent implements OnInit {
2222
minSize: { height: 100, width: 100 }
2323
};
2424

25-
public positionSettings2: PositionSettings = {
25+
public newPositionSettings: PositionSettings = {
26+
horizontalDirection: HorizontalAlignment.Center,
27+
verticalDirection: VerticalAlignment.Middle,
28+
};
29+
30+
public newAnimationSettings: PositionSettings = {
2631
openAnimation: useAnimation(slideInTop),
2732
closeAnimation: useAnimation(slideOutBottom)
2833
};
2934

3035
public ngOnInit() {
3136
// Set position settings on ngOnInit
32-
// this.alert.positionSettings = this.positionSettings2;
37+
// this.alert.positionSettings = this.newAnimationSettings;
3338

3439
console.log(this.alert.positionSettings);
3540
}
3641

42+
togglePosition() {
43+
this.alert.positionSettings = this.alert.positionSettings === this.positionSettings ?
44+
this.newPositionSettings : this.positionSettings;
45+
}
46+
3747
onDialogOKSelected(args) {
3848
// args.event - event
3949
// args.dialog - dialog

0 commit comments

Comments
 (0)