From ec3b8a8c3bc61c057c4c43ce538f6c50aa87e0c5 Mon Sep 17 00:00:00 2001 From: Amanpreet Singh Date: Sun, 26 Apr 2015 13:34:49 +0530 Subject: [PATCH] Complete tests for the repo --- tests/test.js | 21 ++++++++++++++++++--- tests/utils.js | 29 ++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/tests/test.js b/tests/test.js index 0133590..c0de69f 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,14 +1,29 @@ -var assert = require('assert') +var assert = require('chai').assert, utils = require('./utils'); var $ = utils.getSelectorObject(); describe('Main module', function () { - it('should contain a link for all title', function () { + it('should contain a non-duplicate link for all title', function () { + var links = []; + $('a').each(function (k) { + var href = $(this).attr('href'); + + assert.isDefined(href, 'Expected href for ' + $(this).html()); + + if (links[href]) { + console.log(href); + assert.ok(false, 'Duplicate link for ' + $(this).html()); + } + + links[href] = true; + }); }); it('should be sorted alphabetically', function () { - + $('ul').each(function () { + utils.testList(assert, $, $(this)); + }) }); }) \ No newline at end of file diff --git a/tests/utils.js b/tests/utils.js index fdbb651..9ee15d7 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -3,10 +3,33 @@ var fs = require('fs'), cheerio = require('cheerio'); module.exports = (function () { - return { + var utils = { getSelectorObject: function () { - var html = marked(fs.readFileSync('../README.md')); + var html = marked(fs.readFileSync('./README.md', 'utf-8')); return cheerio.load(html); }, - } + + testList: function (assert, $, list) { + var self = this; + + list.find('ul').each(function () { + utils.testList(assert, $, $(this)); + $(this).remove('ul'); + }); + self.testAlphabetical(assert, $, list); + }, + + testAlphabetical: function (assert, $, list) { + var items = []; + list.find("li > a:first-child").map(function (i) { + items.push($(this).text().toLowerCase()); + }); + + sorted = items.slice().sort(); + + assert.deepEqual(items, sorted, 'Links should be in alphabetical order'); + } + }; + + return utils; })(); \ No newline at end of file