diff options
author | Jesse Hallett <jesse@galois.com> | 2014-01-06 13:55:04 -0800 |
---|---|---|
committer | Jesse Hallett <jesse@galois.com> | 2014-01-06 14:44:41 -0800 |
commit | dbcf8d56fb0b20d5abb58e20944ee3a79c052f14 (patch) | |
tree | bde8f354b0fa9ba9b6a4517b4dd80d3f557d6c48 | |
parent | 55cd32bfaf9ed5bc5418751369e46fa1d7f098e8 (diff) |
Creates test suite for Wikipedia guidelines
-rw-r--r-- | guidelines/wikipedia/.gitignore | 1 | ||||
-rw-r--r-- | guidelines/wikipedia/Gruntfile.js | 67 | ||||
-rw-r--r-- | guidelines/wikipedia/package.json | 14 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/.jshintrc | 22 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/exports.js | 68 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/fixture_helper.js | 14 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/imageAlt_spec.js | 9 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/prelude_helper.js | 0 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/pseudoHeadings_spec.js | 17 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/rule_helper.js | 22 | ||||
-rw-r--r-- | guidelines/wikipedia/specs/spaceBetweenListItems_spec.js | 29 |
11 files changed, 263 insertions, 0 deletions
diff --git a/guidelines/wikipedia/.gitignore b/guidelines/wikipedia/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/guidelines/wikipedia/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/guidelines/wikipedia/Gruntfile.js b/guidelines/wikipedia/Gruntfile.js new file mode 100644 index 0000000..69f1954 --- /dev/null +++ b/guidelines/wikipedia/Gruntfile.js @@ -0,0 +1,67 @@ +/*global module:false*/ +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + // Metadata. + pkg: grunt.file.readJSON('package.json'), + jshint: { + gruntfile: { + jshintrc: true, + src: 'Gruntfile.js' + }, + src_specs: { + jshintrc: true, + src: ['src/**/*.js', 'test/**/*.js'] + } + }, + jasmine: { + guidelines: { + src: 'src/**/*.js', + options: { + vendor: [ + '../../src/js/lib/underscore.js', + '../../src/js/lib/jquery/jquery-1.8.3.js', + '../../src/js/lib/md5.js', + '../../src/js/fiveui/injected/prelude.js', + '../../src/js/lib/injected/jquery-plugins.js', + '../../src/js/lib/injected/compute.js' + ], + helpers: ['specs/exports.js', 'specs/*_helper.js'], + specs: 'specs/*_spec.js', + host: 'http://localhost:<%= connect.server.options.port %>/guidelines/wikipedia' + } + } + }, + connect: { + server: { + options: { + port: 9867, + base: '../..' + } + } + }, + watch: { + gruntfile: { + files: '<%= jshint.gruntfile.src %>', + tasks: ['jshint:gruntfile'] + }, + src_specs: { + files: '<%= jshint.src_specs.src %>', + tasks: ['jshint:src_specs', 'test'] + } + } + }); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-contrib-connect'); + grunt.loadNpmTasks('grunt-contrib-jasmine'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + + // Default task. + grunt.registerTask('default', ['jshint', 'test']); + + grunt.registerTask('test', ['connect:server', 'jasmine:guidelines']); + +}; diff --git a/guidelines/wikipedia/package.json b/guidelines/wikipedia/package.json new file mode 100644 index 0000000..3817308 --- /dev/null +++ b/guidelines/wikipedia/package.json @@ -0,0 +1,14 @@ +{ + "name": "wikipedia-guidelines", + "license": "BSD-3-Clause", + "engines": { + "node": ">= 0.10.0" + }, + "devDependencies": { + "grunt": "~0.4.2", + "grunt-contrib-jshint": "~0.7.2", + "grunt-contrib-watch": "~0.5.3", + "grunt-contrib-jasmine": "~0.5.2", + "grunt-contrib-connect": "~0.6.0" + } +} diff --git a/guidelines/wikipedia/specs/.jshintrc b/guidelines/wikipedia/specs/.jshintrc new file mode 100644 index 0000000..3643c90 --- /dev/null +++ b/guidelines/wikipedia/specs/.jshintrc @@ -0,0 +1,22 @@ +{ + "laxbreak": true +, "laxcomma": true +, "undef": true +, "jquery": true +, "globals": { + "fiveui": false + , "$5": false + , "exports": false + + , "afterEach": false + , "beforeEach": false + , "describe": false + , "it": false + , "expect": false + , "fixture": true + , "teardownFixtures": true + , "rule": true + , "run": true + } +} + diff --git a/guidelines/wikipedia/specs/exports.js b/guidelines/wikipedia/specs/exports.js new file mode 100644 index 0000000..7dcecbb --- /dev/null +++ b/guidelines/wikipedia/specs/exports.js @@ -0,0 +1,68 @@ +/* + * Defines an `exports` object that can capture names and rules from + * multiple files. Requires a javascript runtime that supports + * ECMAScript 5. + */ +(function (global) { + 'use strict'; + + var exports = {}; + var rules = {}; + var unmatchedName, unmatchedDef; + var lastName, lastDef; + + Object.defineProperty(exports, 'name', { + set: function(name) { + if (unmatchedDef) { + rules[name] = unmatchedDef; + unmatchedDef = null; + } + else { + unmatchedName = name; + } + lastName = name; + }, + + get: function() { + return lastName; + } + }); + + Object.defineProperty(exports, 'rule', { + set: function(def) { + if (unmatchedName) { + rules[unmatchedName] = def; + unmatchedName = null; + } + else { + unmatchedDef = def; + } + lastDef = def; + }, + + get: function() { + return lastDef; + } + }); + + Object.defineProperty(global, 'exports', { + get: function() { + return exports; + }, + + set: function(exp) { + if (exp && typeof exp === 'object' && exp.name && exp.rule) { + rules[exp.name] = exp.rule; + lastName = exp.name; + lastDef = exp.rule; + } + } + }); + + function rule(name) { + return rules[name]; + } + + global.rule = rule; + +}(this)); diff --git a/guidelines/wikipedia/specs/fixture_helper.js b/guidelines/wikipedia/specs/fixture_helper.js new file mode 100644 index 0000000..7c278c1 --- /dev/null +++ b/guidelines/wikipedia/specs/fixture_helper.js @@ -0,0 +1,14 @@ +function fixture(html) { + var $article = $('#mw-content-text'); + if ($article.length === 0) { + $article = $('<div id="mw-content-text"></div>'); + $article.appendTo('body'); + } + var $fix = $(html); + $article.append($fix); + return $fix; +} + +function teardownFixtures() { + $('#mw-content-text').remove(); +} diff --git a/guidelines/wikipedia/specs/imageAlt_spec.js b/guidelines/wikipedia/specs/imageAlt_spec.js new file mode 100644 index 0000000..be91e6f --- /dev/null +++ b/guidelines/wikipedia/specs/imageAlt_spec.js @@ -0,0 +1,9 @@ +describe('imageAlt', function() { + var imageAlt = rule('Images should include an alt attribute'); + + afterEach(teardownFixtures); + + it('succeeds', function() { + expect(true).toBe(true); + }); +}); diff --git a/guidelines/wikipedia/specs/prelude_helper.js b/guidelines/wikipedia/specs/prelude_helper.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/guidelines/wikipedia/specs/prelude_helper.js diff --git a/guidelines/wikipedia/specs/pseudoHeadings_spec.js b/guidelines/wikipedia/specs/pseudoHeadings_spec.js new file mode 100644 index 0000000..effd5e9 --- /dev/null +++ b/guidelines/wikipedia/specs/pseudoHeadings_spec.js @@ -0,0 +1,17 @@ +describe('pseudoHeadings', function() { + var pseudo = rule('Do not make pseudo-headings'); + + afterEach(teardownFixtures); + + it('does not allow paragraphs with all bold text', function() { + var $p = fixture('<p><b>pseudo heading</b></p>'); + var results = run(pseudo); + expect(results.errors.length).toEqual(1); + expect(results.errors[0].element).toEqual($p.find('b').get(0)); + }); + + it('permits paragraphs that include bold and non-bold text', function() { + fixture('<p><b>this paragraph</b> contains non-bold text</p>'); + expect(run(pseudo).errors.length).toEqual(0); + }); +}); diff --git a/guidelines/wikipedia/specs/rule_helper.js b/guidelines/wikipedia/specs/rule_helper.js new file mode 100644 index 0000000..45bcd60 --- /dev/null +++ b/guidelines/wikipedia/specs/rule_helper.js @@ -0,0 +1,22 @@ +function run(rule) { + var warnings = []; + var errors = []; + rule({ + warning: function(msg, elem) { + warnings.push({ + message: msg, + element: elem + }); + }, + error: function(msg, elem) { + errors.push({ + message: msg, + element: elem + }); + } + }); + return { + warnings: warnings, + errors: errors + }; +} diff --git a/guidelines/wikipedia/specs/spaceBetweenListItems_spec.js b/guidelines/wikipedia/specs/spaceBetweenListItems_spec.js new file mode 100644 index 0000000..6ea8a83 --- /dev/null +++ b/guidelines/wikipedia/specs/spaceBetweenListItems_spec.js @@ -0,0 +1,29 @@ +describe('spaceBetweenListItems', function() { + var space = rule('Do not separate list items with blank lines'); + + afterEach(teardownFixtures); + + it('warns of adjacent bullet lists that each have a single item', function() { + fixture('<ul><li>foo</li></ul> <ul><li>bar</li></ul>'); + fixture('<ol><li>foo</li></ol> <ol><li>bar</li></ol>'); + var results = run(space); + expect(results.warnings.length).toEqual(2); + }); + + it('permits adjacent lists of different types with a single item each', function() { + fixture('<ul><li>foo</li></ul> <ol><li>bar</li></ol>'); + expect(run(space).warnings.length).toEqual(0); + }); + + it('warns of adjacent description lists that each have a single dt/dd pair', function() { + fixture('<dl><dt>foo</dt><dd>1</dd></dl> <dl><dt>bar</dt><dd>2</dd></dl>'); + expect(run(space).warnings.length).toEqual(1); + }); + + it('does not warn of adjacent description lists with a single dd or dt', function() { + fixture('<dl><dt>baz</dt><dd>nao</dd></dl>'); + fixture('<dl><dd>Hi there!</dd></dl>'); + fixture('<dl><dt>title</dt></dl>'); + expect(run(space).warnings.length).toEqual(0); + }); +}); |