Skip to content

Commit

Permalink
Form should have labels
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinapowers committed Aug 2, 2018
1 parent c869261 commit 78a2e89
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
6 changes: 3 additions & 3 deletions test/unit/mocha/part6/form-should-have-checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ describe("BookForm.vue", () => {

assert(
checkbox.length > 0,
"The form doesn't have an `<input>` element with a `type` of `checkbox`"
"The form doesn't have an `<input>` element with a `type` of `checkbox`."
);

assert.hasAnyKeys(
checkbox.attr(),
["v-model"],
"The BookForm checkbox does not have a `v-model` directive containing `bookData.finishedReading` as its value"
"The BookForm checkbox does not have a `v-model` directive containing `bookData.finishedReading` as its value."
);

assert.propertyVal(
checkbox.attr(),
"v-model",
"bookData.finishedReading",
"The BookForm checkbox does not have a `v-model` directive containing `bookData.finishedReading` as its value"
"The BookForm checkbox does not have a `v-model` directive containing `bookData.finishedReading` as its value."
);
});
});
64 changes: 64 additions & 0 deletions test/unit/mocha/part6/form-should-have-labels.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const assert = require("chai").assert;
const parse5 = require("parse5");
const cheerio = require("cheerio");
const helpers = require("../helpers");

describe("BookForm.vue", () => {
it("should contain three labels with a `for` attribute @book-form-will-contain-labels", () => {
const file = helpers.readFile("src/components/BookForm.vue");
const nodes = helpers.parseFile(file);
const tagName = helpers.getHtmlTag("template", nodes);
const content = parse5.serialize(tagName[0].content);
const $ = cheerio.load(content);
const label = $("form").find("label");

assert(
label.length === 3,
"The form doesn't have three `<label>` elements with a `for` attribute."
);

assert.hasAnyKeys(
label.attr(),
["for"],
"The BookForm label does not have a `for` attribute containing `finishedReading` as its value."
);

assert.propertyVal(
label.attr(),
"for",
"finishedReading",
"The BookForm label does not have a `for` attribute containing `finishedReading` as its value."
);

assert(
$('label[for="borrowed"]').length > 0,
"The BookForm label does not have a `for` attribute containing `borrowed` as its value."
);

assert(
$('label[for="bought"]').length > 0,
"The BookForm label does not have a `for` attribute containing `bought` as its value."
);

assert(
$('label[for="finishedReading"]')
.text()
.match(/\s*Finished\s*Reading/),
"The BookForm does not have a label with a text of `Finished Reading`."
);

assert(
$('label[for="borrowed"]')
.text()
.match(/\s*borrowed/),
"The BookForm does not have a label with a text of `borrowed`."
);

assert(
$('label[for="bought"]')
.text()
.match(/\s*bought/),
"The BookForm does not have a label with a text of `bought`."
);
});
});
6 changes: 3 additions & 3 deletions test/unit/mocha/part6/form-should-have-radio-button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ describe("BookForm.vue", () => {

assert(
radio.length == 2,
"The form doesn't have two `<input>` elements with a `type` of `radio`"
"The form doesn't have two `<input>` elements with a `type` of `radio`."
);

assert.hasAnyKeys(
radio.attr(),
["v-model"],
"The BookForm radio does not have a `v-model` directive containing `bookData.ownership` as its value"
"The BookForm radio does not have a `v-model` directive containing `bookData.ownership` as its value."
);

assert.propertyVal(
radio.attr(),
"v-model",
"bookData.ownership",
"The BookForm radio does not have a `v-model` directive containing `bookData.finishedReading` as its value"
"The BookForm radio does not have a `v-model` directive containing `bookData.finishedReading` as its value."
);
});
});
8 changes: 4 additions & 4 deletions test/unit/mocha/part6/refactor-book-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("BookForm.vue", () => {

assert(
bookTitle.length > 0,
"The `bookData` `bookTitle` property is not defined with value of `''`"
"The `bookData` `bookTitle` property is not defined with value of `''`."
);

let bookAuthor = esquery(
Expand All @@ -49,7 +49,7 @@ describe("BookForm.vue", () => {
);
assert(
bookAuthor.length > 0,
"The `bookData` `bookAuthor` property is not defined with value of `''`"
"The `bookData` `bookAuthor` property is not defined with value of `''`."
);

let finishedReading = esquery(
Expand All @@ -59,7 +59,7 @@ describe("BookForm.vue", () => {

assert(
finishedReading.length > 0,
"The `bookData` `finishedReading` property is not defined with value of `false`"
"The `bookData` `finishedReading` property is not defined with value of `false`."
);

let ownership = esquery(data[0], "Property[key.name=ownership]");
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("BookForm.vue", () => {

assert(
notes.length > 0,
"The `bookData` `notes` property is not defined with value of `My notes about the book:`"
"The `bookData` `notes` property is not defined with value of `My notes about the book:`."
);
});
});
6 changes: 3 additions & 3 deletions test/unit/mocha/part6/should-have-a-text-area.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ describe("BookForm.vue", () => {
const $ = cheerio.load(content);
const textarea = $("form textarea");

assert(textarea.length > 0, "The form doesn't have an `<textarea>`");
assert(textarea.length > 0, "The form doesn't have an `<textarea>`.");

assert.hasAnyKeys(
textarea.attr(),
["v-model"],
"The BookForm textarea does not have a `v-model` directive containing `bookData.notes` as its value"
"The BookForm textarea does not have a `v-model` directive containing `bookData.notes` as its value."
);

assert.propertyVal(
textarea.attr(),
"v-model",
"bookData.notes",
"The BookForm textarea does not have a `v-model` directive containing `bookData.notes` as its value"
"The BookForm textarea does not have a `v-model` directive containing `bookData.notes` as its value."
);
});
});

0 comments on commit 78a2e89

Please sign in to comment.