Welcome to mirror list, hosted at ThFree Co, Russian Federation.

modalsSpec.js « tests « js - github.com/twbs/ratchet.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c1c2b85639f2072b62a321a80b7953a052fa0a7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
describe('Modals', function () {
  beforeEach(function () {
    var templateModal = [
        '<a id="linkOpenModal" href="#myModal" class="btn">Open modal</a>',
        '<div id="myModal" class="modal">',
          '<header class="bar bar-nav">',
            '<a id="linkCloseModal" class="icon icon-close pull-right" href="#myModal"></a>',
            '<h1 class="title">Modal</h1>',
          '</header>',
          '<div class="content">',
            '<p class="content-padded">The contents of my modal go here.</p>',
          '</div>',
        '</div>'
    ].join('');
    document.body.innerHTML += templateModal;
  });

  afterEach(function () {
    var linkModal = document.getElementById('linkOpenModal');
    var modal = document.getElementById('myModal');
    linkModal.parentNode.removeChild(linkModal);
    modal.parentNode.removeChild(modal);
  });

  it('Modal should fire modalOpen event', function (done) {
    window.addEventListener('modalOpen', function () {
      expect(true).toBe(true);
      done();
    });
    var link = document.getElementById('linkOpenModal');
    var eventTouchEnd = new CustomEvent('touchend', {
      bubbles: true,
      cancelable: true
    });
    link.dispatchEvent(eventTouchEnd);
  });

  it('Modal should fire modalClose event', function (done) {
    var link = document.getElementById('linkOpenModal');
    var eventTouchEnd = new CustomEvent('touchend', {
      bubbles: true,
      cancelable: true
    });
    window.addEventListener('modalClose', function () {
      expect(true).toBe(true);
      done();
    });
    link.dispatchEvent(eventTouchEnd);
    var closeLink = document.getElementById('linkCloseModal');
    closeLink.dispatchEvent(eventTouchEnd);
  });
});