Skip to content

Commit

Permalink
Refactors and cleans up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
megheaiulian committed Aug 14, 2018
1 parent 64b9ca9 commit f160ec4
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 242 deletions.
6 changes: 6 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
"WCT": false,
"getDomType": false,
"setupOmnitableFixture":false
},
"rules": {
"no-unused-vars": [
"warn",
{"varsIgnorePattern":"omnitable"}
]
}
}
11 changes: 5 additions & 6 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<script src="./helpers.js"></script>
<script src="./helpers/utils.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="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">
Expand Down Expand Up @@ -54,10 +53,10 @@

<script>
(function () {
/* global setupOmnitableFixture*/
'use strict';
// get dom Type from helpers.js
const domType = getDomType(); //eslint-disable-line no-undef

const domType = getDomType();

suite('basic' + domType, () => {
var omnitable,
data;
Expand Down
7 changes: 2 additions & 5 deletions test/boolean.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<script src="./helpers.js"></script>
<script src="./helpers/utils.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="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">
Expand All @@ -29,11 +28,9 @@

<script>
(function () {
/* global setupOmnitableFixture*/
'use strict';

// get dom Type from helpers.js
const domType = getDomType(); //eslint-disable-line no-undef
const domType = getDomType();

suite('basic' + domType, () => {
let omnitable,
Expand Down
11 changes: 4 additions & 7 deletions test/fit-dropdowns.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<script src="./helpers.js"></script>
<script src="./helpers/utils.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="helpers.html">
<link rel="import" href="../cosmoz-omnitable.html">
<link rel="import" href="../cosmoz-omnitable-column-autocomplete.html">
<link rel="import" href="../cosmoz-omnitable-column.html">
Expand All @@ -36,15 +35,13 @@
</cosmoz-omnitable>
</template>
</test-fixture>

<script>
(function () {
/* global setupOmnitableFixture*/
// get dom Type from helpers.js
const domType = getDomType(); //eslint-disable-line no-undef
'use strict';

let omnitable;
const data = [
const domType = getDomType(),
data = [
{ id: 0, group: 'group0', name: 'Item 0' },
{ id: 1, group: 'group0', name: 'Item 1' },
{ id: 2, group: 'group1', name: 'Item 2' },
Expand Down
15 changes: 6 additions & 9 deletions test/group.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<script src="./helpers.js"></script>
<script src="./helpers/utils.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="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">
Expand Down Expand Up @@ -73,11 +72,9 @@

<script>
(function () {
/* global setupOmnitableFixture*/
'use strict';

// get dom Type from helpers.js
const domType = getDomType(); //eslint-disable-line no-undef
const domType = getDomType();

suite('id' + domType, () => {
let omnitable,
Expand Down Expand Up @@ -157,10 +154,10 @@
let omnitable,
data;

setup(done => {
data = Cosmoz.TableDemoBehavior.generateTableDemoData(10, 11, 25);
omnitable = setupOmnitableFixture('amount', data, () => done());
});
setup(done => {
data = Cosmoz.TableDemoBehavior.generateTableDemoData(10, 11, 25);
omnitable = setupOmnitableFixture('amount', data, () => done());
});

test('setting groupOn property to "amount" updates property groupOnColumn', done => {
omnitable.groupOn = 'amount';
Expand Down
11 changes: 4 additions & 7 deletions test/hash-param.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<script src="./helpers.js"></script>
<script src="./helpers/utils.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="helpers.html">

<link rel="import" href="../cosmoz-omnitable.html">
<link rel="import" href="../cosmoz-omnitable-column-autocomplete.html">
<link rel="import" href="../cosmoz-omnitable-column.html">
Expand All @@ -40,12 +38,11 @@

<script>
(function () {
/* global setupOmnitableFixture*/
// get dom Type from helpers.js
const domType = getDomType(); //eslint-disable-line no-undef
'use strict';

let omnitable;
const data = [
const domType = getDomType(),
data = [
{ id: 0, group: 'group0', name: 'Item 0' },
{ id: 1, group: 'group0', name: 'Item 1' },
{ id: 2, group: 'group1', name: 'Item 2' },
Expand Down
11 changes: 0 additions & 11 deletions test/helpers.js

This file was deleted.

23 changes: 18 additions & 5 deletions test/helpers.html → test/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script>
(function () {
/* global window */
'use strict';

window.setupOmnitableFixture = (omnitableFixtureName, data, callback) => {
const setupOmnitableFixture = (omnitableFixtureName, data, callback) => {
const omnitable = fixture(omnitableFixtureName);
omnitable.data = data;
if (omnitable.visibleColumns != null && omnitable.visibleColumns.length) {
Expand All @@ -28,7 +26,7 @@
};

// Detect dom type: dom=shadow vs wc-shadydom=true
window.getDomType = () => {
const getDomType = () => {
// match GET parameter named 'dom'
let param = window.location.search.match(/(\?|&)dom\=([^&]*)/), // eslint-disable-line no-useless-escape
dom;
Expand All @@ -38,5 +36,20 @@
const domType = dom && dom === 'shadow' ? ' | Using shadow DOM' : ' | Using shady DOM';
return domType;
};

const onColumnReady = (omnitable, columnIndex, done) => {
const checkReady = () => {
const {visibleColumns: visible, columns} = omnitable;
if (visible && visible.length > 0) {
omnitable.removeEventListener('visible-columns-changed', checkReady);
Polymer.Base.async(() => done(columns[columnIndex]), 30);
}
};
omnitable.addEventListener('visible-columns-changed', checkReady);
omnitable.notifyResize();
checkReady();
};

Object.assign(window, {setupOmnitableFixture, getDomType, onColumnReady});
}());
</script>

6 changes: 2 additions & 4 deletions test/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<script src="./helpers.js"></script>
<script src="./helpers/utils.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="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">
Expand All @@ -37,11 +36,10 @@

<script>
(function () {
/* global setupOmnitableFixture*/
'use strict';

// get dom Type from helpers.js
const domType = getDomType(); //eslint-disable-line no-undef
const domType = getDomType();

suite('basic' + domType, () => {
let omnitable,
Expand Down
81 changes: 32 additions & 49 deletions test/range-date.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<script src="./helpers.js"></script>
<script src="./helpers/utils.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="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">
Expand All @@ -36,43 +35,40 @@
</test-fixture>

<script>
/*global sinon chai flush setupOmnitableFixture*/
(function () {
'use strict';

// get dom Type from helpers.js
const domType = getDomType(); //eslint-disable-line no-undef

const data = [
{ age: 17,
amount: { amount: '12.4', currency: 'USD' },
date: '2023-03-21T00:00:00Z',
time: ''
},
{ amount: { amount: 2 },
date: new Date('2015-03-18T00:00:00Z')
},
{ age: -11,
amount: { amount: 678, currency: 'AUD' },
date: new Date(86400000), // Fri Jan 02 1970
time: 86400000
},
{ age: 9,
amount: { amount: -8, currency: 'EUR' },
date: new Date(99, 5, 24, 11, 33, 30, 0), // Thu Jun 24 1999 11:33:30 GMT+0300 (EEST)
time: '86400000'
},
{
age: 5,
amount: { amount: '3450', currency: 'DKK' },
date: new Date('2016-08-27'),
time: '2016-08-27T14:34:56Z'
},
{
date: '2017-12-22T23:00:00Z',
time: '00:00:00'
}
];
const domType = getDomType(),
data = [
{ age: 17,
amount: { amount: '12.4', currency: 'USD' },
date: '2023-03-21T00:00:00Z',
time: ''
},
{ amount: { amount: 2 },
date: new Date('2015-03-18T00:00:00Z')
},
{ age: -11,
amount: { amount: 678, currency: 'AUD' },
date: new Date(86400000), // Fri Jan 02 1970
time: 86400000
},
{ age: 9,
amount: { amount: -8, currency: 'EUR' },
date: new Date(99, 5, 24, 11, 33, 30, 0), // Thu Jun 24 1999 11:33:30 GMT+0300 (EEST)
time: '86400000'
},
{
age: 5,
amount: { amount: '3450', currency: 'DKK' },
date: new Date('2016-08-27'),
time: '2016-08-27T14:34:56Z'
},
{
date: '2017-12-22T23:00:00Z',
time: '00:00:00'
}
];

const onFilter = (column, done) => {
let handler;
Expand All @@ -92,19 +88,6 @@
});
};

const onColumnReady = (omnitable, columnIndex, done) => {
const checkReady = () => {
const {visibleColumns: visible, columns} = omnitable;
if (visible && visible.length > 0) {
omnitable.removeEventListener('visible-columns-changed', checkReady);
Polymer.Base.async(() => done(columns[columnIndex]), 30);
}
};
omnitable.addEventListener('visible-columns-changed', checkReady);
omnitable.notifyResize();
checkReady();
};

sinon.assert.expose(chai.assert, { prefix: '' });

suite('date' + domType, () => {
Expand Down
Loading

0 comments on commit f160ec4

Please sign in to comment.