-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for boolean, column, list, horizontal list. small code optimiza…
…tions. (#165) * column boolean code optimization * _computeSelected valuePath default * tests for column boolean * tests for omnitable column * function keyword removed * column list handle null params * basic tests for column list * list horizontal handle null * tests for list horizontal * list test getString returns values * list applyMultiFilter handle null
- Loading branch information
1 parent
6efa6cf
commit ab73c90
Showing
7 changed files
with
381 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> | ||
<title>cosmoz-omnitable boolean test</title> | ||
|
||
<script src="../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../web-component-tester/browser.js"></script> | ||
<script src="../../test-fixture/test-fixture-mocha.js"></script> | ||
|
||
<link rel="import" href="../../test-fixture/test-fixture.html"> | ||
<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html"> | ||
|
||
<link rel="import" href="../cosmoz-omnitable.html"> | ||
<link rel="import" href="../cosmoz-omnitable-columns.html"> | ||
<link rel="import" href="../demo/table-demo-behavior.html"> | ||
</head> | ||
<body> | ||
<test-fixture id="basic"> | ||
<template> | ||
<cosmoz-omnitable id="omnitable" class="flex" selection-enabled> | ||
<cosmoz-omnitable-column-boolean name="boolean" value-path="boolean"> | ||
</cosmoz-omnitable-column-boolean> | ||
</cosmoz-omnitable> | ||
</template> | ||
</test-fixture> | ||
|
||
<script> | ||
(function () { | ||
'use strict'; | ||
|
||
suite('basic', () => { | ||
let omnitable, | ||
column, | ||
data; | ||
|
||
setup(done => { | ||
omnitable = fixture('basic'); | ||
data = [ | ||
{ boolean: true }, | ||
{ boolean: false }, | ||
{ null: true }, | ||
{ boolean: 'invalid' }, | ||
{ boolean: 'true' } | ||
]; | ||
omnitable.data = data; | ||
omnitable.notifyResize(); | ||
if (omnitable.visibleColumns != null && omnitable.visibleColumns.length) { | ||
done(); | ||
} else { | ||
omnitable.addEventListener('visible-columns-changed', () => { | ||
column = omnitable.columns[0]; | ||
Polymer.Base.async(done, 30); | ||
}); | ||
} | ||
}); | ||
|
||
test('initializes boolean column', () => { | ||
assert.equal(column.is, 'cosmoz-omnitable-column-boolean'); | ||
}); | ||
|
||
test('_getDefaultFilter is null', () => { | ||
assert.isNull(column.filter); | ||
}); | ||
|
||
test('_textFilterChanged updates filter', () => { | ||
assert.isNull(column.filter); | ||
column._textFilterChanged('true'); | ||
assert.isTrue(column.filter); | ||
}); | ||
|
||
test('_textFilterChanged updates filter as null', done => { | ||
column.filter = 'true'; | ||
column._filterChangedFromAbove = false; | ||
column._textFilterChanged(); | ||
assert.isNull(column.filter); | ||
done(); | ||
}); | ||
|
||
test('filterChanged observer converts boolean to string', () => { | ||
column.filter = true; | ||
assert.equal(column._textFilter, 'true'); | ||
column.filter = false; | ||
assert.equal(column._textFilter, 'false'); | ||
}); | ||
|
||
test('getString uses this.valuePath as default', () => { | ||
assert.equal(column.getString(data[0]), 'True'); | ||
assert.equal(column.getString(data[1]), 'False'); | ||
}); | ||
|
||
test('_computeSelected returns boolean to string', () => { | ||
assert.equal(column._computeSelected(data[0]), 'true'); | ||
assert.equal(column._computeSelected(data[1]), 'false'); | ||
}); | ||
|
||
test('_valueChanged updates _valuePath', done => { | ||
const item = {boolean: false}, | ||
el = document.createElement('div'); | ||
el.selected = 'true'; | ||
el.addEventListener('click', e => { | ||
column._valueChanged(e); | ||
assert.equal(item.boolean, true); | ||
done(); | ||
}); | ||
const e = new Event('click'); | ||
e.model = {}; | ||
e.model.item = item; | ||
el.dispatchEvent(e); | ||
}); | ||
|
||
test('_valueChanged does not update _valuePath if value is equal to oldValue', done => { | ||
const item = {boolean: true}, | ||
el = document.createElement('div'); | ||
el.selected = 'true'; | ||
el.addEventListener('click', e => { | ||
column._valueChanged(e); | ||
assert.equal(item.boolean, true); | ||
done(); | ||
}); | ||
const e = new Event('click'); | ||
e.model = {}; | ||
e.model.item = item; | ||
el.dispatchEvent(e); | ||
}); | ||
}); | ||
})(); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.