Skip to content

Commit

Permalink
Test the folder selection
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiKillertO committed Oct 26, 2016
1 parent ad4cc6d commit c0991e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ Prompt.prototype.render = function() {
message += chalk.bold("\n");
var choicesStr = listRender(this.opt.choices, this.selected);
message += "\n" + this.paginator.paginate(choicesStr, this.selected, this.opt.pageSize);
if (this.searchMode) {
message += ("\nSearch: " + this.searchTerm);
} else {
message += chalk.dim("\n(Use "/" key to search this directory)");
message += chalk.dim("\n(Use "-" key to navigate to the parent folder");
}
message += chalk.dim("\n(Use arrow keys)");
}
if (this.searchMode) {
message += ("\nSearch: " + this.searchTerm);
} else {
message += chalk.dim("\n(Use "/" key to search this directory)");
message += chalk.dim("\n(Use "-" key to navigate to the parent folder");
}
message += chalk.dim("\n(Use arrow keys)");
this.screen.render(message);
};

Expand All @@ -220,7 +220,6 @@ Prompt.prototype.handleSubmit = function(e) {
var done = obx.filter(function(choice) {
return choice === CHOOSE || choice === CURRENT;
}).take(1);

var back = obx.filter(function(choice) {
return choice === BACK;
}).takeUntil(done);
Expand Down
17 changes: 15 additions & 2 deletions test/spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ describe("inquirer-directory", function() {
}
expect(this.rl.output.__raw__).to.not.contain("..");
});
it("should allow users to go back using "-" shortcut", function() {
it("should allow users to go back using '-' shortcut", function() {
this.prompt.run();
expect(this.rl.output.__raw__).to.contain("zfolder2");
this.rl.keyPress("-");
expect(this.rl.output.__raw__).to.contain("..");
expect(this.rl.output.__raw__).to.not.contain("zfolder2");
});

it("should allow users search for a folder using "/" shortcut", function() {
it("should allow users search for a folder using '/' shortcut", function() {
this.prompt.run();
expect(this.rl.output.__raw__).to.not.contain("Search:");
this.rl.keyPress("/");
Expand All @@ -124,6 +124,19 @@ describe("inquirer-directory", function() {
raw = this.rl.output.__raw__.replace("❯", ">");
expect(raw).to.contain("> folder2");
});

it("should allow users to select a folder using 'choose this directory' choice", function() {
this.prompt.run();
this.rl.moveUp();
this.rl.enter();
expect(this.prompt.currentPath.split('/').slice(-1)[0]).to.equal("root");
});

it("should allow users to select a folder using '.' choice", function() {
this.prompt.run();
this.rl.enter();
expect(this.prompt.currentPath.split('/').slice(-1)[0]).to.equal("root");
});
// it("should allow users to press keys to shortcut to that value", function (done) {
// prompt.run(function (answer) {
// expect(answer).to.equal("zfolder2");
Expand Down

0 comments on commit c0991e8

Please sign in to comment.