-
-
+
+
+
diff --git a/src/app/shared/modules/dialog/dialog.component.spec.ts b/src/app/shared/modules/dialog/dialog.component.spec.ts
index be6963d63e..58df1a7de8 100644
--- a/src/app/shared/modules/dialog/dialog.component.spec.ts
+++ b/src/app/shared/modules/dialog/dialog.component.spec.ts
@@ -4,9 +4,11 @@ import { DialogComponent } from "./dialog.component";
import { MockMatDialogRef, MockMatDialogData } from "shared/MockStubs";
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
import { SharedScicatFrontendModule } from "shared/shared.module";
+
describe("DialogComponent", () => {
let component: DialogComponent;
let fixture: ComponentFixture
;
+ let dialogRef: MatDialogRef;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
@@ -22,10 +24,46 @@ describe("DialogComponent", () => {
beforeEach(() => {
fixture = TestBed.createComponent(DialogComponent);
component = fixture.componentInstance;
+ dialogRef = TestBed.inject(MatDialogRef);
fixture.detectChanges();
});
it("should create", () => {
expect(component).toBeTruthy();
});
+
+ it("should close the dialog when cancelling", () => {
+ const closeSpy = spyOn(dialogRef, "close");
+
+ component.onNoClick();
+
+ expect(closeSpy).toHaveBeenCalledTimes(1);
+ });
+
+ it("should render dynamic additional fields and disable submit when required data is missing", () => {
+ component.data = {
+ title: "Mark for deletion reason",
+ additionalFields: {
+ deletiionCode: {
+ label: "Deletion code",
+ type: "select",
+ required: true,
+ options: [{ option: "MARKED_FOR_DELETION" }],
+ },
+ explanation: {
+ label: "Explanation for deletion",
+ type: "textarea",
+ required: true,
+ },
+ },
+ };
+
+ fixture.detectChanges();
+
+ const compiled = fixture.debugElement.nativeElement;
+
+ expect(compiled.textContent).toContain("Deletion code");
+ expect(compiled.textContent).toContain("Explanation for deletion");
+ expect(compiled.querySelector("textarea")).toBeTruthy();
+ });
});
diff --git a/src/app/shared/modules/dialog/dialog.component.ts b/src/app/shared/modules/dialog/dialog.component.ts
index 935de919ac..df754fa59d 100644
--- a/src/app/shared/modules/dialog/dialog.component.ts
+++ b/src/app/shared/modules/dialog/dialog.component.ts
@@ -1,6 +1,29 @@
import { Component, Inject } from "@angular/core";
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
+export interface DialogOptionData {
+ option: string;
+ tooltip?: string;
+}
+
+export interface DynamicField {
+ label: string;
+ type: "text" | "textarea" | "select";
+ required?: boolean;
+ options?: DialogOptionData[];
+}
+
+export interface DynamicDialogData {
+ title: string;
+ label?: string;
+ question?: string;
+ choice?: {
+ options: DialogOptionData[];
+ };
+ additionalFields?: { [key: string]: DynamicField };
+ [key: string]: any;
+}
+
@Component({
selector: "app-dialog",
templateUrl: "./dialog.component.html",
@@ -10,7 +33,7 @@ import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
export class DialogComponent {
constructor(
public dialogRef: MatDialogRef,
- @Inject(MAT_DIALOG_DATA) public data: any,
+ @Inject(MAT_DIALOG_DATA) public data: DynamicDialogData,
) {}
onNoClick(): void {