Skip to content

Commit

Permalink
fix dialog service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Nov 4, 2024
1 parent 6d3ee12 commit ffe75b8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
61 changes: 51 additions & 10 deletions frontend/src/app/services/dialog.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,78 @@ 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', () => {
expect(service).toBeTruthy();
});

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, {
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, {
panelClass: service.DIALOG_PANEL_CLASS_SMALL,
...service.DIALOG_CONFIG,
data: {
title: 'DELETE.TEAM.TITLE',
text: 'DELETE.TEAM.TEXT',
},
});
});
});
4 changes: 4 additions & 0 deletions frontend/src/style/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,7 @@ table.okr-table {
.okr-form-input {
@extend .okr-form-col;
}

.okr-form-label-input-container {
//TODO
}

0 comments on commit ffe75b8

Please sign in to comment.