<commit_before><!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <script src="../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
  <script src="../../bower_components/web-component-tester/browser.js"></script>
  <script src="../../VaadinGrid/VaadinGrid.nocache.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 = qLocal("div.v-grid");
        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'));
      })

      it('should draw correct dimensions and row heights by default', 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() {
        beforeEach(function() {
          // Increase the number of rows
          tbody.innerHTML += tbody.innerHTML; //4
          tbody.innerHTML += tbody.innerHTML; //8
          tbody.innerHTML += tbody.innerHTML; //16
        });

        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() {
          assertSameDimensions();
        });
      });

      describe('using scaled dimensions', function() {
        beforeEach(function() {
          grid.style.position = 'absolute';<commit_msg>Test grid fixed height after sorting. (#8)<commit_after><!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <script src="../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
  <script src="../../bower_components/web-component-tester/browser.js"></script>
  <script src="../../VaadinGrid/VaadinGrid.nocache.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 = qLocal("div.v-grid");
        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'));
      })

      it('should draw correct dimensions and row heights by default', 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() {
        beforeEach(function() {
          // Increase the number of rows
          tbody.innerHTML += tbody.innerHTML; //4
          tbody.innerHTML += tbody.innerHTML; //8
          tbody.innerHTML += tbody.innerHTML; //16
        });

        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() {
          assertSameDimensions();
        });
      });

      describe('grid with a fixed height (issue #8)', function() {
        before(function() {
          grid.columns[0].sortable = true;
          grid.style.height = "500px";
        });

        it('should keep the correct height after sorting', function() {
          var firstNonFrozenHeaderCell = qLocal.bind(this, ".v-grid-header .v-grid-cell:not(.frozen)");

          firstNonFrozenHeaderCell().click();

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

      describe('using scaled dimensions', function() {
        beforeEach(function() {
          grid.style.position = 'absolute';
{'fraction_non_alphanumeric': 0.1422278162366268, 'fraction_numerical': 0.008055380742605412, 'mean_word_length': 2.1873245086241475, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5453689', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2168, 'n_words': 487}