Skip to content

Commit

Permalink
Refactors helpers 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 9ebdc15 commit f8a1575
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 268 deletions.
10 changes: 9 additions & 1 deletion test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
"flush": false,
"MockInteractions": false,
"sinon": true,
"WCT": false
"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
30 changes: 0 additions & 30 deletions test/helpers.html

This file was deleted.

11 changes: 0 additions & 11 deletions test/helpers.js

This file was deleted.

55 changes: 55 additions & 0 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
(function () {
'use strict';

const setupOmnitableFixture = (omnitableFixtureName, data, callback) => {
const omnitable = fixture(omnitableFixtureName);
omnitable.data = data;
if (omnitable.visibleColumns != null && omnitable.visibleColumns.length) {
callback(omnitable);
} else {
// In Polymer 1.x, the visible-columns-changed event will be fire multiple times,
// causing done to be called multiple times, which mocha does not allow.
// So using a flag to prevent multiple calls to done.
const onVisible = () => {
const columns = omnitable.visibleColumns;
if (Array.isArray(columns) && columns.length > 0) {
omnitable.removeEventListener('visible-columns-changed', onVisible);
Polymer.Base.async(() => callback(omnitable), 60);
}
};

omnitable.addEventListener('visible-columns-changed', onVisible);
}

omnitable.notifyResize();
return omnitable;
};

// Detect dom type: dom=shadow vs wc-shadydom=true
const getDomType = () => {
// match GET parameter named 'dom'
let param = window.location.search.match(/(\?|&)dom\=([^&]*)/), // eslint-disable-line no-useless-escape
dom;
if (Array.isArray(param) && param.length > 0) {
dom = decodeURIComponent(param[2]);
}
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});
}());

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
Loading

0 comments on commit f8a1575

Please sign in to comment.