CI: Migrate Sonar Scan job to GHA
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / services / ui / confirm-dialog.service.spec.ts
index 2cc241e..cb06ec1 100644 (file)
  * ========================LICENSE_END===================================
  */
 
-import { TestBed } from '@angular/core/testing';
+import { TestBed } from "@angular/core/testing";
 
-import { ConfirmDialogService } from './confirm-dialog.service';
-import { MatDialogModule } from '@angular/material';
-import {UiService} from './ui.service';
+import { ConfirmDialogService } from "./confirm-dialog.service";
+import { MatDialog, MatDialogModule } from "@angular/material/dialog";
+import { UiService } from "./ui.service";
+import { ConfirmDialogComponent } from "@app/ui/confirm-dialog/confirm-dialog.component";
+import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
 
-describe('ConfirmDialogService', () => {
-  beforeEach(() => TestBed.configureTestingModule({
-    imports: [ MatDialogModule ],
-    providers: [UiService]
-  }));
+describe("ConfirmDialogService", () => {
+  let matDialogSpy: jasmine.SpyObj<MatDialog>;
+  let service: ConfirmDialogService;
 
-  it('should be created', () => {
-    const service: ConfirmDialogService = TestBed.get(ConfirmDialogService);
+  beforeEach(() => {
+    matDialogSpy = jasmine.createSpyObj("MatDialog", ["open"]);
+
+    TestBed.configureTestingModule({
+      imports: [BrowserAnimationsModule, MatDialogModule],
+      providers: [
+        { provide: MatDialog, useValue: matDialogSpy },
+        UiService,
+      ],
+    });
+
+    service = TestBed.inject(ConfirmDialogService);
+  });
+
+  it("should be created", () => {
     expect(service).toBeTruthy();
   });
+
+  it("should open confirm dialog with correct dark mode and data", () => {
+    const uiService: UiService = TestBed.inject(UiService);
+    uiService.darkModeState.next(false);
+
+    service.openConfirmDialog("Heading", "Message");
+
+    expect(matDialogSpy.open).toHaveBeenCalledWith(ConfirmDialogComponent, {
+      panelClass: "",
+      width: "480px",
+      position: { top: "100px" },
+      data: {
+        heading: "Heading",
+        message: "Message",
+      },
+    });
+
+    uiService.darkModeState.next(true);
+
+    service.openConfirmDialog("Heading", "Message");
+
+    expect(matDialogSpy.open).toHaveBeenCalledWith(ConfirmDialogComponent, {
+      panelClass: "dark-theme",
+      width: "480px",
+      position: { top: "100px" },
+      data: {
+        heading: "Heading",
+        message: "Message",
+      },
+    });
+  });
 });