From bded13a86cce88770e5e456ad4665a3679084f1a Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Mon, 4 Nov 2024 09:34:18 +0100 Subject: [PATCH] fix dialog service tests --- .../src/app/services/dialog.service.spec.ts | 67 ++++++++++++++++--- frontend/src/style/styles.scss | 4 ++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/services/dialog.service.spec.ts b/frontend/src/app/services/dialog.service.spec.ts index 16b4888d16..ba6e12bb13 100644 --- a/frontend/src/app/services/dialog.service.spec.ts +++ b/frontend/src/app/services/dialog.service.spec.ts @@ -2,16 +2,26 @@ import { TestBed } from '@angular/core/testing'; import { DialogService } from './dialog.service'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; -import { MatDialogRef } from '@angular/material/dialog'; +import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { ConfirmDialogComponent } from '../shared/dialog/confirm-dialog/confirm-dialog.component'; -import { TeamComponent } from '../components/team/team.component'; +import { AddEditTeamDialog } from '../team-management/add-edit-team-dialog/add-edit-team-dialog.component'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; +import { provideHttpClient } from '@angular/common/http'; describe('DialogService', () => { let service: DialogService; + let matDialogSpy: MatDialog; + let translateServiceSpy: TranslateService; beforeEach(() => { - TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], providers: [TranslateService] }); + TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot()], + providers: [provideHttpClient(), provideHttpClientTesting(), TranslateService], + }); + matDialogSpy = TestBed.inject(MatDialog); service = TestBed.inject(DialogService); + translateServiceSpy = TestBed.inject(TranslateService); + jest.spyOn(matDialogSpy, 'open'); }); it('should be created', () => { @@ -19,20 +29,57 @@ describe('DialogService', () => { }); it('should open dialog', () => { - const dialog = service.open(TeamComponent); + const dialog = service.open(AddEditTeamDialog, { + data: { + aProperty: 'aValue', + }, + }); expect(dialog).toBeInstanceOf(MatDialogRef); - expect(dialog._containerInstance._config.panelClass).toEqual(service.DIALOG_CONFIG.panelClass); - expect(dialog._containerInstance._config.maxWidth).toEqual(service.DIALOG_CONFIG.maxWidth); - expect(dialog.componentInstance).toBeInstanceOf(TeamComponent); + expect(dialog.componentInstance).toBeInstanceOf(AddEditTeamDialog); + + expect(matDialogSpy.open).toHaveBeenCalledWith( + AddEditTeamDialog, + expect.objectContaining({ + panelClass: service.DIALOG_PANEL_CLASS_DEFAULT, + ...service.DIALOG_CONFIG, + data: { + aProperty: 'aValue', + }, + }), + ); }); it('should open confirm dialog', () => { + const i18nData = { + team: 'the a-team', + }; jest.spyOn(service, 'open'); - const dialog = service.openConfirmDialog('DELETE.ACTION'); + jest.spyOn(translateServiceSpy, 'instant'); + const dialog = service.openConfirmDialog('DELETE.TEAM', i18nData); + + //Call function of own service expect(service.open).toHaveBeenCalledTimes(1); expect(dialog).toBeInstanceOf(MatDialogRef); + expect(translateServiceSpy.instant).toHaveBeenCalledTimes(2); + expect(translateServiceSpy.instant).toHaveBeenCalledWith('DELETE.TEAM.TITLE', i18nData); + expect(translateServiceSpy.instant).toHaveBeenCalledWith('DELETE.TEAM.TEXT', i18nData); + + //Call function of angular material dialog + expect(matDialogSpy.open).toHaveBeenCalledTimes(1); expect(dialog.componentInstance).toBeInstanceOf(ConfirmDialogComponent); - expect(dialog.componentInstance.data.title).toBe('DELETE.ACTION.TITLE'); - expect(dialog.componentInstance.data.text).toBe('DELETE.ACTION.TEXT'); + expect(dialog.componentInstance.data.title).toBe('DELETE.TEAM.TITLE'); + expect(dialog.componentInstance.data.text).toBe('DELETE.TEAM.TEXT'); + + expect(matDialogSpy.open).toHaveBeenCalledWith( + ConfirmDialogComponent, + expect.objectContaining({ + panelClass: service.DIALOG_PANEL_CLASS_SMALL, + ...service.DIALOG_CONFIG, + data: { + title: 'DELETE.TEAM.TITLE', + text: 'DELETE.TEAM.TEXT', + }, + }), + ); }); }); diff --git a/frontend/src/style/styles.scss b/frontend/src/style/styles.scss index 2af48b165f..72046c9660 100644 --- a/frontend/src/style/styles.scss +++ b/frontend/src/style/styles.scss @@ -371,3 +371,7 @@ table.okr-table { .okr-form-input { @extend .okr-form-col; } + +.okr-form-label-input-container { + //TODO +}