BVB Source Codes

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

Return Download web-design-standards: download search.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 search = require('../../../src/js/components/search');
  6. var TEMPLATE = fs.readFileSync(path.join(__dirname, 'template.html'));
  7.  
  8. var isVisuallyHidden = function (el) {
  9.   return el.classList.contains('usa-sr-only');
  10. };
  11.  
  12. describe('search toggle', function () {
  13.   var button;
  14.   var form;
  15.  
  16.   beforeEach(function () {
  17.     document.body.innerHTML = TEMPLATE;
  18.     button = document.querySelector('.js-search-button');
  19.     form = document.querySelector('.js-search-form');
  20.     search();
  21.   });
  22.  
  23.   afterEach(function () {
  24.     search.off();
  25.   });
  26.  
  27.   it('initializes the form as visually hidden, button visible', function () {
  28.     assert.equal(button.hidden, false);
  29.     assert.equal(isVisuallyHidden(form), true);
  30.   });
  31.  
  32.   it('reveals the search form on click', function () {
  33.     button.click();
  34.     assert.equal(button.hidden, true);
  35.     assert.equal(isVisuallyHidden(form), false);
  36.   });
  37.  
  38.   it('hides the search form on second click', function () {
  39.     button.click();
  40.     document.body.click();
  41.     assert.equal(button.hidden, false);
  42.     assert.equal(isVisuallyHidden(form), true);
  43.   });
  44.  
  45.   it('does not hide the search form when clicked directly', function () {
  46.     button.click();
  47.     form.click();
  48.     assert.equal(button.hidden, true);
  49.     assert.equal(isVisuallyHidden(form), false);
  50.   });
  51.  
  52.   describe('off()', function () {
  53.     it('removes click handlers', function () {
  54.       search.off();
  55.       button.click();
  56.       assert.equal(button.hidden, false);
  57.       assert.equal(isVisuallyHidden(form), true);
  58.     });
  59.   });
  60.  
  61. });
  62.  
downloadsearch.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
viper - Go configuration with fang 2017-02-17
bypy - The Python client for Baidu Yun (Personal Cloud St... 2017-02-17
ZLSwipeableView - A simple view for building card like interface ins... 2017-02-17
searchkit - React UI components / widgets. The easiest way to ... 2017-02-17
Ghost.py - Webkit based scriptable web browser for python. 2017-02-17
SwitchButton - A cute widget of Switch Button for you to create b... 2017-02-17
Starscream - Websockets in swift for iOS and OSX 2017-02-17
cat - Central Application Tracking 2017-02-17
dotfiles - aul's shell, git, etc config files. also homebrew,... 2017-02-17
git-radar - A heads up display for git 2017-02-17

 Back to top