From e5f8cc1bdf0b5ae746c8232c996284bf328fc259 Mon Sep 17 00:00:00 2001 From: Rubens Mariuzzo Date: Sat, 9 Jul 2016 18:04:35 -0400 Subject: [PATCH] Test cases improved. --- Gruntfile.js | 117 +++++++++--------- bower.json | 60 ++++----- package.json | 72 +++++------ src/jquery.checkboxes.js | 9 +- tests/.jshintrc | 3 +- tests/fixtures/checked.html | 65 +++++----- tests/fixtures/mixed.html | 65 +++++----- tests/fixtures/unchecked.html | 65 +++++----- tests/helpers.js | 39 ++++++ tests/specs/jquery_checkboxes_check_spec.js | 58 +++++---- tests/specs/jquery_checkboxes_max_spec.js | 34 +++-- tests/specs/jquery_checkboxes_range_spec.js | 23 +++- tests/specs/jquery_checkboxes_spec.js | 23 +++- tests/specs/jquery_checkboxes_toggle_spec.js | 59 ++++----- tests/specs/jquery_checkboxes_uncheck_spec.js | 58 +++++---- tests/test.html | 14 +-- 16 files changed, 424 insertions(+), 340 deletions(-) create mode 100644 tests/helpers.js diff --git a/Gruntfile.js b/Gruntfile.js index a3455c0..3cce158 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,72 +2,77 @@ module.exports = function (grunt) { - // Load all Grunt tasks. - require('load-grunt-tasks')(grunt); + // Load all Grunt tasks. + require('load-grunt-tasks')(grunt); - // Grunt configuration. - grunt.initConfig({ + // Grunt configuration. + grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), + pkg: grunt.file.readJSON('package.json'), - clean: ['dist'], + clean: ['dist'], - watch: { - scripts: { - files: [ - 'Gruntfile.js', - 'src/**/*.js', - 'tests/specs/**/*.js', - '!.grunt' - ], - tasks: ['jshint', 'jasmine'] - } - }, + watch: { + scripts: { + files: [ + 'Gruntfile.js', + 'src/**/*.js', + 'tests/specs/**/*.js', + 'tests/helpers.js', + '!.grunt' + ], + tasks: ['jshint', 'jasmine'] + } + }, - uglify: { - all: { - files: { - 'dist/jquery.checkboxes-<%= pkg.version %>.min.js': ['src/jquery.checkboxes.js'] + uglify: { + all: { + files: { + 'dist/jquery.checkboxes-<%= pkg.version %>.min.js': ['src/jquery.checkboxes.js'] + }, + options: { + banner: '/*! checkboxes.js v<%= pkg.version %> | ' + + '(c) 2013, <%= grunt.template.today("yyyy") %> Rubens Mariuzzo | ' + + 'http://github.com/rmariuzzo/checkboxes.js/LICENSE */', + } + } }, - options: { - banner: '/*! checkboxes.js v<%= pkg.version %> | ' + - '(c) 2013, <%= grunt.template.today("yyyy") %> Rubens Mariuzzo | ' + - 'http://github.com/rmariuzzo/checkboxes.js/LICENSE */', - } - } - }, - jshint: { - all: { - src: [ - 'Gruntfile.js', - 'src/**/*.js', - 'tests/spec/**/*.js' - ], - options: { - jshintrc: true - } - } - }, + jshint: { + all: { + src: [ + 'Gruntfile.js', + 'src/**/*.js', + 'tests/spec/**/*.js' + ], + options: { + jshintrc: '<%= baseDir %>.jshintrc', + reporterOutput: '' + } + } + }, - jasmine: { - all: { - src: 'src/**/*.js', - options: { - specs: 'tests/specs/*_spec.js', - vendor: [ - 'bower_components/jquery/dist/jquery.min.js', - 'bower_components/jasmine-jquery/lib/jasmine-jquery.js' - ] + jasmine: { + all: { + src: 'src/**/*.js', + options: { + specs: 'tests/specs/*_spec.js', + vendor: [ + 'bower_components/jquery/dist/jquery.min.js', + 'bower_components/jasmine-jquery/lib/jasmine-jquery.js' + ], + helpers: [ + 'tests/helpers.js' + ] + } + } } - } - } - }); + }); - grunt.registerTask('default', ['jshint', 'watch']); - grunt.registerTask('build', ['clean', 'jshint', 'jasmine', 'uglify']); - grunt.registerTask('test', ['jasmine']); - grunt.registerTask('travis', ['jshint', 'jasmine']); + grunt.registerTask('default', ['jshint', 'watch']); + grunt.registerTask('build', ['clean', 'jshint', 'jasmine', 'uglify']); + grunt.registerTask('test', ['jasmine']); + grunt.registerTask('travis', ['jshint', 'jasmine']); }; diff --git a/bower.json b/bower.json index b7c7245..5e02748 100644 --- a/bower.json +++ b/bower.json @@ -1,32 +1,32 @@ { - "name": "checkboxes.js", - "version": "1.0.5", - "homepage": "http://rmariuzzo.github.io/checkboxes.js/", - "authors": [ - "Rubens Mariuzzo " - ], - "description": "A jQuery plugin that give you nice powers over your checkboxes.", - "main": "src/jquery.checkboxes.js", - "keywords": [ - "checkbox", - "checkboxes", - "jquery", - "plugin", - "check", - "uncheck", - "range", - "selection" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "devDependencies": { - "jquery": "~2.1.1", - "jasmine-jquery": "~2.0.3" - } + "name": "checkboxes.js", + "version": "1.0.5", + "homepage": "http://rmariuzzo.github.io/checkboxes.js/", + "authors": [ + "Rubens Mariuzzo " + ], + "description": "A jQuery plugin that give you nice powers over your checkboxes.", + "main": "src/jquery.checkboxes.js", + "keywords": [ + "checkbox", + "checkboxes", + "jquery", + "plugin", + "check", + "uncheck", + "range", + "selection" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "devDependencies": { + "jquery": "~2.1.1", + "jasmine-jquery": "~2.0.3" + } } diff --git a/package.json b/package.json index 00ddd95..e675f7c 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,38 @@ { - "name": "checkboxes.js", - "version": "1.0.6", - "description": "A jQuery plugin that gives you nice powers over your checkboxes.", - "keywords": [ - "checkbox", - "checkboxes", - "range", - "jquery", - "plugin" - ], - "homepage": "https://github.com/rmariuzzo/checkboxes.js", - "bugs": "https://github.com/rmariuzzo/checkboxes.js/issues", - "license": "MIT", - "author": { - "name": "Rubens Mariuzzo", - "email": "rubens@mariuzzo.com", - "url": "https://github.com/rmariuzzo" - }, - "contributors": [], - "main": "dist/jquery.checkboxes-1.0.6.min.js", - "repository": { - "type": "git", - "url": "https://github.com/rmariuzzo/checkboxes.js.git" - }, - "devDependencies": { - "grunt": "~0.4.1", - "grunt-contrib-clean": "^0.6.0", - "grunt-contrib-jasmine": "~0.6.5", - "grunt-contrib-jshint": "~0.10.0", - "grunt-contrib-uglify": "~0.2.2", - "grunt-contrib-watch": "~0.6.1", - "load-grunt-tasks": "~0.4.0" - }, - "scripts": { - "test": "grunt travis --verbose" - } + "name": "checkboxes.js", + "version": "1.0.6", + "description": "A jQuery plugin that gives you nice powers over your checkboxes.", + "keywords": [ + "checkbox", + "checkboxes", + "range", + "jquery", + "plugin" + ], + "homepage": "https://github.com/rmariuzzo/checkboxes.js", + "bugs": "https://github.com/rmariuzzo/checkboxes.js/issues", + "license": "MIT", + "author": { + "name": "Rubens Mariuzzo", + "email": "rubens@mariuzzo.com", + "url": "https://github.com/rmariuzzo" + }, + "contributors": [], + "main": "dist/jquery.checkboxes-1.0.6.min.js", + "repository": { + "type": "git", + "url": "https://github.com/rmariuzzo/checkboxes.js.git" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-clean": "^0.6.0", + "grunt-contrib-jasmine": "~0.6.5", + "grunt-contrib-jshint": "~0.10.0", + "grunt-contrib-uglify": "~0.2.2", + "grunt-contrib-watch": "~0.6.1", + "load-grunt-tasks": "~0.4.0" + }, + "scripts": { + "test": "grunt travis --verbose" + } } diff --git a/src/jquery.checkboxes.js b/src/jquery.checkboxes.js index d55b4cb..1468b37 100644 --- a/src/jquery.checkboxes.js +++ b/src/jquery.checkboxes.js @@ -21,6 +21,7 @@ Checkboxes.prototype.check = function () { this.$context.find(':checkbox') .filter(':not(:disabled)') + .filter(':visible') .prop('checked', true); }; @@ -28,7 +29,7 @@ * Uncheck all checkboxes in context. */ Checkboxes.prototype.uncheck = function () { - this.$context.find(':checkbox') + this.$context.find(':checkbox:visible') .filter(':not(:disabled)') .prop('checked', false); }; @@ -37,7 +38,7 @@ * Toggle the state of all checkboxes in context. */ Checkboxes.prototype.toggle = function () { - this.$context.find(':checkbox') + this.$context.find(':checkbox:visible') .filter(':not(:disabled)') .each(function () { var $checkbox = $(this); @@ -63,7 +64,7 @@ }); } else { // Disable max. - this.$context.off('click.checkboxes'); + this.$context.off('click.checkboxes.max'); } }; @@ -80,7 +81,7 @@ var $checkbox = $(event.target); if (event.shiftKey && instance.$last) { - var $checkboxes = instance.$context.find(':checkbox'); + var $checkboxes = instance.$context.find(':checkbox:visible'); var from = $checkboxes.index(instance.$last); var to = $checkboxes.index($checkbox); var start = Math.min(from, to); diff --git a/tests/.jshintrc b/tests/.jshintrc index 2451208..7a7cc4a 100644 --- a/tests/.jshintrc +++ b/tests/.jshintrc @@ -22,6 +22,7 @@ "spyOn": true, "jasmine": true, "$": true, - "loadFixtures": true + "loadFixtures": true, + "setupContext": true, } } diff --git a/tests/fixtures/checked.html b/tests/fixtures/checked.html index afd4bb8..298d116 100644 --- a/tests/fixtures/checked.html +++ b/tests/fixtures/checked.html @@ -1,38 +1,43 @@ + + - - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
- \ No newline at end of file + + diff --git a/tests/fixtures/mixed.html b/tests/fixtures/mixed.html index 778d552..a1aa417 100644 --- a/tests/fixtures/mixed.html +++ b/tests/fixtures/mixed.html @@ -1,38 +1,43 @@ + + - - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
- \ No newline at end of file + + diff --git a/tests/fixtures/unchecked.html b/tests/fixtures/unchecked.html index 4a21bf3..ccc7d95 100644 --- a/tests/fixtures/unchecked.html +++ b/tests/fixtures/unchecked.html @@ -1,38 +1,43 @@ + + - - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
- - +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
- \ No newline at end of file + + diff --git a/tests/helpers.js b/tests/helpers.js new file mode 100644 index 0000000..b58bf09 --- /dev/null +++ b/tests/helpers.js @@ -0,0 +1,39 @@ +/** + * Setup checkbox context for testing purposes. + * + * @return {Object} The setup context. + */ +function setupContext() { + + var context = {}; + + /** + * The original context. + * @type {Object} + */ + context.original = $('#context'); + + /** + * The modified context. + * @return {Object} + */ + context.modified = context.original.clone() + .prop('id', 'modified-context') + .insertAfter(context.original); + + /** + * Iterate each checkbox from the original and modified context by index. + * @param {Function} fn The function to run for each cycle. + */ + context.each = function (fn) { + context.original.find(':checkbox').each(function (index) { + var original = $(this); + var modified = $(context.modified.find(':checkbox').get(index)); + var originalState = original.prop('checked'); + var modifiedState = modified.prop('checked'); + fn.call(null, original, modified, originalState, modifiedState, index); + }); + }; + + return context; +} diff --git a/tests/specs/jquery_checkboxes_check_spec.js b/tests/specs/jquery_checkboxes_check_spec.js index 11375f5..cceb46a 100644 --- a/tests/specs/jquery_checkboxes_check_spec.js +++ b/tests/specs/jquery_checkboxes_check_spec.js @@ -1,45 +1,43 @@ +// Setup Jasmine's fixtures path. + jasmine.getFixtures().fixturesPath = 'tests/fixtures'; +// Spec description. + describe('The `check` method', function () { 'use strict'; - it('should exists', function () { - loadFixtures('unchecked.html'); - var el = $('body').checkboxes(); - expect(el.data('checkboxes').check).toBeDefined(); - }); + // Load fixtures and setup the testing contexts before each specs. - it('should be a function', function () { - loadFixtures('unchecked.html'); - var el = $('body').checkboxes(); - expect(typeof el.data('checkboxes').check).toBe('function'); + var ctx; + + beforeEach(function () { + loadFixtures('checked.html'); + ctx = setupContext(); }); - it('should check all checkboxes in context', function () { - loadFixtures('unchecked.html'); - var el = $('body').checkboxes('check'); - expect(el.find(':checkbox')).toBeChecked(); + // Spec definitions. + + it('should exists', function () { + expect(ctx.original.checkboxes().data('checkboxes').check).toBeDefined(); }); - it('should check specified checkbox', function () { - // Check first checkbox. - loadFixtures('unchecked.html'); - var el = $(':checkbox:first').parent().checkboxes('check'); - expect(el.find(':checkbox:first')).toBeChecked(); - expect(el.find(':checkbox:not(:first)')).toBeChecked(); - - // Check last checkbox. - loadFixtures('unchecked.html'); - el = $(':checkbox:last').parent().checkboxes('check'); - expect(el.find(':checkbox:last')).toBeChecked(); - expect(el.find(':checkbox:not(:last)')).toBeChecked(); + it('should be a function', function () { + expect(typeof ctx.original.checkboxes().data('checkboxes').check).toBe('function'); }); - it('should check all checkboxes in context, but no disabled ones', function () { - loadFixtures('unchecked.html'); - var el = $('body').checkboxes('check'); - expect(el.find(':checkbox:disabled')).not.toBeChecked(); - expect(el.find(':checkbox:not(:disabled)')).toBeChecked(); + it('should check all visible and enabled checkboxes in context', function () { + // Check all checkboxes in context. + ctx.modified.checkboxes('check'); + + // Ensure all checkboxes were checked as expected. + ctx.each(function (original, modified, originalState, modifiedState) { + if (!original.is(':disabled') && original.is(':visible')) { + expect(modified).toBeChecked(); + } else { + expect(modifiedState).toBe(originalState); + } + }); }); }); diff --git a/tests/specs/jquery_checkboxes_max_spec.js b/tests/specs/jquery_checkboxes_max_spec.js index 9d8501c..1d655b5 100644 --- a/tests/specs/jquery_checkboxes_max_spec.js +++ b/tests/specs/jquery_checkboxes_max_spec.js @@ -1,28 +1,40 @@ +// Setup Jasmine's fixtures path. + jasmine.getFixtures().fixturesPath = 'tests/fixtures'; +// Spec description. + describe('The `max` method', function () { 'use strict'; + // Load fixtures and setup the testing contexts before each specs. + + var ctx; + + beforeEach(function () { + loadFixtures('unchecked.html'); + ctx = setupContext(); + }); + + // Spec definitions. + it('should exists', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes(); - expect(el.data('checkboxes').max).toBeDefined(); + expect(ctx.original.checkboxes().data('checkboxes').max).toBeDefined(); }); it('should be a function', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes(); - expect(typeof el.data('checkboxes').max).toBe('function'); + expect(typeof ctx.original.checkboxes().data('checkboxes').max).toBe('function'); }); it('should limit the number of checked checkboxes in context', function () { - loadFixtures('unchecked.html'); - var context = $('body'); - context.checkboxes('max', 3); - context.find(':checkbox').each(function (i) { + ctx.modified.checkboxes('max', 7); + + // Click all checkboxes. + ctx.modified.find(':checkbox').each(function (i) { $(this).click(); - expect($(this).prop('checked')).toBe(i < 3); // The first three should be checked. }); + + expect(ctx.modified.find(':checkbox:checked').length, 7); }); }); diff --git a/tests/specs/jquery_checkboxes_range_spec.js b/tests/specs/jquery_checkboxes_range_spec.js index f47c425..3941c9a 100644 --- a/tests/specs/jquery_checkboxes_range_spec.js +++ b/tests/specs/jquery_checkboxes_range_spec.js @@ -1,18 +1,29 @@ +// Setup Jasmine's fixtures path. + jasmine.getFixtures().fixturesPath = 'tests/fixtures'; +// Spec description. + describe('The `range` method', function () { 'use strict'; + // Load fixtures and setup the testing contexts before each specs. + + var ctx; + + beforeEach(function () { + loadFixtures('mixed.html'); + ctx = setupContext(); + }); + + // Spec definitions. + it('should exists', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes(); - expect(el.data('checkboxes').range).toBeDefined(); + expect(ctx.original.checkboxes().data('checkboxes').range).toBeDefined(); }); it('should be a function', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes(); - expect(typeof el.data('checkboxes').range).toBe('function'); + expect(typeof ctx.original.checkboxes().data('checkboxes').range).toBe('function'); }); }); diff --git a/tests/specs/jquery_checkboxes_spec.js b/tests/specs/jquery_checkboxes_spec.js index fdf60d1..19514ca 100644 --- a/tests/specs/jquery_checkboxes_spec.js +++ b/tests/specs/jquery_checkboxes_spec.js @@ -1,8 +1,23 @@ +// Setup Jasmine's fixtures path. + jasmine.getFixtures().fixturesPath = 'tests/fixtures'; +// Spec description. + describe('The jQuery checkboxes plugin', function () { 'use strict'; + // Load fixtures and setup the testing contexts before each specs. + + var ctx; + + beforeEach(function () { + loadFixtures('mixed.html'); + ctx = setupContext(); + }); + + // Spec definitions. + it('should exists', function () { expect($.fn.checkboxes).toBeDefined(); }); @@ -12,15 +27,11 @@ describe('The jQuery checkboxes plugin', function () { }); it('should create an instance in $.data', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes(); - expect(el.data('checkboxes')).toBeDefined(); + expect(ctx.original.checkboxes().data('checkboxes')).toBeDefined(); }); it('should not create an instance in $.data with empty element set', function () { - loadFixtures('checked.html'); - var el = $().checkboxes(); - expect(el.data('checkboxes')).not.toBeDefined(); + expect($().checkboxes().data('checkboxes')).not.toBeDefined(); }); }); diff --git a/tests/specs/jquery_checkboxes_toggle_spec.js b/tests/specs/jquery_checkboxes_toggle_spec.js index b442d49..eccb0da 100644 --- a/tests/specs/jquery_checkboxes_toggle_spec.js +++ b/tests/specs/jquery_checkboxes_toggle_spec.js @@ -1,49 +1,42 @@ +// Setup Jasmine's fixtures path. + jasmine.getFixtures().fixturesPath = 'tests/fixtures'; +// Spec description. + describe('The `toggle` method', function () { 'use strict'; - it('should exists', function () { - loadFixtures('mixed.html'); - var el = $('body').checkboxes(); - expect(el.data('checkboxes').toggle).toBeDefined(); - }); + // Load fixtures and setup the testing contexts before each specs. - it('should be a function', function () { - loadFixtures('mixed.html'); - var el = $('body').checkboxes(); - expect(typeof el.data('checkboxes').toggle).toBe('function'); - }); + var ctx; - it('should toggle all checkboxes in context', function () { + beforeEach(function () { loadFixtures('mixed.html'); - var original = $('body').clone(); - var modified = $('body').checkboxes('toggle'); - modified.find(':checkbox:not(:disabled)').each(function (i) { - expect($(this).prop('checked')).not.toBe(original.find(':checkbox:not(:disabled)').eq(i).prop('checked')); - }); + ctx = setupContext(); }); - it('should toggle specified checkbox', function () { - // Check first checkbox. - loadFixtures('mixed.html'); - var original = $(':checkbox:first').clone(); - var modified = $(':checkbox:first').parent().checkboxes('toggle'); - expect(modified.find(':checkbox:first').prop('checked')).not.toBe(original.prop('checked')); + // Spec definitions. - // Check last checkbox. - loadFixtures('mixed.html'); - original = $(':checkbox:last').clone(); - modified = $(':checkbox:last').parent().checkboxes('toggle'); - expect(modified.find(':checkbox:last').prop('checked')).not.toBe(original.prop('checked')); + it('should exists', function () { + expect(ctx.original.checkboxes().data('checkboxes').toggle).toBeDefined(); }); - it('should toggle all checkboxes in context, but no disabled ones', function () { - loadFixtures('mixed.html'); - var original = $('body').clone(); - var modified = $('body').checkboxes('toggle'); - modified.find(':checkbox:disabled').each(function (i) { - expect($(this).prop('checked')).toBe(original.find(':checkbox:disabled').eq(i).prop('checked')); + it('should be a function', function () { + expect(typeof ctx.original.checkboxes().data('checkboxes').toggle).toBe('function'); + }); + + it('should toggle all visible and enabled checkboxes in context', function () { + // Toggle all checkboxes in context. + ctx.modified.checkboxes('toggle'); + + // Ensure all checkboxes were toggled as expected. + ctx.each(function (original, modified, originalState, modifiedState) { + if (!original.is(':disabled') && original.is(':visible')) { + expect(modifiedState).not.toBe(originalState); + } else { + expect(modifiedState).toBe(originalState); + } }); }); diff --git a/tests/specs/jquery_checkboxes_uncheck_spec.js b/tests/specs/jquery_checkboxes_uncheck_spec.js index b926754..92c4b44 100644 --- a/tests/specs/jquery_checkboxes_uncheck_spec.js +++ b/tests/specs/jquery_checkboxes_uncheck_spec.js @@ -1,45 +1,43 @@ +// Setup Jasmine's fixtures path. + jasmine.getFixtures().fixturesPath = 'tests/fixtures'; +// Spec description. +// describe('The `uncheck` method', function () { 'use strict'; - it('should exists', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes(); - expect(el.data('checkboxes').uncheck).toBeDefined(); - }); + // Load fixtures and setup the testing contexts before each specs. - it('should be a function', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes(); - expect(typeof el.data('checkboxes').uncheck).toBe('function'); + var ctx; + + beforeEach(function () { + loadFixtures('mixed.html'); + ctx = setupContext(); }); - it('should uncheck all checkboxes in context', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes('uncheck'); - expect(el.find(':checkbox:not(:disabled)')).not.toBeChecked(); + // Spec definitions. + + it('should exists', function () { + expect(ctx.original.checkboxes().data('checkboxes').uncheck).toBeDefined(); }); - it('should uncheck specified checkbox', function () { - // Check first checkbox. - loadFixtures('checked.html'); - var el = $(':checkbox:first').parent().checkboxes('uncheck'); - expect(el.find(':checkbox:first')).not.toBeChecked(); - expect(el.find(':checkbox:not(:first)')).toBeChecked(); - - // Check last checkbox. - loadFixtures('checked.html'); - el = $(':checkbox:last').parent().checkboxes('uncheck'); - expect(el.find(':checkbox:last')).not.toBeChecked(); - expect(el.find(':checkbox:not(:last)')).toBeChecked(); + it('should be a function', function () { + expect(typeof ctx.original.checkboxes().data('checkboxes').uncheck).toBe('function'); }); - it('should check all checkboxes in context, but no disabled ones', function () { - loadFixtures('checked.html'); - var el = $('body').checkboxes('uncheck'); - expect(el.find(':checkbox:disabled')).toBeChecked(); - expect(el.find(':checkbox:not(:disabled)')).not.toBeChecked(); + it('should uncheck all visible and enabled checkboxes in context', function () { + // Uncheck all checkboxes in context. + ctx.modified.checkboxes('uncheck'); + + // Ensure all checkboxes were unchecked as expected. + ctx.each(function (original, modified, originalState, modifiedState) { + if (!original.is(':disabled') && original.is(':visible')) { + expect(modified).not.toBeChecked(); + } else { + expect(modifiedState).toBe(originalState); + } + }); }); }); diff --git a/tests/test.html b/tests/test.html index 54caee6..3dcd45c 100644 --- a/tests/test.html +++ b/tests/test.html @@ -3,13 +3,13 @@ Document - +
@@ -23,7 +23,7 @@
- +
@@ -41,10 +41,10 @@
- Check all - Uncheck all - \ No newline at end of file +