ws.test.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. function timeoutAsync(cb, delay) {
  2. return new Promise((resolve, reject) => {
  3. setTimeout(function() {
  4. cb();
  5. resolve(true);
  6. }, delay);
  7. });
  8. }
  9. (function($) {
  10. $(document).ready(function() {
  11. var $mainMenu = $('#nav-menus');
  12. var $menuRepo = $('#menu-repo');
  13. var $linkToRepo1 = $menuRepo.find('a:first');
  14. var $menuExample = $('#menu-example');
  15. var $menuBtn = $('#menu-btn');
  16. var $homeLink = $('#nav-back-home');
  17. QUnit.test( "hello test", function( assert ) {
  18. assert.ok( 1 == "1", "Passed!" );
  19. });
  20. QUnit.test( "initial state", function( assert ) {
  21. assert.equal( 0, _ws.files.length, "_ws.files should hold 0 file when app started from root" );
  22. assert.ok( $menuRepo.is(':visible'), "menu repo visible (though menu is hidden)" );
  23. assert.equal( 2, ($menuRepo.find('a')).length, "menu repo should contain 2 links" );
  24. assert.ok( $menuExample.is(':visible'), "menu example visible (though menu is hidden AND menu empty)" );
  25. assert.equal( 0, ($menuExample.find('a')).length, "menu example should contain 0 links" );
  26. });
  27. QUnit.test( "test menu toggle", function( assert ) {
  28. var done = assert.async();
  29. assert.equal( $mainMenu.width(), 0, "0. INIT width should be 0" );
  30. assert.ok( $mainMenu.is(':visible'), "0. INIT menu should NOT have class 'in'" );
  31. $menuBtn.trigger('click');
  32. assert.ok( $mainMenu.hasClass('in'), "1.AFTER CLICK menu should have class 'in'" );
  33. assert.ok( $mainMenu.is(':visible'), "1.AFTER CLICK menu should be visible" );
  34. timeoutAsync(() => {
  35. assert.notEqual( $mainMenu.width(), 0, "1.AFTER CLICK menu should have width > 0" );
  36. $menuBtn.trigger('click');
  37. assert.ok( ! $mainMenu.hasClass('in'), "2.AFTER 2ND CLICK menu should NOT have class 'in'" );
  38. }, 100)
  39. .then(() => timeoutAsync(() => {
  40. assert.equal( $mainMenu.width(), 0, "2.AFTER 2ND CLICK width should be 0" );
  41. done();
  42. }, 160));
  43. });
  44. QUnit.test( "test nav to repo", function( assert ) {
  45. assert.equal( window.location.pathname, '/', "location should be / at first" );
  46. $linkToRepo1.trigger('click');
  47. assert.equal( window.location.pathname, '/example-repo1' );
  48. });
  49. QUnit.test( "test nav back to home", function( assert ) {
  50. $homeLink.trigger('click');
  51. assert.ok( window.location.pathname, '/', "location should be / when clicking app title" );
  52. });
  53. });
  54. })(jQuery);