Skip to content

Commit

Permalink
fix(test): reuse more logic
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 59c269e commit 5688863
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = config => {
//
// npm run test -- --grep test/foo/bar.test.js
// npm run test -- --grep test/bar/*
pattern: config.grep ? config.grep : 'test/**/*.test.js',
pattern: config.grep ? config.grep : 'test/*.test.js',
type: 'module'
}],

Expand Down
50 changes: 22 additions & 28 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ 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>
`;
<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()),
setupFixture = async (fix = defaultsFixture) => {
const nav = await fixture(fix);
nav._templatesObserver.flush();
nav.items = getItems();
return nav;
};

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

suite('defaults', () => {
let nav;

suiteSetup(async () => {
nav = await fixture(defaultsFixture);
nav._templatesObserver.flush();
nav.items = Array(20).fill('').map((e, i) => i.toString());
nav = await setupFixture();
});

test('creates buffer elements', () => {
Expand Down Expand Up @@ -57,9 +62,7 @@ suite('properties check', () => {
let nav;

suiteSetup(async () => {
nav = await fixture(defaultsFixture);
nav._templatesObserver.flush();
nav.items = Array(20).fill('').map((e, i) => i.toString());
nav = await setupFixture();
});

test('selected property is updated', () => {
Expand Down Expand Up @@ -108,7 +111,7 @@ suite('duplicate ids', () => {
suiteSetup(async () => {
nav = await fixture(defaultsFixture);
nav._templatesObserver.flush();
const items = Array(20).fill('').map((e, i) => i.toString());
const items = getItems();
items[0] = '0';
items[1] = '0';
nav.items = items;
Expand Down Expand Up @@ -144,7 +147,7 @@ suite('cache', () => {
});

setup(() => {
nav.items = Array(20).fill('').map((e, i) => i.toString());
nav.items = getItems();
});

teardown(() => {
Expand Down Expand Up @@ -210,13 +213,10 @@ suite('cache', () => {
});

suite('other methods', () => {
const getItems = () => Array(20).fill('').map((e, i) => i.toString());

let nav;
setup(async () => {
nav = await fixture(defaultsFixture);
nav._templatesObserver.flush();
nav.items = getItems();
nav = await setupFixture();
});

test('setItemById warns about a unknown item', () => {
Expand Down Expand Up @@ -287,9 +287,7 @@ suite('navigation', () => {
let nav;

suiteSetup(async () => {
nav = await fixture(defaultsFixture);
nav._templatesObserver.flush();
nav.items = Array(10).fill('').map((e, i) => i.toString());
nav = await setupFixture();
});

test('selects next item', async () => {
Expand Down Expand Up @@ -320,15 +318,13 @@ suite('elements buffer', () => {
let nav;

setup(async () => {
nav = await fixture(html`
nav = await setupFixture(html`
<cosmoz-data-nav elements-buffer="4">
<template>
<cosmoz-data-nav-test-view class="fit layout vertical" item="{{ item }}" index="[[ index ]]"></cosmoz-data-nav-test-view>
</template>
</cosmoz-data-nav>
`);
nav._templatesObserver.flush();
nav.items = Array(10).fill('').map((e, i) => i.toString());
});

test('elementsBuffer property updates _elements', () => {
Expand Down Expand Up @@ -356,16 +352,14 @@ suite('renderQueue', () => {
setup(async () => {
[, nav] = await Promise.all([
fixture(customStyle),
fixture(html`
setupFixture(html`
<cosmoz-data-nav elements-buffer="5">
<template>
<cosmoz-data-nav-test-view class="fit layout vertical" item="{{ item }}" index="[[ index ]]"></cosmoz-data-nav-test-view>
</template>
</cosmoz-data-nav>
`)
]);
nav._templatesObserver.flush();
nav.items = Array(10).fill('').map((e, i) => i.toString());
});

test('renderQueue three items', async () => {
Expand Down

0 comments on commit 5688863

Please sign in to comment.