Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saulis committed Jul 10, 2016
1 parent 749997d commit 0070b6d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 53 deletions.
5 changes: 4 additions & 1 deletion data-table-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@

properties: {
beforeBind: Object,
expanded: Boolean,
expanded: {
type: Boolean,
reflectToAttribute: true
},
index: Number,
item: Object,
selected: {
Expand Down
8 changes: 4 additions & 4 deletions test/lazy-loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@
});

it('should be called with sort order', function(done) {
table.sortOrder = {
table.sortOrder = [{
path: 'foo',
sortOrder: 'asc'
};
}];

table.clearCache();
table.async(function() {
Expand All @@ -172,11 +172,11 @@
table._currentPage = 10;

table.async(function() {
expect(table._cachedPages.indexOf(10)).to.eql(0);
expect(table._cachedPages).to.contain.members([10]);

table.clearCache();

expect(table._cachedPages.indexOf(10)).to.eql(-1);
expect(table._cachedPages).not.to.contain.members([10]);
done();
}, 250);
});
Expand Down
18 changes: 7 additions & 11 deletions test/row-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</data-table-column>
<data-table-column name="Second">
<template>
<a href="#">[[ item.value2 ]]</a>
<a href="#" id="link">[[ item.value2 ]]</a>
</template>
</data-table-column>
<template is="row-detail">[[ item.value2 ]]</template>
Expand Down Expand Up @@ -68,8 +68,7 @@
});

it('should show row detail when row is clicked', function(done) {
var firstRow = grid.querySelector('#items .item data-table-row');
firstRow.focus();
var firstRow = grid.querySelector('data-table-row:not([header])');
firstRow.click();

setTimeout(function() {
Expand All @@ -87,9 +86,8 @@
});

it('should not show row detail when row cell with a focusable element is clicked', function(done) {
var firstRow = grid.querySelector('#items .item data-table-row');
var focusableElement = firstRow.querySelector('data-table-cell:nth-of-type(2) > a');
focusableElement.focus();
var firstRow = grid.querySelector('data-table-row:not([header])');
var focusableElement = firstRow.querySelector('#link');
focusableElement.click();

setTimeout(function() {
Expand Down Expand Up @@ -122,8 +120,7 @@
});

it('should not show row detail when row is clicked', function(done) {
var firstRow = grid.querySelector('#items .item data-table-row');
firstRow.focus();
var firstRow = grid.querySelector('data-table-row:not([header])');
firstRow.click();

setTimeout(function() {
Expand All @@ -135,9 +132,8 @@
});

it('should show row detail when row cell with expanded property bound is activated', function(done) {
var firstRow = grid.querySelector('#items .item data-table-row');
var focusableElement = firstRow.querySelector('data-table-cell:nth-of-type(1) > paper-checkbox');
focusableElement.focus();
var firstRow = grid.querySelector('data-table-row:not([header])');
var focusableElement = firstRow.querySelector('paper-checkbox');
focusableElement.click();

setTimeout(function() {
Expand Down
59 changes: 22 additions & 37 deletions test/selecting.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../iron-data-table.html">
<link rel="import" href="../../vaadin-combo-box/vaadin-combo-box.html">
<link rel="import" href="../../paper-input/paper-input.html">
</head>

<body>
Expand Down Expand Up @@ -43,7 +44,7 @@
<data-table-column name="Second">
<template>
<value-helper id="second" value="[[selected]]"></value-helper>
<input id="input" type="text"></input>
<paper-input id="third" value="{{selected}}"></paper-input>
</template>
</data-table-column>
</iron-data-table>
Expand All @@ -60,6 +61,7 @@
<div>[[value]]</div>
</template>
<script>
document.addEventListener('WebComponentsReady', function() {
Polymer({
is: 'value-helper',

Expand All @@ -70,6 +72,7 @@
}
}
});
});
</script>
</dom-module>

Expand All @@ -78,12 +81,6 @@
var table;
var first, second, input;

function tap(node) {
Polymer.Base.fire('tap', null, {
node: node
});
}

function waitUntil(fn, done) {
setTimeout(function() {
if (!fn()) {
Expand All @@ -99,7 +96,7 @@
table.items = ['foo', 'bar', 'baz'];
first = table.querySelector("#first");
second = table.querySelector("#second");
input = table.querySelector("#input");
input = table.querySelector("#third");

//100ms to take into account the debounce on _loadPage.
table.async(done, 100);
Expand Down Expand Up @@ -203,50 +200,49 @@
});
});

describe('by tapping on rows', function() {
describe('by clicking on rows', function() {
it('should not select row when selection-enabled is false', function(done) {
table.selectionEnabled = false;

first.addEventListener('value-changed', function(e) {
done(new Error('Value should not change.'));
});

tap(first);
first.click();

setTimeout(done, 250);
});

it('should select row when tapping', function(done) {
it('should select row when clicking', function(done) {
first.addEventListener('value-changed', function(e) {
expect(e.detail.value).to.eql(true);
done();
});

tap(first);
first.click();
});

it('should deselect row when tapping again', function(done) {
tap(first);
it('should deselect row when clicking again', function(done) {
first.click();

first.addEventListener('value-changed', function(e) {
expect(e.detail.value).to.eql(false);
done();
});

tap(first);
first.click();
});

// can't be tested reliably because focus can't be trusted when testing.
it.skip('should not select row when tapping on focusable child', function(done) {
tap(first);
it.skip('should not select row when clicking on focusable child', function(done) {
first.click();

var spy = sinon.spy();
first.addEventListener('value-changed', spy);

tap(input);
input.click();

table.async(function() {
debugger;
expect(spy.callCount).to.eql(0);
done();
}, 250);
Expand All @@ -260,34 +256,33 @@
done();
});

tap(first);
first.click();
});
it('should update [[selected]] on template instances', function(done) {
second.addEventListener('value-changed', function(e) {
expect(e.detail.value).to.eql(true);
done();
});

tap(first);
first.click();
});
});

describe('using two-way binding', function() {
it('should update [[selected]] on template instances with the same item', function() {
input.value = 'foo';

expect(first.innerHTML).to.eql('true');
expect(second.innerHTML).to.eql('true');
expect(first.children[0].innerHTML).to.eql('true');
expect(second.children[0].innerHTML).to.eql('true');
});

it('should update selectedItem(s)', function() {
input.value = 'bar';
input.value = 'foo';

expect(table.selectedItem).to.eql('bar');
expect(table.selectedItems).to.have.members(['bar']);
expect(table.selectedItem).to.eql('foo');
expect(table.selectedItems).to.have.members(['foo']);
});
});

describe('using data-table-row selected property', function() {});

describe('using data-table-row selected attribute', function() {}
Expand All @@ -314,12 +309,6 @@
Polymer.Base.async(done, 200);
});

it('should bind selection enabled property', function() {
grid.selectionEnabled = true;

expect(grid.$.list.selectionEnabled).to.be.true;
});

it('should select item', function() {
grid.selectItem(0);

Expand Down Expand Up @@ -348,10 +337,6 @@
grid.multiSelection = true;
});

it('should be bound to iron-list', function() {
expect(grid.$.list.multiSelection).to.be.true;
});

it('should select all', function() {
grid.selectAll();

Expand Down

0 comments on commit 0070b6d

Please sign in to comment.