From 1db97508cc3834315b4a098c637895a862489527 Mon Sep 17 00:00:00 2001
From: "Lisa Flinn (She/Her)"
Date: Thu, 2 May 2024 14:29:22 +0100
Subject: [PATCH] added unit test
revert back to original files
---
.../dynamicdialog/dynamicdialog.spec.ts | 57 +++++++++++++++++--
.../showcase/doc/dynamicdialog/exampledoc.ts | 55 +++++++++++-------
2 files changed, 85 insertions(+), 27 deletions(-)
diff --git a/src/app/components/dynamicdialog/dynamicdialog.spec.ts b/src/app/components/dynamicdialog/dynamicdialog.spec.ts
index 6db4d25ac55..3d96af97f8b 100755
--- a/src/app/components/dynamicdialog/dynamicdialog.spec.ts
+++ b/src/app/components/dynamicdialog/dynamicdialog.spec.ts
@@ -31,6 +31,24 @@ export class TestDynamicDialogComponent {
});
}
}
+@Component({
+ template: ` `
+})
+export class TestDynamicDialogWithClosableFalseComponent {
+ constructor(public dialogService: DialogService) {}
+
+ show() {
+ this.dialogService.open(TestComponent, {
+ header: 'Demo Header',
+ width: '70%',
+ contentStyle: { 'max-height': '350px', overflow: 'auto' },
+ closable: false,
+ closeOnEscape: true,
+ dismissableMask: true,
+ baseZIndex: 0
+ });
+ }
+}
@NgModule({
imports: [CommonModule, DynamicDialogModule],
declarations: [TestComponent, TestDynamicDialogComponent],
@@ -39,20 +57,20 @@ export class TestDynamicDialogComponent {
})
export class FakeTestDialogModule {}
-describe('DynamicDialog', () => {
- let fixture: ComponentFixture;
- let testDynamicDialogComponent: TestDynamicDialogComponent;
-
+fdescribe('DynamicDialog', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, FakeTestDialogModule],
declarations: [Footer]
});
- fixture = TestBed.createComponent(TestDynamicDialogComponent);
- testDynamicDialogComponent = fixture.debugElement.componentInstance;
});
it('should open dialog and close dialog', fakeAsync(() => {
+ let fixture: ComponentFixture;
+ let testDynamicDialogComponent: TestDynamicDialogComponent;
+
+ fixture = TestBed.createComponent(TestDynamicDialogComponent);
+ testDynamicDialogComponent = fixture.debugElement.componentInstance;
fixture.detectChanges();
testDynamicDialogComponent.show();
@@ -74,4 +92,31 @@ describe('DynamicDialog', () => {
expect(dynamicDialogEl).toBeUndefined();
flush();
}));
+
+ it('should open dialog and close dialog without the closing icon enabled', fakeAsync(() => {
+ let fixture: ComponentFixture;
+ let testDynamicDialogComponent: TestDynamicDialogWithClosableFalseComponent;
+ fixture = TestBed.createComponent(TestDynamicDialogComponent);
+ testDynamicDialogComponent = fixture.debugElement.componentInstance;
+ fixture.detectChanges();
+
+ testDynamicDialogComponent.show();
+ fixture.detectChanges();
+ tick(300);
+
+ let dynamicDialogEl = document.getElementsByClassName('p-dynamic-dialog')[0];
+ expect(dynamicDialogEl).toBeTruthy();
+ const titleEl = dynamicDialogEl.getElementsByClassName('p-dialog-title')[0];
+ const testComponentHeader = dynamicDialogEl.getElementsByTagName('h2')[0];
+ expect(titleEl.textContent).toEqual('Demo Header');
+ expect(testComponentHeader.textContent).toEqual('PrimeNG ROCKS!');
+ const backdropEl = document.getElementsByClassName('p-dialog-mask')[0];
+ backdropEl.dispatchEvent(new Event('mousedown'));
+ fixture.detectChanges();
+ tick(700);
+
+ dynamicDialogEl = document.getElementsByClassName('p-dynamic-dialog')[0];
+ expect(dynamicDialogEl).toBeUndefined();
+ flush();
+ }));
});
diff --git a/src/app/showcase/doc/dynamicdialog/exampledoc.ts b/src/app/showcase/doc/dynamicdialog/exampledoc.ts
index a23c78198ae..67e6c96745d 100644
--- a/src/app/showcase/doc/dynamicdialog/exampledoc.ts
+++ b/src/app/showcase/doc/dynamicdialog/exampledoc.ts
@@ -1,7 +1,7 @@
import { Component, OnDestroy } from '@angular/core';
import { MessageService } from 'primeng/api';
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
-import { Code } from '../../domain/code';
+import { Code } from '@domain/code';
import { ProductListDemo } from './productlistdemo';
import { Footer } from './footer';
@@ -15,8 +15,8 @@ import { Footer } from './footer';
-
-
+ html: `
`,
- typescript: `
-import { Component, OnDestroy } from '@angular/core';
+ typescript: `import { Component, OnDestroy } from '@angular/core';
import { MessageService } from 'primeng/api';
-import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
-import { Product } from '../../domain/product';
-import { ProductListDemo } from './productlistdemo';
-import { Footer } from './footer';
+import { DialogService, DynamicDialogModule, DynamicDialogRef } from 'primeng/dynamicdialog';
+import { ProductListDemo } from './demo/productlistdemo';
+import { Footer } from './demo/footer';
+import { ToastModule } from 'primeng/toast';
+import { ButtonModule } from 'primeng/button';
@Component({
selector: 'dynamic-dialog-example-demo',
templateUrl: './dynamic-dialog-example-demo.html',
- providers: [DialogService, MessageService]
+ imports: [DynamicDialogModule, ToastModule, ButtonModule],
+ providers: [DialogService, MessageService],
+ standalone: true,
})
export class DynamicDialogExampleDemo implements OnDestroy {
@@ -156,13 +157,18 @@ export interface Product {
path: 'src/app/demo/productlistdemo.ts',
name: 'ProductListDemo',
content: `import { Component, OnInit } from '@angular/core';
-import { Product } from '../../domain/product';
-import { ProductService } from '../../service/productservice';
+import { Product } from '@domain/product';
+import { ProductService } from '@service/productservice';
import { MessageService } from 'primeng/api';
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
import { InfoDemo } from './infodemo';
+import { TableModule } from 'primeng/table'
+import { ButtonModule } from 'primeng/button';
+
@Component({
providers: [DialogService, MessageService, ProductService],
+ standalone:true,
+ imports:[TableModule, ButtonModule],
template: \`
@@ -187,7 +193,7 @@ import { InfoDemo } from './infodemo';
{{ product.quantity }}
-
+
|
@@ -239,14 +245,18 @@ export class ProductListDemo implements OnInit {
content: `import { Component} from '@angular/core';
import { DialogService, DynamicDialogComponent, DynamicDialogRef } from 'primeng/dynamicdialog';
import { MessageService } from 'primeng/api';
+import { ButtonModule } from 'primeng/button';
+
@Component({
providers: [DialogService, MessageService],
+ standalone: true,
+ imports:[ButtonModule],
template: \`
There are {{ totalProducts }} products in total in this list.
\`
})
@@ -281,12 +291,15 @@ export class InfoDemo {
name: 'Footer',
content: `import { Component } from '@angular/core';
import { DynamicDialogRef } from 'primeng/dynamicdialog';
+import { ButtonModule } from 'primeng/button';
@Component({
selector: 'footer',
+ standalone: true,
+ imports: [ButtonModule],
template: \`
\`
})
export class Footer {