Skip to content
Snippets Groups Projects
Commit 8e0bf034 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5009 use correct dialog config when opening dialog wizard

parent 367e2e43
Branches
Tags
No related merge requests found
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { Dialog } from '@angular/cdk/dialog'; import { Dialog, DialogConfig } from '@angular/cdk/dialog';
import { OzgcloudDialogService } from './ozgcloud-dialog.service'; import { OzgcloudDialogService } from './ozgcloud-dialog.service';
import { mock } from '@alfa-client/test-utils';
describe('OzgcloudDialogService', () => { describe('OzgcloudDialogService', () => {
let service: OzgcloudDialogService; let service: OzgcloudDialogService;
const component = <any>{ name: 'Component' }; const component = <any>{ name: 'Component' };
const dialog = { const dialog = mock(Dialog);
open: jest.fn(), const dialogData = { id: 'ZumBeispiel' };
getDialogById: jest.fn(), const dialogConfigWithData: DialogConfig = { data: dialogData };
closeAll: jest.fn(),
};
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
...@@ -30,26 +29,42 @@ describe('OzgcloudDialogService', () => { ...@@ -30,26 +29,42 @@ describe('OzgcloudDialogService', () => {
}); });
describe('open', () => { describe('open', () => {
const config = <any>{ id: 'ZumBeispiel' }; beforeEach(() => {
dialog.open.mockReset();
});
it('should open dialog with data', () => {
service.open(component, dialogData);
it('should call dialog open with config', () => { expect(dialog.open).toHaveBeenCalledWith(component, dialogConfigWithData);
const openMock = (service.open = jest.fn()); });
service.open(component, config); it('should open dialog wihtout data', () => {
service.open(component);
expect(openMock).toHaveBeenCalledWith(component, config); expect(dialog.open).toHaveBeenCalledWith(component, undefined);
}); });
}); });
describe('openWizard', () => { describe('openWizard', () => {
const config = <any>{ id: 'ZumBeispiel' }; beforeEach(() => {
dialog.open.mockReset();
});
it('should open wizard dialog', () => {
service.openWizard(component);
expect(dialog.open).toHaveBeenCalledWith(component, {
...service.WIZARD_DIALOG_CONFIG,
});
});
it('should call dialog open with conifg', () => { it('should open wizard dialog with data', () => {
service.openWizard(component, config); service.openWizard(component, dialogData);
expect(dialog.open).toHaveBeenCalledWith(component, { expect(dialog.open).toHaveBeenCalledWith(component, {
data: config,
...service.WIZARD_DIALOG_CONFIG, ...service.WIZARD_DIALOG_CONFIG,
data: dialogData,
}); });
}); });
}); });
......
import { Dialog, DialogConfig, DialogRef } from '@angular/cdk/dialog'; import { Dialog, DialogConfig, DialogRef } from '@angular/cdk/dialog';
import { ComponentType } from '@angular/cdk/portal'; import { ComponentType } from '@angular/cdk/portal';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { isNil } from 'lodash-es';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
...@@ -14,10 +15,24 @@ export class OzgcloudDialogService { ...@@ -14,10 +15,24 @@ export class OzgcloudDialogService {
constructor(private dialog: Dialog) {} constructor(private dialog: Dialog) {}
public openWizard<T, D>(component: ComponentType<T>, data?: D): DialogRef<T> { public openWizard<T, D>(component: ComponentType<T>, data?: D): DialogRef<T> {
return this.open<T, D>(component, data); return this.openDialog<T>(
component,
this.buildDialogConfigWithData<D>(data, this.WIZARD_DIALOG_CONFIG),
);
} }
public open<T, D>(component: ComponentType<T>, data?: D): DialogRef<T> { public open<T, D>(component: ComponentType<T>, data?: D): DialogRef<T> {
return this.dialog.open<T, D>(component, { ...this.WIZARD_DIALOG_CONFIG, data }); return this.openDialog(component, this.buildDialogConfigWithData(data));
}
private buildDialogConfigWithData<D>(data: D, dialogConfig?: DialogConfig): DialogConfig | null {
if (isNil(data)) {
return dialogConfig;
}
return { ...dialogConfig, data };
}
private openDialog<T>(component: ComponentType<T>, dialogConfig?: DialogConfig): DialogRef<T> {
return this.dialog.open<T>(component, dialogConfig);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment