Skip to content

Commit

Permalink
WIP Make HistoricalCommandReader the only reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu1kn committed Dec 4, 2016
1 parent 5c60665 commit e20a885
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
23 changes: 15 additions & 8 deletions lib/command-readers/historical.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class HistoricalCommandReader {
const history = this._historyStore.getAll();
if (history.length === 0) {
return this._vsWindow.showInputBox({
prompt: 'No history available. Enter a new command'
placeHolder: 'Enter a command',
prompt: 'No history available yet'
});
}

Expand All @@ -22,22 +23,28 @@ class HistoricalCommandReader {
}

_letUserToPickCommand(state) {
const options = {placeHolder: 'Select a command to reuse'};
const options = {placeHolder: 'Select a command to reuse or Cancel (Esc) to write a new command'};
return this._vsWindow.showQuickPick(state.history.reverse(), options)
.then(pickedCommand => Object.assign({}, state, {pickedCommand}));
}

_letUserToModifyCommand(state) {
if (!state.pickedCommand) return state;

const options = {
value: state.pickedCommand,
prompt: 'Edit the command if necessary'
};
const options = this._getInputBoxOption(state.pickedCommand);
return this._vsWindow.showInputBox(options)
.then(finalCommand => Object.assign({}, state, {finalCommand}));
}

_getInputBoxOption(pickedCommand) {
if (!pickedCommand) {
return {placeHolder: 'Enter a command'};
}
return {
placeHolder: 'Enter a command',
prompt: 'Edit the command if necessary',
value: pickedCommand
};
}

}

module.exports = HistoricalCommandReader;
16 changes: 10 additions & 6 deletions test/lib/command-readers/historical.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ describe('HistoricalCommandReader', () => {
expect(command).to.eql('COMMAND_FINAL');
expect(vscodeWindow.showQuickPick).to.have.been.calledWith(
['COMMAND_2', 'COMMAND_1'],
{placeHolder: 'Select a command to reuse'}
{placeHolder: 'Select a command to reuse or Cancel (Esc) to write a new command'}
);
expect(vscodeWindow.showInputBox).to.have.been.calledWith({
placeHolder: 'Enter a command',
prompt: 'Edit the command if necessary',
value: 'COMMAND_1'
});
Expand All @@ -34,21 +35,24 @@ describe('HistoricalCommandReader', () => {
expect(command).to.eql('COMMAND');
expect(vscodeWindow.showQuickPick).to.not.have.been.called;
expect(vscodeWindow.showInputBox).to.have.been.calledWith({
prompt: 'No history available. Enter a new command'
placeHolder: 'Enter a command',
prompt: 'No history available yet'
});
});
});

it('does not show inputBox if history command picker is dismissed', () => {
it('shows inputBox if history command picker is dismissed', () => {
const vscodeWindow = {
showInputBox: sinon.spy(),
showInputBox: sinon.stub().returns(Promise.resolve('COMMAND')),
showQuickPick: () => Promise.resolve()
};
const historyStore = {getAll: () => ['COMMAND_1', 'COMMAND_2']};
const reader = new HistoricalCommandReader({historyStore, vsWindow: vscodeWindow});
return reader.read().then(command => {
expect(command).to.be.undefined;
expect(vscodeWindow.showInputBox).to.not.have.been.called;
expect(command).to.eql('COMMAND');
expect(vscodeWindow.showInputBox).to.have.been.calledWith({
placeHolder: 'Enter a command'
});
});
});

Expand Down

0 comments on commit e20a885

Please sign in to comment.