BVB Source Codes

web-design-standards Show navigation.spec.js Source code

Return Download web-design-standards: download navigation.spec.js Source code - Download web-design-standards Source code - Type:.js
  1. var assert = require('assert');
  2. var fs = require('fs');
  3. var path = require('path');
  4.  
  5. var navigation = require('../../../src/js/components/navigation');
  6. var TEMPLATE = fs.readFileSync(path.join(__dirname, 'template.html'));
  7.  
  8. describe('navigation toggle', function () {
  9.   var nav;
  10.   var overlay;
  11.   var closeButton;
  12.   var menuButton;
  13.  
  14.   var isVisible = function (el) {
  15.     return el.classList.contains('is-visible');
  16.   };
  17.  
  18.   beforeEach(function () {
  19.     document.body.innerHTML = TEMPLATE;
  20.     nav = document.querySelector('.usa-nav');
  21.     overlay = document.querySelector('.usa-overlay');
  22.     closeButton = document.querySelector('.usa-nav-close');
  23.     menuButton = document.querySelector('.usa-menu-btn');
  24.     navigation();
  25.   });
  26.  
  27.   afterEach(function () {
  28.     navigation.off();
  29.   });
  30.  
  31.   it('shows the nav when the menu button is clicked', function () {
  32.     menuButton.click();
  33.     assert.equal(isVisible(nav), true);
  34.     assert.equal(isVisible(overlay), true);
  35.   });
  36.  
  37.   it('hides the nav when the close button is clicked', function () {
  38.     menuButton.click();
  39.     closeButton.click();
  40.     assert.equal(isVisible(nav), false);
  41.     assert.equal(isVisible(overlay), false);
  42.   });
  43.  
  44.   it('hides the nav when the overlay is clicked', function () {
  45.     menuButton.click();
  46.     overlay.click();
  47.     assert.equal(isVisible(nav), false);
  48.     assert.equal(isVisible(overlay), false);
  49.   });
  50.  
  51.   describe('off()', function () {
  52.     it('removes event listeners', function () {
  53.       assert.equal(isVisible(nav), false);
  54.       assert.equal(isVisible(overlay), false);
  55.  
  56.       // remove event listeners, then click the button,
  57.       // and confirm that the nav is still hidden
  58.       navigation.off();
  59.       menuButton.click();
  60.       assert.equal(isVisible(nav), false);
  61.       assert.equal(isVisible(overlay), false);
  62.  
  63.       // next, re-enable the event listeners, click the button,
  64.       // and confirm that the nav is visible again
  65.       navigation();
  66.       menuButton.click();
  67.       assert.equal(isVisible(nav), true);
  68.       assert.equal(isVisible(overlay), true);
  69.  
  70.       // again, remove the event listeners, click the close button,
  71.       // and confirm that everything is still visible
  72.       navigation.off();
  73.       closeButton.click();
  74.       assert.equal(isVisible(nav), true);
  75.       assert.equal(isVisible(overlay), true);
  76.     });
  77.   });
  78.  
  79. });
  80.  
downloadnavigation.spec.js Source code - Download web-design-standards Source code
Related Source Codes/Software:
KineticJS - KineticJS is an HTML5 Canvas JavaScript framework ... 2017-01-07
yui3 - A library for building richly interactive web appl... 2017-01-07
TextBlob - Simple, Pythonic, text processing--Sentiment analy... 2017-01-07
monaco-editor - A browser based code editor 2017-01-07
grumpy - Grumpy is a Python to Go source code transcompiler... 2017-01-07
Knuff - The debug application for Apple Push Notification ... 2017-01-07
RoundedImageView - A fast ImageView that supports rounded corners, ov... 2017-01-07
flowchart.js - Draws simple SVG flow chart diagrams from textual ... 2017-01-08
TextFieldEffects - Custom UITextFields effects inspired by Codrops, b... 2017-01-08
glide - Package Management for Golang h... 2017-01-08
mongo-express - Web-based MongoDB admin interface, written with No... 2017-05-17
XCL-Charts - Android charting libraries (XCL-Charts is a free c... 2017-05-17
scrollMonitor - A simple and fast API to monitor elements as you s... 2017-05-16
XCDYouTubeKit - YouTube video player for iOS, tvOS and macOS 2017-05-16
rails-erd - Generate Entity-Relationship Diagrams for Rails ap... 2017-05-16
np - A better `npm publish` 2017-05-16
android - Smartisan open source code for full build.(repo ma... 2017-05-16
word_cloud - A little word cloud generator in Pytho 2017-05-16
mobileplayer-ios - 2017-05-16
Destroy-Windows-10-Spying - Destroy Windows Spying tool ... 2017-05-15

 Back to top