Skip to content

Commit

Permalink
fix: Changes in progress dashboard are correctly saved
Browse files Browse the repository at this point in the history
fixes: #1140
Schottkyc137 authored Mar 14, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c981cd1 commit df2fa3f
Showing 2 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import {
ComponentFixture,
fakeAsync,
TestBed,
waitForAsync,
} from "@angular/core/testing";

import { ProgressDashboardComponent } from "./progress-dashboard.component";
import { EntityMapperService } from "../../../core/entity/entity-mapper.service";
import { AlertService } from "../../../core/alerts/alert.service";
import { ProgressDashboardWidgetModule } from "../progress-dashboard-widget.module";
import { FontAwesomeTestingModule } from "@fortawesome/angular-fontawesome/testing";
import { MatDialog } from "@angular/material/dialog";
import { Subject } from "rxjs";
import { take } from "rxjs/operators";

describe("ProgressDashboardComponent", () => {
let component: ProgressDashboardComponent;
let fixture: ComponentFixture<ProgressDashboardComponent>;
const mockDialog = jasmine.createSpyObj<MatDialog>("matDialog", ["open"]);
let mockEntityService: jasmine.SpyObj<any>;

beforeEach(
waitForAsync(() => {
const mockEntityService = jasmine.createSpyObj("mockEntityService", [
mockEntityService = jasmine.createSpyObj("mockEntityService", [
"load",
"save",
]);
mockEntityService.load.and.resolveTo({ title: "test", parts: [] });
mockEntityService.save.and.resolveTo();

TestBed.configureTestingModule({
imports: [ProgressDashboardWidgetModule, FontAwesomeTestingModule],
providers: [
{ provide: EntityMapperService, useValue: mockEntityService },
{ provide: MatDialog, useValue: mockDialog },
{
provide: AlertService,
useValue: jasmine.createSpyObj([
@@ -44,4 +56,14 @@ describe("ProgressDashboardComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});

it("saves data after the dialog was closed", fakeAsync(() => {
const closeNotifier = new Subject();
mockDialog.open.and.returnValue({
afterClosed: () => closeNotifier.pipe(take(1)),
} as any);
component.showEditComponent();
closeNotifier.next({});
expect(mockEntityService.save).toHaveBeenCalled();
}));
});
Original file line number Diff line number Diff line change
@@ -29,10 +29,7 @@ export class ProgressDashboardComponent
ngOnInit() {
this.data = new ProgressDashboardConfig(this.dashboardConfigId);
this.entityMapper
.load<ProgressDashboardConfig>(
ProgressDashboardConfig,
this.dashboardConfigId
)
.load(ProgressDashboardConfig, this.dashboardConfigId)
.then((config) => {
this.data = config;
})
@@ -60,13 +57,16 @@ export class ProgressDashboardComponent
}

showEditComponent() {
const dialog = this.dialog.open(EditProgressDashboardComponent, {
data: this.data,
});
dialog.afterClosed().subscribe((next) => {
if (next) {
this.data.parts = next;
}
});
this.dialog
.open(EditProgressDashboardComponent, {
data: this.data,
})
.afterClosed()
.subscribe(async (next) => {
if (next) {
this.data.parts = next;
await this.save();
}
});
}
}

0 comments on commit df2fa3f

Please sign in to comment.