| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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();
- }, 180));
- });
- 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" );
- assert.equal( _ws.files.length, 2, "_ws.files should hold 2 files" );
- done();
- }, 50);
- });
- QUnit.test( "test adding a collection", function( assert ) {
- var done = assert.async();
- var $addCollectionForm = $('#add-collection-form');
- var $addCollectionBtn = $('#add-collection-btn');
- assert.equal( $addCollectionForm.length, 1, "there should be one #add-collection-form element" );
- assert.equal( $addCollectionBtn.length, 1, "there should be one #add-collection-btn element" );
- $addCollectionBtn.trigger( 'click' );
- assert.ok( $addCollectionForm.is(':visible'), "clicking on #add-collection-btn should make appear the *-form element" );
- done();
- });
- QUnit.test( "test nav back to home", function( assert ) {
- var done = assert.async();
- $homeLink.trigger('click');
- assert.ok( window.location.pathname, '/', "location should be / when clicking app title" );
- timeoutAsync(() => {
- assert.equal( ($menuExample.find('a')).length, 0, "menu example should contain 0 entry" );
- done();
- }, 50);
- });
- });
- })(jQuery);
|