-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix input prompt repeating value when value is longer than terminal width. Closes #214 #239
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ var _ = require("lodash"); | |
var ReadlineStub = require("../../helpers/readline"); | ||
var fixtures = require("../../helpers/fixtures"); | ||
|
||
var utils = require("../../../lib/utils/utils"); | ||
var Input = require("../../../lib/prompts/input"); | ||
|
||
|
||
|
@@ -53,4 +54,71 @@ describe("`input` prompt", function() { | |
this.rl.emit("line", ""); | ||
}); | ||
|
||
describe("given a terminal width", function() { | ||
|
||
beforeEach(function() { | ||
this.cliWidthStub = sinon.stub( utils, "cliWidth" ); | ||
this.cliWidthStub.returns(20); | ||
}); | ||
|
||
afterEach(function() { | ||
this.cliWidthStub.restore(); | ||
}); | ||
|
||
it("should clean short lines appropriately", function( done ) { | ||
var prompt = new Input( this.fixture, this.rl ); | ||
var cleanSpy = sinon.spy( prompt, "clean" ); | ||
prompt.run(function() { | ||
expect( cleanSpy.callCount ).to.equal(1); | ||
expect( cleanSpy.calledWith(1) ).to.be.true; | ||
done(); | ||
}.bind(this)); | ||
|
||
this.rl.line = "hello"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, I have to assign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is correct as we use a mocked readline. So there's no usual Readline behavior during testing. |
||
this.rl.emit( "line", this.rl.line ); | ||
}); | ||
|
||
it("should clean wrapped long lines", function( done ) { | ||
var prompt = new Input( this.fixture, this.rl ); | ||
var cleanSpy = sinon.spy( prompt, "clean" ); | ||
prompt.run(function() { | ||
expect( cleanSpy.callCount ).to.equal(1); | ||
expect( cleanSpy.calledWith(3) ).to.be.true; | ||
done(); | ||
}.bind(this)); | ||
|
||
this.rl.line = "asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"; | ||
this.rl.emit( "line", this.rl.line ); | ||
}); | ||
|
||
}); | ||
|
||
describe("given no terminal width", function() { | ||
|
||
beforeEach(function() { | ||
this.cliWidthStub = sinon.stub( utils, "cliWidth" ); | ||
|
||
// Return the default value | ||
this.cliWidthStub.returns(0); | ||
}); | ||
|
||
afterEach(function() { | ||
this.cliWidthStub.restore(); | ||
}); | ||
|
||
it("should clean one line even if the input line is long", function( done ) { | ||
var prompt = new Input( this.fixture, this.rl ); | ||
var cleanSpy = sinon.spy( prompt, "clean" ); | ||
prompt.run(function() { | ||
expect( cleanSpy.callCount ).to.equal(1); | ||
expect( cleanSpy.calledWith(1) ).to.be.true; | ||
done(); | ||
}.bind(this)); | ||
|
||
this.rl.line = "asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"; | ||
this.rl.emit( "line", this.rl.line ); | ||
}); | ||
|
||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SBoudrias Do you have any insight on how to get this function (
Prompt.prototype.onEnd
) called in the unit tests? Currently onlyonKeypress
seems to be called there, even when emitting a line event.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not sure I understand this question. Mind clarifying?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SBoudrias If you take a look at my latest changes in the PR, I was able to unit test
Prompt.prototype.onKeypress()
by usingthis.rl.emit()
, however callingthis.rl.emit()
in the unit tests doesn't callPrompt.prototype.onEnd()
(it does call it when not mocking readline), so I wonder if you know a way to makePrompt.prototype.onEnd()
get called as well, to unit test that function as well.