jquery.pep_test.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*global QUnit:false, module:false, test:false, asyncTest:false, expect:false*/
  2. /*global start:false, stop:false ok:false, equal:false, notEqual:false, deepEqual:false*/
  3. /*global notDeepEqual:false, strictEqual:false, notStrictEqual:false, raises:false*/
  4. (function($) {
  5. /*
  6. ======== A Handy Little QUnit Reference ========
  7. http://docs.jquery.com/QUnit
  8. Test methods:
  9. expect(numAssertions)
  10. stop(increment)
  11. start(decrement)
  12. Test assertions:
  13. ok(value, [message])
  14. equal(actual, expected, [message])
  15. notEqual(actual, expected, [message])
  16. deepEqual(actual, expected, [message])
  17. notDeepEqual(actual, expected, [message])
  18. strictEqual(actual, expected, [message])
  19. notStrictEqual(actual, expected, [message])
  20. raises(block, [expected], [message])
  21. */
  22. module('jQuery#pep', {
  23. setup: function() {
  24. this.elems = $('#qunit-fixture').children();
  25. }
  26. });
  27. test('is chainable', 1, function() {
  28. // Not a bad test to run on collection methods.
  29. strictEqual(this.elems.pep(), this.elems, 'should be chainable');
  30. });
  31. test('plugin name', 1, function() {
  32. var $el = $( '#qunit-fixture span' ).first();
  33. $el.pep();
  34. strictEqual($el.data('plugin_pep').name, 'pep', 'plugin name should be Pep');
  35. });
  36. test('toggle pep object', 1, function() {
  37. var $el = $( '#qunit-fixture span' ).first();
  38. $el.pep();
  39. $el.data('plugin_pep').toggle()
  40. strictEqual($el.first().data('plugin_pep').disabled, true, 'this.disable variable should be true when toggled once');
  41. });
  42. test('explicit toggle pep object', 1, function() {
  43. var $el = $( '#qunit-fixture span' ).first();
  44. $el.pep();
  45. $el.data('plugin_pep').toggle(false) // false === disable
  46. strictEqual($el.first().data('plugin_pep').disabled, true, 'this.disable variable should be true when toggled off explicitly');
  47. });
  48. test('toggle via api - once', 1, function() {
  49. var $el = $( '#qunit-fixture span' );
  50. $el.pep();
  51. $.pep.toggleAll()
  52. strictEqual($el.first().data('plugin_pep').disabled, true, 'this.disable variable should be true when toggled once');
  53. });
  54. test('toggle via api - twice', 1, function() {
  55. var $el = $( '#qunit-fixture span' );
  56. $el.pep();
  57. $.pep.toggleAll()
  58. $.pep.toggleAll()
  59. strictEqual($el.first().data('plugin_pep').disabled, false, 'this.disable variable should be false when toggled twice');
  60. });
  61. test('activeDropRegions initially declared', 2, function() {
  62. var $el = $( '#qunit-fixture span' );
  63. $el.pep();
  64. ok($el.data('plugin_pep').activeDropRegions, '`activeDropRegions` property is defined');
  65. equal($el.data('plugin_pep').activeDropRegions.length, 0, '`activeDropRegions` property is initialized with length 0');
  66. });
  67. }(jQuery));