aboutsummaryrefslogtreecommitdiff
path: root/src/js/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/tests')
-rw-r--r--src/js/tests/README.md9
-rw-r--r--src/js/tests/specs/jquery-plugins.js62
-rw-r--r--src/js/tests/specs/rules.js8
3 files changed, 68 insertions, 11 deletions
diff --git a/src/js/tests/README.md b/src/js/tests/README.md
index dbd8435..1127a70 100644
--- a/src/js/tests/README.md
+++ b/src/js/tests/README.md
@@ -9,7 +9,7 @@ In Browser
----------
Start a local webserver at the FiveUI project root ($FIVEUI_ROOT) and load
-`contexts/data/tests/SpecRunner.html`.
+`src/js/tests/SpecRunner.html`.
Headless
--------
@@ -22,9 +22,8 @@ Install [phantomjs](http://phantomjs.org/) on your system.
Run:
- $ cd contexts/data
- $ phantomjs lib/phantomjs_jasmine/phantomjs_jasminexml_runner.js \
- tests/PhantomJSJasmineRunner.html tests/reports/
+ $ phantomjs ../lib/phantomjs_jasmine/phantomjs_jasminexml_runner.js \
+ PhantomJSJasmineRunner.html reports/
XML test reports will be generated in
-`$FIVEUI_ROOT/contexts/data/tests/reports/`.
+`$FIVEUI_ROOT/src/js/tests/reports/`.
diff --git a/src/js/tests/specs/jquery-plugins.js b/src/js/tests/specs/jquery-plugins.js
index 7fc196b..2f33b1a 100644
--- a/src/js/tests/specs/jquery-plugins.js
+++ b/src/js/tests/specs/jquery-plugins.js
@@ -86,7 +86,34 @@ describe('jQuery plugins', function () {
});
it('filters out everything', function () {
- expect($t.notColorSet(['#ffffff', '#000000', '#e1e1e1']).length).toEqual(0);
+ expect(
+ $t.notColorSet(['#ffffff', '#000000', '#e1e1e1']).length).toEqual(0
+ );
+ });
+ });
+
+ describe('fiveui.jquery.cssIs', function () {
+ var htm = '<p style="color: #000000; background-color: #232323">foo</p>' +
+ '<p style="color: #ffffff; font-size: 5em">foo</p>' +
+ '<p style="color: #e1e1e1; background-color: #141414">foo</p>' +
+ '<p style="color: #ffffff">foo</p>' +
+ '<h1 style="color: #ffffff; font-size: 5em">big</h1>';
+ var $t = $(htm);
+
+ it('filters out colors', function () {
+ expect($t.cssIs('color',
+ ['#ffffff', '#000000'],
+ fiveui.color.colorToHexWithDefault).length).toEqual(4);
+ });
+
+ it('filters out background-colors', function () {
+ expect($t.cssIs('background-color',
+ ['#141414', '#232323'],
+ fiveui.color.colorToHexWithDefault).length).toEqual(2);
+ });
+
+ it('filters out elements of different type', function () {
+ expect($t.cssIs('font-size', ['5em']).length).toEqual(2);
});
});
@@ -99,11 +126,15 @@ describe('jQuery plugins', function () {
var $t = $(htm);
it('filters out colors', function () {
- expect($t.cssIsNot('color', ['#ffffff', '#000000'], fiveui.color.colorToHexWithDefault).length).toEqual(1);
+ expect($t.cssIsNot('color',
+ ['#ffffff', '#000000'],
+ fiveui.color.colorToHexWithDefault).length).toEqual(1);
});
it('filters out background-colors', function () {
- expect($t.cssIsNot('background-color', ['#141414', '#232323'], fiveui.color.colorToHexWithDefault).length).toEqual(3);
+ expect($t.cssIsNot('background-color',
+ ['#141414', '#232323'],
+ fiveui.color.colorToHexWithDefault).length).toEqual(3);
});
it('filters out elements of different type', function () {
@@ -111,6 +142,31 @@ describe('jQuery plugins', function () {
});
});
+ describe('fiveui.jquery.attrFilter', function () {
+ var isEmpty = function (s) { return $.trim(s) == ""; };
+
+ it('filters for zero elements with empty alt', function () {
+ var $elt = $('<a href="foo" alt="bar"><a href="beel" alt="bar">');
+ expect($elt.attrFilter('alt', isEmpty).length).toEqual(0);
+ });
+
+ it('filters for one element with empty alt', function () {
+ var $elt = $('<a href="foo" alt=""><a href="beel" alt="bar">');
+ expect($elt.attrFilter('alt', isEmpty).length).toEqual(1);
+ });
+
+ it('filters out elements that don\'t have the attribute', function () {
+ var $elt = $('<a href="foo"><a href="beel">');
+ expect($elt.attrFilter('alt', isEmpty).length).toEqual(0);
+ });
+
+ it('filters for elements with alt containing foo', function () {
+ var hasFoo = function (s) { return /foo/.test(s); };
+ var $elt = $('<a href="foo" alt="barfoo"><a href="beel" alt="bar">');
+ expect($elt.attrFilter('alt', hasFoo).length).toEqual(1);
+ });
+ });
+
describe('fiveui.jquery.linksTo', function () {
it('filters out elements with no href', function () {
expect($('<p>foo</p>').linksTo('bar').length).toEqual(0);
diff --git a/src/js/tests/specs/rules.js b/src/js/tests/specs/rules.js
index 518cfc9..b863037 100644
--- a/src/js/tests/specs/rules.js
+++ b/src/js/tests/specs/rules.js
@@ -3,7 +3,7 @@ describe('fiveui.Rules', function() {
it('round trips via JSON', function() {
- var ruleIn = new fiveui.Rule({
+ var ruleIn = new fiveui.RuleSet({
id: 42,
name: 'testRule',
description: 'see: http://test.description/',
@@ -11,7 +11,7 @@ describe('fiveui.Rules', function() {
var jsonRule = JSON.stringify(ruleIn);
- var ruleOut = fiveui.Rule.fromJSON(JSON.parse(jsonRule));
+ var ruleOut = fiveui.RuleSet.fromJSON(42, JSON.parse(jsonRule));
expect(ruleOut.id).toBe(ruleIn.id);
expect(ruleOut.name).toBe(ruleIn.name);
@@ -50,7 +50,9 @@ describe('fiveui.RuleSet', function() {
var ruleSet = new fiveui.RuleSet({
id: 42,
name: 'rule set',
- description: 'desc', [rule1, rule2],
+ description: 'desc',
+ rules: ['rule1', 'rule2'],
+ dependencies: ['dep1', 'dep2']
});
var jsonSet = JSON.stringify(ruleSet);