summaryrefslogtreecommitdiffstats
path: root/vaadin-grid/test/grid-redrawer.html
blob: 81c5f494c3f3c4442ead5fbd9cf07cbca82b6512 (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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <script src="../../webcomponentsjs/webcomponents-lite.min.js"></script>
  <script src="../../web-component-tester/browser.js"></script>

  <script src="common.js"></script>

  <link rel="import" href="../vaadin-grid.html">
</head>

<body>

<div id="gridwrapper"></div>

<script>
  describe.feature('redrawer', function() {
    function width(e) {
      return pxval(e, 'width');
    }

    function height(e) {
      return pxval(e, 'height');
    }

    function pxval(e, prop) {
      return parseInt(e.ownerDocument.defaultView.getComputedStyle(e).getPropertyValue(prop).replace('px', ''));
    }

    describe('redraw', function() {
      function assertHeightByRows(rows) {
        var headersHeight = headers * thHeight;
        var footersHeight = footers * tfHeight;

        h1 = headersHeight + footersHeight + rows * tdHeight;
        // IE and FF add an aditional pixel to each row
        h2 = h1 + rows + headers + footers;

        expect([h1, h2]).to.include(height(inner));
      }

      function assertSameDimensions() {
        expect(width(grid)).to.equal(width(inner));
        expect(height(grid)).to.equal(height(inner));
      }

      var inner,
          tbody,
          headers,
          footers,
          tfHeight,
          thHeight,
          tdHeight

      beforeEach(function() {
        inner = qaLocal("div.v-grid")[1];
        tbody = qLight('table tbody');

        headers = qaLocal('thead tr').length;
        footers = qaLocal('tfoot tr').length;

        tfHeight = height(qLocal('tfoot tr td'));
        thHeight = height(qLocal('thead tr th'));
        tdHeight = height(qLocal('tbody tr td'));

        grid.style.height = "";
        grid.style.width = "";
        grid.removeAttribute('rows');

        // need to return thenable object for FF sake.
        return grid;
      });

      // currently disabled because the grid.then call jams the test on IE.
      it.skip('should draw correct dimensions and row heights by default', function() {
        return grid.then(function() {
          assertSameDimensions();
          assertHeightByRows(2);
        });
      });

      it('should redraw correctly after modifying body', function() {
        tbody.innerHTML += tbody.innerHTML;

        return grid.then(function() {
          assertSameDimensions();
          assertHeightByRows(4);
        });
      });

      describe('using limited row visibility', function() {
        before(function() {
          // Increase the number of rows
          tbody.innerHTML += tbody.innerHTML; //4
          tbody.innerHTML += tbody.innerHTML; //8
          tbody.innerHTML += tbody.innerHTML; //16

          return grid;
        });

        it('should redraw only visible rows', function() {
          return grid.then(function() {
            assertSameDimensions();

            // grid has a limit of 10 data rows by default
            assertHeightByRows(10);
          });
        });

        it('should redraw visible rows after limit is decreased', function() {
          grid.rows = 3;

          return grid.then(function() {
            assertSameDimensions();

            assertHeightByRows(3);
          });
        });

        it('should redraw visible rows limit is removed', function() {
          grid.rows = 0;

          return grid.then(function() {
            assertSameDimensions();

            assertHeightByRows(10); // default
          });
        });
      });

      it('should redraw with fixed dimensions', function() {
        grid.style.width = '300px';
        grid.style.height = '100px';

        return grid.then(function() {
          return grid.then(function() {
            assertSameDimensions();
          });
        });
      });

      describe('grid with a fixed height (issue #8)', function() {
        it('should keep the correct height after sorting', function() {
          grid.columns[0].sortable = true;
          grid.style.height = "500px";

          var firstNonFrozenHeaderCell = qLocal.bind(this, ".v-grid-header .v-grid-cell:not(.frozen)");
          firstNonFrozenHeaderCell().click();

          return grid.then(function() {
            expect(qaLocal('.v-grid')[3].style.height).to.equal('100%');
          });
        });
      });

      describe('using scaled dimensions', function() {
        beforeEach(function() {
          grid.style.position = 'absolute';
          grid.style.width = '100%';
          grid.style.height = '100%';

          return grid;
        });

        it('should redraw with scaled dimensions', function() {
            assertSameDimensions();
        });

        it('should match dimensions with the surrounding div', function() {
          expect(height(grid)).to.equal(document.body.clientHeight);

          // For some reason in IE sometimes there is a slight difference of 1 pixels
          expect(Math.abs(document.body.clientWidth - width(grid))).to.be.at.most(1);
        })

        it('should allow different dimensions for v-grid and inner div', function() {
          // We can have different height for v-grid and the inner grid.
          // Also we can define more than 10 rows.
          tbody.innerHTML += tbody.innerHTML; //4
          tbody.innerHTML += tbody.innerHTML; //8
          tbody.innerHTML += tbody.innerHTML; //16

          grid.rows = 12;
          grid.style.width = '50%';

          return grid.then(function() {
            expect(height(grid)).to.not.equal(height(inner));
            assert.equal(width(grid), width(inner));
            assertHeightByRows(12);
          });
        });
      });
    });
  });
</script>

</body>
</html>