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'); var $editor = $('#editor'); var $editorTabs = $('#tabs'); QUnit.test( "hello test", function( assert ) { assert.ok( 1 == "1", "Passed!" ); }); QUnit.test( "initial state", function( assert ) { assert.equal( _ws.files.length, 0, "_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( ($menuRepo.find('a')).length, 2, "menu repo should contain 2 links" ); assert.ok( $menuExample.is(':visible'), "menu example visible (though menu is hidden AND menu empty)" ); assert.equal( ($menuExample.find('a')).length, 0, "menu example should contain 0 links" ); assert.ok( ! $editor.is(':visible'), "editor invisible" ); assert.ok( ! $editorTabs.is(':visible'), "editor tabs invisible" ); }); 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'" ); }, 120) .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 ) { var done = assert.async(); assert.equal( window.location.pathname, '/', "location should be / at first" ); $linkToRepo1.trigger('click'); assert.equal( window.location.pathname, '/example-repo1' ); timeoutAsync(() => { assert.equal( ($menuExample.find('a')).length, 1, "menu example should contain 1 entry" ); assert.equal( $menuExample.find('a:first').html(), "Test Example", "link to 1st example should be labelled 'Test Example'" ); done(); }, 100); }); QUnit.test( "test nav to example", function( assert ) { var done = assert.async(); assert.equal( ($menuExample.find('a')).length, 1, "menu example should contain 1 entry" ); var $linkToExmp1 = $menuExample.find('a:first'); $linkToExmp1.trigger('click'); assert.equal( window.location.pathname, '/example-repo1/repo1-example1', "location should be /example-repo1/repo1-example1" ); timeoutAsync(() => { assert.ok( $editor.is(':visible'), "editor visible" ); done(); }, 50); }); 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);