Skip to content

Commit

Permalink
Add test to the checkbox prompt and add doc to the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jun 22, 2013
1 parent dd3496f commit bad2d30
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ See `examples/expand.js` for a running example.
Answer:
```

### Checkbox - `{ type: "checkbox" }`

Take `type`, `name`, `message`, `choices`[, `filter`, `validate`] properties.

Choices marked as `{ checked: true }` will be checked by default.

``` prompt
[?] Choose your toppings: (press <space> to select)
[ ] Pepperoni
> [ ] Cheese
[X] Tomato
[ ] Pineapple
[ ] Bacon
```

### Confirm - `{ type: "confirm" }`

Take `type`, `name`, `message`[, `default`] properties. `default` is expected to be a boolean if used.
Expand Down
28 changes: 28 additions & 0 deletions test/specs/prompts/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,32 @@ describe("`checkbox` prompt", function() {
this.rl.emit("line");
});

it("should check defaults choices", function( done ) {
this.fixture.choices = [
{ name: "1", checked: true },
{ name: "2", checked: false },
{ name: "3", checked: false }
];
this.checkbox = new Checkbox( this.fixture, this.rl );
this.checkbox.run(function( answer ) {
expect(answer.length).to.equal(1);
expect(answer[0]).to.equal("1");
done();
});
this.rl.emit("line");
});

it("should toggle choice when hitting space", function( done ) {
this.checkbox.run(function( answer ) {
expect(answer.length).to.equal(1);
expect(answer[0]).to.equal("choice 1");
done();
});
this.rl.emit("keypress", " ", { name: "space" });
this.rl.emit("keypress", null, { name: "down" });
this.rl.emit("keypress", " ", { name: "space" });
this.rl.emit("keypress", " ", { name: "space" });
this.rl.emit("line");
});

});

0 comments on commit bad2d30

Please sign in to comment.