Skip to content

Commit

Permalink
fix(components/modals): SkyModalTestingController.closeTopModal pas…
Browse files Browse the repository at this point in the history
…ses `reason` and `result` to the modal instance (#2565)
  • Loading branch information
Blackbaud-SteveBrush authored Jul 29, 2024
1 parent ae73ccb commit 0337f78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class TestComponent implements OnDestroy {
this.#instances.forEach((i) => i.close());
}

public getInstanceAt(index: number): SkyModalInstance | undefined {
return this.#instances.at(index);
}

public openModal(): void {
const instance = this.#modalSvc.open(ModalTestComponent, {
providers: [
Expand Down Expand Up @@ -143,6 +147,24 @@ describe('modal-testing.controller', () => {
modalController.expectNone();
});

it('should close a modal with args', () => {
const { fixture, modalController } = setupTest();

fixture.componentInstance.openModal();
fixture.detectChanges();

const closeSpy = spyOn(
fixture.componentInstance.getInstanceAt(0)!,
'close',
).and.callThrough();

modalController.closeTopModal({ reason: 'save', data: { foo: 'bar' } });

fixture.detectChanges();

expect(closeSpy).toHaveBeenCalledWith({ foo: 'bar' }, 'save');
});

it('should throw if topmost modal does not match criteria', () => {
const { fixture, modalController } = setupTest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class SkyModalTestingService
);
}

modal.instance.close(args);
modal.instance.close(args?.data, args?.reason);
}

public expectCount(value: number): void {
Expand Down

0 comments on commit 0337f78

Please sign in to comment.