ws.test.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. var $editor = $('#editor');
  18. var $editorTabs = $('#tabs');
  19. QUnit.test( "hello test", function( assert ) {
  20. assert.ok( 1 == "1", "Passed!" );
  21. });
  22. QUnit.test( "initial state", function( assert ) {
  23. assert.equal( _ws.files.length, 0, "_ws.files should hold 0 file when app started from root" );
  24. assert.ok( $menuRepo.is(':visible'), "menu repo visible (though menu is hidden)" );
  25. assert.equal( ($menuRepo.find('a')).length, 2, "menu repo should contain 2 links" );
  26. assert.ok( $menuExample.is(':visible'), "menu example visible (though menu is hidden AND menu empty)" );
  27. assert.equal( ($menuExample.find('a')).length, 0, "menu example should contain 0 links" );
  28. assert.ok( ! $editor.is(':visible'), "editor invisible" );
  29. assert.ok( ! $editorTabs.is(':visible'), "editor tabs invisible" );
  30. });
  31. QUnit.test( "test menu toggle", function( assert ) {
  32. var done = assert.async();
  33. assert.equal( $mainMenu.width(), 0, "0. INIT width should be 0" );
  34. assert.ok( $mainMenu.is(':visible'), "0. INIT menu should NOT have class 'in'" );
  35. $menuBtn.trigger('click');
  36. assert.ok( $mainMenu.hasClass('in'), "1.AFTER CLICK menu should have class 'in'" );
  37. assert.ok( $mainMenu.is(':visible'), "1.AFTER CLICK menu should be visible" );
  38. timeoutAsync(() => {
  39. assert.notEqual( $mainMenu.width(), 0, "1.AFTER CLICK menu should have width > 0" );
  40. $menuBtn.trigger('click');
  41. assert.ok( ! $mainMenu.hasClass('in'), "2.AFTER 2ND CLICK menu should NOT have class 'in'" );
  42. }, 120)
  43. .then(() => timeoutAsync(() => {
  44. assert.equal( $mainMenu.width(), 0, "2.AFTER 2ND CLICK width should be 0" );
  45. done();
  46. }, 180));
  47. });
  48. QUnit.test( "test nav to repo", function( assert ) {
  49. var done = assert.async();
  50. assert.equal( window.location.pathname, '/', "location should be / at first" );
  51. $linkToRepo1.trigger('click');
  52. assert.equal( window.location.pathname, '/example-repo1' );
  53. timeoutAsync(() => {
  54. assert.equal( ($menuExample.find('a')).length, 1, "menu example should contain 1 entry" );
  55. assert.equal( $menuExample.find('a:first').html(), "Test Example", "link to 1st example should be labelled 'Test Example'" );
  56. done();
  57. }, 100);
  58. });
  59. QUnit.test( "test nav to example", function( assert ) {
  60. var done = assert.async();
  61. assert.equal( ($menuExample.find('a')).length, 1, "menu example should contain 1 entry" );
  62. var $linkToExmp1 = $menuExample.find('a:first');
  63. $linkToExmp1.trigger('click');
  64. assert.equal( window.location.pathname, '/example-repo1/repo1-example1', "location should be /example-repo1/repo1-example1" );
  65. timeoutAsync(() => {
  66. assert.ok( $editor.is(':visible'), "editor visible" );
  67. assert.equal( _ws.files.length, 2, "_ws.files should hold 2 files" );
  68. done();
  69. }, 50);
  70. });
  71. QUnit.test( "test adding a collection", function( assert ) {
  72. var done = assert.async();
  73. var $addCollectionForm = $('#add-collection-form');
  74. var $addCollectionBtn = $('#add-collection-btn');
  75. assert.equal( $addCollectionForm.length, 1, "there should be one #add-collection-form element" );
  76. assert.equal( $addCollectionBtn.length, 1, "there should be one #add-collection-btn element" );
  77. $addCollectionBtn.trigger( 'click' );
  78. assert.ok( $addCollectionForm.is(':visible'), "clicking on #add-collection-btn should make appear the *-form element" );
  79. done();
  80. });
  81. QUnit.test( "test nav back to home", function( assert ) {
  82. var done = assert.async();
  83. $homeLink.trigger('click');
  84. assert.ok( window.location.pathname, '/', "location should be / when clicking app title" );
  85. timeoutAsync(() => {
  86. assert.equal( ($menuExample.find('a')).length, 0, "menu example should contain 0 entry" );
  87. done();
  88. }, 50);
  89. });
  90. });
  91. })(jQuery);