Permalink
Browse files

Updated tests

  • Loading branch information...
1 parent 6b36b73 commit b5b475d33a4da63f412d92d4b8b665dfd24c86e8 @tefra committed Jul 9, 2013
Showing with 38 additions and 48 deletions.
  1. +38 −48 test/navgoco.js
View
86 test/navgoco.js
@@ -1,91 +1,81 @@
(function($) {
var menu, first, li;
var html = arrayToUl(links);
+
+ function getVisible() {
+ var result = [];
+ menu.find('ul').filter(':visible').each(function() {
+ result.push($(this).attr('data-index'));
+ });
+ return result;
+ }
+
module('#navgoco', {
// This will run before each test in this module.
setup: function() {
menu = $('<ul>' + html + '</ul>');
menu.appendTo($('#qunit-fixture'));
first = menu.find("li:has(ul) > a").first();
li = first.parent();
+ $.fn.navgoco.defaults.save = false;
+ $.fn.navgoco.defaults.slide.duration = 1;
}
});
- test('test chainability', function() {
- strictEqual(menu.navgoco({save: false}), menu, 'should be chainable');
+ test('chainability', function() {
+ strictEqual(menu.navgoco(), menu, 'should be chainable');
+
+ });
+ test('caret', function() {
+ expect(1);
+ menu.navgoco();
+ var link = menu.find("li:has(ul) > a").last();
+ strictEqual(link.html(), 'Where to Buy<span class="caret"></span>', 'caret should be present');
});
- test('test mouse click', function() {
+ test('mouse click', function() {
expect(2);
- menu.navgoco({save: false});
+ menu.navgoco();
first.click();
ok(li.hasClass('open'), 'should have class open');
first.click();
ok(!li.hasClass('open'), 'should not have class open');
});
- test('test manual toggle', function() {
+ test('manual toggle', function() {
expect(2);
- menu.navgoco({save: false});
+ menu.navgoco();
menu.navgoco('toggle', true, 0);
ok(li.hasClass('open'), 'should have class open');
menu.navgoco('toggle', false, 0);
ok(!li.hasClass('open'), 'should not have class open');
});
- test('test manual toggle to also open parents', function() {
+ test('manual toggle also opens parents', function() {
expect(1);
- menu.navgoco({save: false});
+ menu.navgoco();
menu.navgoco('toggle', true, 3);
- var expected = ['1', '3'];
- var result = [];
-
- menu.find('ul').each(function() {
- var sub = $(this);
- if (sub.parent().hasClass('open')) {
- result.push(sub.attr('data-index'));
- }
- });
-
- deepEqual(result, expected, 'Both sub-menus 1 and 3 should be visible');
+ deepEqual(getVisible(), ['1', '3'], 'Both sub-menus 1 and 3 should be visible');
});
- test('test toggle all', function() {
+ test('manual toggle all', function() {
expect(1);
- menu.navgoco({save: false});
+ menu.navgoco();
menu.navgoco('toggle', true);
- var expected = ['0', '1', '2', '3', '4'];
- var result = [];
-
- menu.find('ul').each(function() {
- result.push($(this).attr('data-index'));
- });
-
- deepEqual(result, expected, 'All sub-menus should be visible');
+ deepEqual(getVisible(), ['0', '1', '2', '3', '4'], 'All sub-menus should be visible');
});
- test('test accordion', function() {
+ test('accordion', function() {
expect(1);
- menu.navgoco({save: false, accordion: true});
+ menu.navgoco({accordion: true});
menu.navgoco('toggle', true, 0);
menu.navgoco('toggle', true, 1);
- menu.navgoco('toggle', true, 4);
-
- var expected = ['4'];
- var result = [];
-
- menu.find('ul').each(function() {
- var sub = $(this);
- if (sub.parent().hasClass('open')) {
- result.push(sub.attr('data-index'));
- }
- });
-
-
-
- deepEqual(result, expected, 'Only submenus 1 and 2 should be visible');
+ menu.navgoco('toggle', true, 0);
+ stop();
+ setTimeout(function() {
+ deepEqual(getVisible(), ['0'], 'Only submenus 0 should be visible');
+ start();
+ }, 1000);
});
-
-
}(jQuery));

0 comments on commit b5b475d

Please sign in to comment.