function timeoutAsync(cb, delay) { return new Promise((resolve, reject) => { setTimeout(function() { cb(); resolve(true); }, delay); }); } (function($) { $(document).ready(function() { var $mainMenu = $('#nav-menus'); var $menuRepo = $('#menu-repo'); var $linkToRepo1 = $menuRepo.find('a:first'); var $menuExample = $('#menu-example'); var $menuBtn = $('#menu-btn'); var $homeLink = $('#nav-back-home'); QUnit.test( "hello test", function( assert ) { assert.ok( 1 == "1", "Passed!" ); }); QUnit.test( "initial state", function( assert ) { assert.equal( 0, _ws.files.length, "_ws.files should hold 0 file when app started from root" ); assert.ok( $menuRepo.is(':visible'), "menu repo visible (though menu is hidden)" ); assert.equal( 2, ($menuRepo.find('a')).length, "menu repo should contain 2 links" ); assert.ok( $menuExample.is(':visible'), "menu example visible (though menu is hidden AND menu empty)" ); assert.equal( 0, ($menuExample.find('a')).length, "menu example should contain 0 links" ); }); QUnit.test( "test menu toggle", function( assert ) { var done = assert.async(); assert.equal( $mainMenu.width(), 0, "0. INIT width should be 0" ); assert.ok( $mainMenu.is(':visible'), "0. INIT menu should NOT have class 'in'" ); $menuBtn.trigger('click'); assert.ok( $mainMenu.hasClass('in'), "1.AFTER CLICK menu should have class 'in'" ); assert.ok( $mainMenu.is(':visible'), "1.AFTER CLICK menu should be visible" ); timeoutAsync(() => { assert.notEqual( $mainMenu.width(), 0, "1.AFTER CLICK menu should have width > 0" ); $menuBtn.trigger('click'); assert.ok( ! $mainMenu.hasClass('in'), "2.AFTER 2ND CLICK menu should NOT have class 'in'" ); }, 100) .then(() => timeoutAsync(() => { assert.equal( $mainMenu.width(), 0, "2.AFTER 2ND CLICK width should be 0" ); done(); }, 160)); }); QUnit.test( "test nav to repo", function( assert ) { assert.equal( window.location.pathname, '/', "location should be / at first" ); $linkToRepo1.trigger('click'); assert.equal( window.location.pathname, '/example-repo1' ); }); QUnit.test( "test nav back to home", function( assert ) { $homeLink.trigger('click'); assert.ok( window.location.pathname, '/', "location should be / when clicking app title" ); }); }); })(jQuery);