diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/HR_PAGE.md | 2 | ||||
-rw-r--r-- | test/fixtures/QUIZ_PAGE.md | 33 | ||||
-rw-r--r-- | test/page.js | 37 |
3 files changed, 59 insertions, 13 deletions
diff --git a/test/fixtures/HR_PAGE.md b/test/fixtures/HR_PAGE.md index da53b0c..49115d0 100644 --- a/test/fixtures/HR_PAGE.md +++ b/test/fixtures/HR_PAGE.md @@ -4,7 +4,7 @@ Some nice content here --- -A beautiful separator, but non an exercise ! +A beautiful separator, but non an exercise or a quiz ! --- diff --git a/test/fixtures/QUIZ_PAGE.md b/test/fixtures/QUIZ_PAGE.md new file mode 100644 index 0000000..545d083 --- /dev/null +++ b/test/fixtures/QUIZ_PAGE.md @@ -0,0 +1,33 @@ +# Gitbook quiz + +Gitbook lets you write a quiz using GFM tables: + +--- + +Here's a quiz about Gitbook + +| | Good | Bad | +| ---------------- | ---- | --- | +| What is Gitbook? | (x) | ( ) | + +> Gitbook is good + +What does Gitbook support? +- [x] Table-based questions with radio buttons +- [x] Table-based questions with checkboxes +- [ ] Telepathy +- [x] List-based questions with checkboxes +- [x] List-based questions with radio buttons +- [ ] Moon-on-a-stick + +> Gitbook supports table and list based quiz questions using either radio buttons or checkboxes. +> +> Gitbook is not telepathic and does not give you the moon on a stick. + +--- + +Some more nice content .... + +[Cool stuff](http://gitbook.io) + +[Link to another Markdown file](./xyz/file.md) diff --git a/test/page.js b/test/page.js index fa6db06..a8a3770 100644 --- a/test/page.js +++ b/test/page.js @@ -4,28 +4,30 @@ var assert = require('assert'); var page = require('../').parse.page; +function loadPage (name, options) { + var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8'); + return page(CONTENT, options); +} -var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/PAGE.md'), 'utf8'); -var LEXED = page(CONTENT, { +var LEXED = loadPage('PAGE', { dir: 'course', outdir: '_book' }); - -var HR_CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/HR_PAGE.md'), 'utf8'); -var HR_LEXED = page(HR_CONTENT); - -var LINKS_CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/GITHUB_LINKS.md'), 'utf8'); - +var QUIZ_LEXED = loadPage('QUIZ_PAGE'); +var HR_LEXED = loadPage('HR_PAGE'); describe('Page parsing', function() { - it('should detection sections', function() { + it('should detect sections', function() { assert.equal(LEXED.length, 4); }); - it('should detection section types', function() { + it('should detect section types', function() { assert.equal(LEXED[0].type, 'normal'); assert.equal(LEXED[1].type, 'exercise'); assert.equal(LEXED[2].type, 'normal'); + assert.equal(QUIZ_LEXED[0].type, 'normal'); + assert.equal(QUIZ_LEXED[1].type, 'quiz'); + assert.equal(QUIZ_LEXED[2].type, 'normal'); }); it('should gen content for normal sections', function() { @@ -35,7 +37,7 @@ describe('Page parsing', function() { it('should make image URLs relative', function() { assert(LEXED[2].content.indexOf('_book/assets/my-pretty-picture.png') !== -1); - }) + }); it('should gen code and content for exercise sections', function() { assert(LEXED[1].content); @@ -64,12 +66,23 @@ describe('Page parsing', function() { it('should detect an exercise\'s language', function() { assert.equal(LEXED[1].lang, 'python'); }); + + it('should render a quiz', function() { + assert(QUIZ_LEXED[1].content); + assert(QUIZ_LEXED[1].quiz); + assert(QUIZ_LEXED[1].quiz[0].base); + assert(QUIZ_LEXED[1].quiz[0].solution); + assert(QUIZ_LEXED[1].quiz[0].feedback); + assert(QUIZ_LEXED[1].quiz[1].base); + assert(QUIZ_LEXED[1].quiz[1].solution); + assert(QUIZ_LEXED[1].quiz[1].feedback); + }); }); describe('Relative links', function() { it('should be resolved to their GitHub counterparts', function() { - var LEXED = page(LINKS_CONTENT, { + var LEXED = loadPage('GITHUB_LINKS', { // GitHub repo ID repo: 'GitBookIO/javascript', |