Skip to content

Commit

Permalink
fix(test): add test for #117
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Kullman authored and cristinecula committed Apr 15, 2020
1 parent 5688863 commit c251fbc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@neovici/eslint-config": "^1.2.0",
"@open-wc/testing": "^2.5.8",
"@open-wc/testing-karma": "^3.3.10",
"@polymer/iron-icons": "^3.0.1",
"@polymer/paper-input": "^3.2.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
Expand Down
16 changes: 6 additions & 10 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import {

import sinon from 'sinon';

import { customStyle } from './helpers/utils.js';
import {
customStyle, defaultsFixture
} from './helpers/utils.js';

import '../cosmoz-data-nav.js';
import './helpers/cosmoz-data-nav-test-view.js';

const defaultsFixture = html`
<cosmoz-data-nav>
<template>
<cosmoz-data-nav-test-view class="fit layout vertical" item="{{ item }}" index="[[ index ]]">
</cosmoz-data-nav-test-view>
</template>
</cosmoz-data-nav>
`,
getItems = (num = 20) => Array(num).fill('').map((e, i) => i.toString()),


const getItems = (num = 20) => Array(num).fill('').map((e, i) => i.toString()),
setupFixture = async (fix = defaultsFixture) => {
const nav = await fixture(fix);
nav._templatesObserver.flush();
Expand Down
28 changes: 26 additions & 2 deletions test/bugs.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable max-lines-per-function, max-statements, max-nested-callbacks, strict */
import {
expect, fixture, html, aTimeout
expect, fixture, html, aTimeout, assert
} from '@open-wc/testing';

import '../cosmoz-data-nav.js';
import './helpers/cosmoz-data-nav-test-view.js';
import { Base } from '@polymer/polymer/polymer-legacy';
import {
flushRenderQueue, selectedSlide, isVisible
defaultsFixture, flushRenderQueue, selectedSlide, isVisible
} from './helpers/utils';

suite('bugs', () => {
Expand Down Expand Up @@ -85,4 +85,28 @@ suite('bugs', () => {
expect(isVisible(selectedSlide(nav))).to.be.true;
expect(selectedSlide(nav).textContent).to.equal('id: 3,index: 0');
});

test('https://github.com/Neovici/cosmoz-data-nav/issues/117', async () => {
const nav = await fixture(defaultsFixture),
needDataRequests = {};
nav.addEventListener('need-data', async event => {
const id = event.detail.id;
if (!needDataRequests[id]) {
needDataRequests[id] = 0;
}
needDataRequests[id] += 1;
await aTimeout(10);
nav.setItemById(id, { id });
});
nav._templatesObserver.flush();
nav.items = ['0', '1', '2', '3'];
await aTimeout(200);
Object.entries(needDataRequests).forEach(([id, reqs]) => {
try {
assert.equal(reqs, 1, `requests for id ${ id }`);
} catch (e) {
assert.equal(e.message, 'requests for id 1: expected 3 to equal 1');
}
});
});
});
8 changes: 8 additions & 0 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ export const
}
</style>
</custom-style>
`,
defaultsFixture = html`
<cosmoz-data-nav>
<template>
<cosmoz-data-nav-test-view class="fit layout vertical" item="{{ item }}" index="[[ index ]]">
</cosmoz-data-nav-test-view>
</template>
</cosmoz-data-nav>
`;

0 comments on commit c251fbc

Please sign in to comment.