Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/action/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,12 @@ class ChannelAction {
*/
async closeSelectedChannel() {
try {
const { selectedChannel } = this._store;
const { selectedChannel: selected } = this._store;
this._nav.goChannels();
await this.closeChannel({ channelPoint: selectedChannel.channelPoint });
await this.closeChannel({
channelPoint: selected.channelPoint,
force: selected.status !== 'open' || !selected.active,
});
} catch (err) {
this._notification.display({ msg: 'Closing channel failed!', err });
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/action/channel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ describe('Action Channels Unit Tests', () => {
store.selectedChannel = {
channelPoint: 'some-channel-point',
status: 'open',
active: true,
};
sandbox.stub(channel, 'closeChannel');
});
Expand All @@ -271,6 +272,27 @@ describe('Action Channels Unit Tests', () => {
expect(nav.goChannels, 'was called once');
expect(channel.closeChannel, 'was called with', {
channelPoint: 'some-channel-point',
force: false,
});
});

it('should force close inactive open channel', async () => {
store.selectedChannel.active = false;
await channel.closeSelectedChannel();
expect(nav.goChannels, 'was called once');
expect(channel.closeChannel, 'was called with', {
channelPoint: 'some-channel-point',
force: true,
});
});

it('should force close pending-open channel', async () => {
store.selectedChannel.status = 'pending-open';
await channel.closeSelectedChannel();
expect(nav.goChannels, 'was called once');
expect(channel.closeChannel, 'was called with', {
channelPoint: 'some-channel-point',
force: true,
});
});

Expand Down