Blame view

bower_components/Materialize/tests/spec/collapsible/collapsibleSpec.js 3.65 KB
a1a3bc73   Luigi Serra   graphs updates
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  describe( "Collapsible Plugin", function () {
    var collapsible, accordion;
  
    beforeEach(function() {
      loadFixtures('collapsible/collapsible.html');
      collapsible = $('.collapsible');
      accordion = $('.accordion');
      popout = $('.popout');
      collapsible.collapsible();
    });
  
    describe( "collapsible", function () {
  
      it("should open all items, keeping all open", function () {
        // Collapsible body height should be 0 on start when hidden.
        var headers = collapsible.find('.collapsible-header');
        var bodies = collapsible.find('.collapsible-body');
  
        bodies.each(function() {
          expect($(this)).toBeHidden('because collapsible bodies should be hidden initially.');
        });
  
        // Collapsible body height should be > 0 after being opened.
        headers.each(function() {
          $(this).click();
        });
        bodies.each(function() {
          expect($(this)).toBeVisible('because collapsible bodies not visible after being opened.');
        });
      });
    });
  
    describe( "accordion", function () {
  
      it("should open first and second items, keeping only second open", function (done) {
        // Collapsible body height should be 0 on start when hidden.
        var firstHeader = accordion.find('.collapsible-header').first();
        var firstBody = accordion.find('.collapsible-body').first();
        var secondHeader = accordion.find('.collapsible-header').eq(1);
        var secondBody = accordion.find('.collapsible-body').eq(1);
        expect(firstBody).toBeHidden('because accordion bodies should be hidden initially.');
        expect(secondBody).toBeHidden('because accordion bodies should be hidden initially.');
  
        // Collapsible body height should be > 0 after being opened.
        firstHeader.click();
  
        setTimeout(function() {
          expect(firstBody).toBeVisible('because accordion bodies not visible after being opened.');
          secondHeader.click();
  
          setTimeout(function() {
            expect(firstBody).toBeHidden('because accordion bodies should be hidden when another item is opened.');
            expect(secondBody).toBeVisible('because accordion bodies not visible after being opened.');
            done();
          }, 400);
        }, 200);
  
      });
    });
  
    describe( "popout", function () {
  
      it("should open first and popout", function (done) {
        // Collapsible body height should be 0 on start when hidden.
        var firstLi = popout.find('li').first();
        var firstHeader = popout.find('.collapsible-header').first();
        var firstBody = popout.find('.collapsible-body').first();
        expect(firstBody).toBeHidden('because accordion bodies should be hidden initially.');
  
        // Expect margin to be > 0 because not popped out.
        popout.find('li').each(function () {
          var marginLeft = parseInt($(this).css('margin-left'));
          var marginRight = parseInt($(this).css('margin-right'));
          expect(marginLeft).toBeGreaterThan(0, 'because closed popout items should have horizontal margins.');
          expect(marginRight).toBeGreaterThan(0, 'because closed popout items should have horizontal margins.');
        });
  
        // expect margin to be 0 because popped out.
        firstHeader.click();
        setTimeout(function() {
          var firstMarginLeft = parseInt(firstLi.css('margin-left'));
          var firstMarginRight = parseInt(firstLi.css('margin-right'));
          expect(firstMarginLeft).toEqual(0, 'because opened popout items should have no horizontal margins.');
          expect(firstMarginRight).toEqual(0, 'because opened popout items should have no horizontal margins.');
          expect(firstBody).toBeVisible('because accordion bodies not visible after being opened.');
  
          done();
        }, 400);
  
      });
    });
  });