Skip to content

Commit

Permalink
fix(module:modal): no longer trigger any action when closing (#7336)
Browse files Browse the repository at this point in the history
  • Loading branch information
maroon1 committed Apr 21, 2022
1 parent b5f82b5 commit d169452
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/modal/modal-ref.ts
Expand Up @@ -167,6 +167,9 @@ export class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAP
}

private async trigger(action: NzTriggerAction): Promise<void> {
if (this.state === NzModalState.CLOSING) {
return;
}
const trigger = { ok: this.config.nzOnOk, cancel: this.config.nzOnCancel }[action];
const loadingKey = { ok: 'nzOkLoading', cancel: 'nzCancelLoading' }[action] as 'nzOkLoading' | 'nzCancelLoading';
const loading = this.config[loadingKey];
Expand Down
26 changes: 26 additions & 0 deletions components/modal/modal.spec.ts
Expand Up @@ -908,6 +908,32 @@ describe('NzModal', () => {
expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(0);
}));

it('should omit any action when closing', async function () {
const onOk = jasmine.createSpy('onOk', () => {});
const onCancel = jasmine.createSpy('onCancel', () => {});
const modalRef = modalService.create({
nzContent: TestWithModalContentComponent,
nzOnOk: onOk,
nzOnCancel: onCancel
});
fixture.detectChanges();
expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(1);
await modalRef.triggerOk();
expect(onOk).toHaveBeenCalledTimes(1);
fakeAsync(() => {
expect(modalRef.getState()).toBe(NzModalState.CLOSING);
modalRef.triggerOk();
modalRef.triggerOk();
modalRef.triggerCancel();
modalRef.triggerCancel();
expect(onOk).toHaveBeenCalledTimes(1);
expect(onCancel).toHaveBeenCalledTimes(0);
fixture.detectChanges();
flush();
expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(0);
});
});

it('should set loading state when the callback is promise', fakeAsync(() => {
const modalRef = modalService.create({
nzContent: TestWithModalContentComponent,
Expand Down

0 comments on commit d169452

Please sign in to comment.