From c0991e8123d979004cfa27575d24fdfba5111d68 Mon Sep 17 00:00:00 2001 From: benjaminJ Date: Wed, 26 Oct 2016 13:38:34 +0200 Subject: [PATCH] Test the folder selection --- src/index.js | 15 +++++++-------- test/spec/index.spec.js | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index 65e795a..11c80e3 100644 --- a/src/index.js +++ b/src/index.js @@ -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); }; @@ -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); diff --git a/test/spec/index.spec.js b/test/spec/index.spec.js index a927622..5470177 100644 --- a/test/spec/index.spec.js +++ b/test/spec/index.spec.js @@ -101,7 +101,7 @@ 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("-"); @@ -109,7 +109,7 @@ describe("inquirer-directory", function() { 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("/"); @@ -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");