Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Completing SkyModalInstance.closed upon close
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackbaud-ScottFreeman committed Nov 29, 2017
1 parent 9e1ecc8 commit e64a35b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/modules/modal/modal-instance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,53 @@ describe('Modal instance', () => {
});

it('should allow users to subscribe to the instanceClose event', function () {
let instance = new SkyModalInstance();
let instance: SkyModalInstance;
let expectedResult: SkyModalCloseArgs;

instance.closed.subscribe((result: SkyModalCloseArgs) => {
expectedResult = result;
});

instance = subscribeToClosed();
instance.cancel('My result');

expect(expectedResult.data).toBe('My result');
expect(expectedResult.reason).toBe('cancel');

instance = subscribeToClosed();
instance.save('My data');
expect(expectedResult.data).toBe('My data');
expect(expectedResult.reason).toBe('save');

instance = subscribeToClosed();
instance.close('My close', 'reason');
expect(expectedResult.data).toBe('My close');
expect(expectedResult.reason).toBe('reason');

instance = subscribeToClosed();
instance.close('close data');
expect(expectedResult.data).toBe('close data');
expect(expectedResult.reason).toBe('close');

function subscribeToClosed() {
const modalInstance = new SkyModalInstance();

modalInstance.closed.subscribe((result: SkyModalCloseArgs) => {
expectedResult = result;
});

return modalInstance;
}
});

it('should only emit closed and complete', () => {
const instance = new SkyModalInstance();
let wasClosedEmitted = false;
let wasClosedCompleted = false;

instance.closed.subscribe({
next: () => wasClosedEmitted = true,
complete: () => wasClosedCompleted = true
});

instance.close();
expect(wasClosedEmitted).toBe(true);
expect(wasClosedCompleted).toBe(true);
});
});
1 change: 1 addition & 0 deletions src/modules/modal/modal-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class SkyModalInstance {
args.data = result;

this.closed.emit(args);
this.closed.complete();
}

}

0 comments on commit e64a35b

Please sign in to comment.