forked from renz45/Vue-BookListing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hampton Paulk
committed
Feb 27, 2018
1 parent
06253b9
commit 2646ecc
Showing
17 changed files
with
479 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const esquery = require('esquery'); | ||
const esprima = require('esprima'); | ||
|
||
describe('BookForm.vue', () => { | ||
it('should contain a data function that returns bookTitle and bookAuthor @book-form-contains-data', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm component does not exist'); | ||
} | ||
const document = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = document.childNodes; | ||
const script = nodes.filter(node => node.nodeName === 'script'); | ||
|
||
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' }); | ||
const data = esquery(ast, 'Property[key.name=data]'); | ||
assert(data.length > 0, 'data function return is not present'); | ||
|
||
let results = esquery(data[0], 'Property[key.name=bookTitle] > .value[value=""]'); | ||
assert(results.length > 0, 'bookTitle property is not defined with a blank string value'); | ||
|
||
results = esquery(data[0], 'Property[key.name=bookAuthor] > .value[value=""]'); | ||
assert(results.length > 0, 'bookAuthor property is not defined with a blank string value'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
test/unit/mocha/part5/book-form-contains-form-data.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const jsdom = require('jsdom'); | ||
|
||
const { JSDOM } = jsdom; | ||
|
||
|
||
describe('BookForm.vue', () => { | ||
it('should a form @book-list-will-contain-form', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm.vue file does not exist'); | ||
} | ||
|
||
// Parse document | ||
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = doc.childNodes; | ||
|
||
// Parse for HTML in template | ||
const template = nodes.filter(node => node.nodeName === 'template'); | ||
const content = parse5.serialize(template[0].content); | ||
const dom = new JSDOM(content, { includeNodeLocations: true, SVG_LCASE: true }); | ||
const document = dom.window.document; | ||
|
||
// Test for for form existance | ||
const results = document.querySelector('form'); | ||
assert(results.length > 0, 'BookForm does not contain a form'); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
test/unit/mocha/part5/book-form-contains-methods-declaration.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const esquery = require('esquery'); | ||
const esprima = require('esprima'); | ||
|
||
describe('BookForm.vue', () => { | ||
it('should contain a methods declaration @book-form-contains-methods-declaration', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm component does not exist'); | ||
} | ||
const document = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = document.childNodes; | ||
const script = nodes.filter(node => node.nodeName === 'script'); | ||
|
||
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' }); | ||
const methods = esquery(ast, 'Property[key.name=methods]'); | ||
assert(methods.length > 0, 'the methods declaration is not present'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const esquery = require('esquery'); | ||
const esprima = require('esprima'); | ||
|
||
|
||
describe('BookForm.vue', () => { | ||
it('should contain props @book-form-contains-props-with-books', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm.vue file does not exist'); | ||
} | ||
|
||
// Parse document and retrieve the script section | ||
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = doc.childNodes; | ||
const script = nodes.filter(node => node.nodeName === 'script'); | ||
|
||
// Test for correct import statement | ||
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' }); | ||
|
||
let results = esquery(ast, 'ExportDefaultDeclaration Property[key.name="name"] Literal[value="BookForm"]'); | ||
assert(results.length > 0, './BookForm does not have a name property with the value of BookForm'); | ||
|
||
results = esquery(ast, 'ExportDefaultDeclaration Property[key.name="props"] Literal[value="books"]'); | ||
assert(results.length > 0, './BookForm does not have a props property with the value of books'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const esquery = require('esquery'); | ||
const esprima = require('esprima'); | ||
|
||
describe('BookForm.vue', () => { | ||
it('should contain a methods call to bookSubmit @book-form-emits-add-book', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm component does not exist'); | ||
} | ||
const document = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = document.childNodes; | ||
const script = nodes.filter(node => node.nodeName === 'script'); | ||
|
||
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' }); | ||
const methods = esquery(ast, 'Property[key.name=methods]'); | ||
assert(methods.length > 0, 'the methods declaration is not present'); | ||
|
||
let results = esquery(methods[0], 'Identifier[name="bookSubmit"]'); | ||
assert(results.length > 0, 'bookSubmit method is not defined'); | ||
|
||
results = esquery(methods[0], 'CallExpression[arguments] > Literal[value="addBook"]'); | ||
assert(results.length > 0, 'addBook is not present in your this call expression'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
|
||
|
||
describe('BookForm.vue', () => { | ||
it('should exist with correct framework @book-form-exists', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm.vue file does not exist'); | ||
} | ||
|
||
// Parse document and retrieve the script section | ||
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = doc.childNodes; | ||
const script = nodes.filter(node => node.nodeName === 'script'); | ||
assert(script, 'No script tag exists in BookForm.vue'); | ||
|
||
const template = nodes.filter(node => node.nodeName === 'template'); | ||
assert(template, 'No template tag exists in BookForm.vue'); | ||
|
||
const style = nodes.filter(node => node.nodeName === 'style'); | ||
assert(style, 'No style tag exists in BookForm.vue'); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
test/unit/mocha/part5/book-form-form-has-on-submit.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const jsdom = require('jsdom'); | ||
|
||
const { JSDOM } = jsdom; | ||
|
||
|
||
describe('BookForm.vue', () => { | ||
it('should contain a form with submit call to bookSubmit @book-list-will-contain-submit-with-prevent-and-method-call', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm.vue file does not exist'); | ||
} | ||
|
||
// Parse document | ||
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = doc.childNodes; | ||
|
||
// Parse for HTML in template | ||
const template = nodes.filter(node => node.nodeName === 'template'); | ||
const content = parse5.serialize(template[0].content); | ||
const dom = new JSDOM(content, { includeNodeLocations: true, SVG_LCASE: true }); | ||
const document = dom.window.document; | ||
|
||
// Test for for form existance | ||
const results = document.querySelector('form'); | ||
assert(results.length > 0, 'BookForm does not contain a form'); | ||
|
||
assert(results.outerHTML.includes('submit.prevent'), 'BookForm does not have an v-on:submit.prevent'); | ||
|
||
assert(results.outerHTML.includes('bookSubmit(bookTitle, bookAuthor)'), 'BookForm does not call bookSubmit'); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
test/unit/mocha/part5/book-form-form-has-v-model-directives.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const jsdom = require('jsdom'); | ||
|
||
const { JSDOM } = jsdom; | ||
|
||
|
||
describe('BookForm.vue', () => { | ||
it('should contain a form with v-model directives @book-list-will-contain-v-model-directives', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm.vue file does not exist'); | ||
} | ||
|
||
// Parse document | ||
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = doc.childNodes; | ||
|
||
// Parse for HTML in template | ||
const template = nodes.filter(node => node.nodeName === 'template'); | ||
const content = parse5.serialize(template[0].content); | ||
const dom = new JSDOM(content, { includeNodeLocations: true, SVG_LCASE: true }); | ||
const document = dom.window.document; | ||
|
||
// Test for for form existance | ||
const results = document.querySelector('form'); | ||
assert(results.length > 0, 'BookForm does not contain a form'); | ||
|
||
assert(results.innerHTML.includes('v-model="bookTitle"'), 'BookForm does not have an v-model for bookTitle'); | ||
|
||
assert(results.innerHTML.includes('v-model="bookAuthor"'), 'BookForm does not have an v-model for bookAuthor'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
test/unit/mocha/part5/book-form-methods-contains-add-book.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const esquery = require('esquery'); | ||
const esprima = require('esprima'); | ||
|
||
describe('BookForm.vue', () => { | ||
it('should contain a methods call to bookSubmit @book-form-contains-method-call', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookForm component does not exist'); | ||
} | ||
const document = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = document.childNodes; | ||
const script = nodes.filter(node => node.nodeName === 'script'); | ||
|
||
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' }); | ||
const methods = esquery(ast, 'Property[key.name=methods]'); | ||
assert(methods.length > 0, 'the methods declaration is not present'); | ||
|
||
let results = esquery(methods[0], 'Identifier[name="bookSubmit"]'); | ||
assert(results.length > 0, 'bookSubmit method is not defined'); | ||
|
||
results = esquery(methods[0], 'Property[key.name="bookSubmit"] > FunctionExpression > Identifier[name="bookTitle"]'); | ||
assert(results.length > 0, 'bookTitle is not an argument inside the the bookSubmit Method'); | ||
|
||
results = esquery(methods[0], 'Property[key.name="bookSubmit"] > FunctionExpression > Identifier[name="bookAuthor"]'); | ||
assert(results.length > 0, 'bookAuthor is not an argument inside the the bookSubmit Method'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
test/unit/mocha/part5/book-list-contains-append-book-method.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const esquery = require('esquery'); | ||
const esprima = require('esprima'); | ||
|
||
describe('BookList.vue', () => { | ||
it('should contain a methods call to appendBook @book-list-contains-method-call', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookList.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookList component does not exist'); | ||
} | ||
const document = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = document.childNodes; | ||
const script = nodes.filter(node => node.nodeName === 'script'); | ||
|
||
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' }); | ||
const methods = esquery(ast, 'Property[key.name=methods]'); | ||
assert(methods.length > 0, 'the methods declaration is not present'); | ||
|
||
let results = esquery(methods[0], 'Identifier[name="appendBook"]'); | ||
assert(results.length > 0, 'appendBook method is not defined'); | ||
|
||
results = esquery(methods[0], 'Property[key.name="appendBook"] > FunctionExpression > Identifier[name="bookTitle"]'); | ||
assert(results.length > 0, 'bookTitle is not an argument inside the the appendBook Method'); | ||
|
||
results = esquery(methods[0], 'Property[key.name="appendBook"] > FunctionExpression > Identifier[name="bookAuthor"]'); | ||
assert(results.length > 0, 'bookAuthor is not an argument inside the the appendBook Method'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
test/unit/mocha/part5/book-list-contains-book-form-element.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('chai').assert; | ||
const parse5 = require('parse5'); | ||
const jsdom = require('jsdom'); | ||
|
||
const { JSDOM } = jsdom; | ||
|
||
|
||
describe('BookList.vue', () => { | ||
it('should contain book-form element @book-list-contains-book-form', () => { | ||
let file; | ||
try { | ||
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookList.vue'), 'utf8'); | ||
} catch (e) { | ||
assert(false, 'The BookList.vue file does not exist'); | ||
} | ||
|
||
// Parse document | ||
const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true }); | ||
const nodes = doc.childNodes; | ||
|
||
// Parse for HTML in template | ||
const template = nodes.filter(node => node.nodeName === 'template'); | ||
const content = parse5.serialize(template[0].content); | ||
const dom = new JSDOM(content, { includeNodeLocations: true, SVG_LCASE: true }); | ||
const document = dom.window.document; | ||
|
||
// Test for booklist in the app div | ||
const results = document.querySelector('div'); | ||
assert(results.innerHTML.includes('book-form'), 'BookList does not contain any book-form tags'); | ||
}); | ||
}); |
Oops, something went wrong.