aboutsummaryrefslogtreecommitdiffstats
path: root/vaadin-grid/test/common.js
blob: 4815d96b1454997f6de6834598510dfeb895304a (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
var grid, wrapper;

describe.feature = function(description, suite) {
  describe(description, function() {
    before(function(done) {
      initializeGrid();

      waitUntil(function() {
        return grid.then;
      }, done, done);
    });

    after(function() {
      return grid; //make sure everything is finished before moving on.
    });

    suite();
  });
};

function gridContainsText(_grid, text) {
  return Polymer.dom(_grid.root).querySelector(".v-grid-tablewrapper").parentElement.innerHTML.indexOf(text) > -1;
}

function waitUntil(check, exec, onTimeout) {
  var id = setInterval(function() {
    if (check()) {
      clearInterval(id);
      clearTimeout(timeoutId);
      exec();
    }
  }, 100);

  var timeoutId = setTimeout(function() {
    clearInterval(id);
    assert.fail();
    onTimeout();
  }, 5000);
}


function initializeGrid() {
  wrapper = document.getElementById("gridwrapper");
  wrapper.innerHTML = "<v-grid>" +
  "                     <table>" +
  "                       <col header-text='Name'>" +
  "                       <col header-text='Value'>" +
  "                       <tbody>" +
  "                         <tr>" +
  "                           <td>Grid</td>" +
  "                           <td>10000</td>" +
  "                         </tr>" +
  "                         <tr>" +
  "                           <td>VaadinX</td>" +
  "                           <td>1000</td>" +
  "                         </tr>" +
  "                       </tbody>" +
  "                     <tfoot>" +
  "                       <tr>" +
  "                         <td>Name</td>" +
  "                         <td>Value</td>" +
  "                       </tr>" +
  "                     </tfoot>"+
  "                     </table>" +
  "                     </v-grid>";
  grid = wrapper.querySelector("v-grid");

  return grid;
};

var local = function() {
  return Polymer.dom(grid.root);
};
var light = function() {
  return Polymer.dom(grid);
};

var qLocal = function(selector) {
  return local().querySelector(selector);
};
var qaLocal = function(selector) {
  return local().querySelectorAll(selector);
};
var qLight = function(selector) {
  return light().querySelector(selector);
};