Improve statement test coverage

This commit is contained in:
Chris Trevino 2016-12-01 16:05:03 -08:00
Родитель 44309607d4
Коммит 2c6fe1c543
10 изменённых файлов: 228 добавлений и 8 удалений

Просмотреть файл

@ -10,6 +10,7 @@ import PlaybackPane from '../PlaybackPane';
import HistoryView from './HistoryView';
import StoryboardingView from './StoryboardingView';
import { IHistoryContainerSharedProps } from './interfaces';
import isNumber from '../../isNumber';
import './History.scss';
const { PropTypes } = React;
@ -179,7 +180,7 @@ export class History extends React.Component<IHistoryProps, {}> {
onSelectMainView,
bookmarksEnabled,
} = this.props;
const isPlaybackMode = Number.isInteger(bookmarkPlaybackIndex);
const isPlaybackMode = isNumber(bookmarkPlaybackIndex);
return isPlaybackMode ? this.renderPlayback() : (
<HistoryTabs

Просмотреть файл

@ -5,9 +5,9 @@ export interface IHistoryContainerSharedProps {
mainView: string;
historyType: string;
getSourceFromState: Function;
branchContainerExpanded: boolean;
highlightSuccessorsOf: number;
bookmarksEnabled: boolean;
branchContainerExpanded?: boolean;
highlightSuccessorsOf?: number;
bookmarksEnabled?: boolean;
/**
* ControlBar Configuration Properties

Просмотреть файл

@ -1,5 +1,3 @@
/// <reference path="../node_modules/typescript/lib/lib.es2017.d.ts" />
/// <reference path="../node_modules/typescript/lib/lib.dom.d.ts" />
import HistoryComponent from './components/History';
export default HistoryComponent;

Просмотреть файл

@ -1,3 +1,7 @@
export default function isNumber(d: any) {
return d !== null && d !== undefined && !Number.isNaN(d);
return d !== null &&
d !== undefined &&
typeof d === 'number' &&
!Number.isNaN(d) &&
Number.isFinite(d);
}

Просмотреть файл

@ -0,0 +1,62 @@
import * as React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import BranchList from '../../../src/components/BranchList';
describe('The BranchList component', () => {
it('can render an empty branch list', () => {
const rendered = mount(
<BranchList
activeBranch={null}
branches={[]}
/>
);
expect(rendered).to.be.ok;
});
it('can render an non-empty branch list', () => {
let clickedId = null;
const rendered = mount(
<BranchList
activeBranch={5}
branches={[
{
id: 5,
label: 'delta-1',
startsAt: 5,
endsAt: 10,
maxDepth: 10,
branchType: 'current',
}
]}
onBranchClick={(id) => clickedId = id}
/>
);
expect(rendered).to.be.ok;
rendered.find('.history-branch').get(0);
rendered.find('.history-branch').simulate('click');
expect(clickedId).to.equal(5);
});
it('will not throw an error when an branch is clicked without an onClick handler defined', () => {
const rendered = mount(
<BranchList
activeBranch={5}
branches={[
{
id: 5,
label: 'delta-1',
startsAt: 5,
endsAt: 10,
maxDepth: 10,
branchType: 'current',
}
]}
/>
);
// click should be ok
expect(rendered).to.be.ok;
rendered.find('.history-branch').get(0);
rendered.find('.history-branch').simulate('click');
});
});

Просмотреть файл

@ -0,0 +1,42 @@
import * as React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import Continuation from '../../../src/components/Continuation';
describe('The Continuation component', () => {
it('can be rendered', () => {
const rendered = mount(
<Continuation />
);
expect(rendered).to.be.ok;
});
it('can render a sane continuation count', () => {
const rendered = mount(
<Continuation count={10} />
);
expect(rendered).to.be.ok;
const found = rendered.find('.history-state-continuations');
expect(found.html().indexOf("10")).to.be.gte(0);
expect(found.length).to.equal(1);
});
it('can render a high count', () => {
const rendered = mount(
<Continuation count={1000} />
);
expect(rendered).to.be.ok;
const found = rendered.find('.history-state-continuations');
expect(found.html().indexOf("99+")).to.be.gte(0);
expect(found.length).to.equal(1);
});
it('can be rendered', () => {
let clicked = false;
const rendered = mount(
<Continuation onClick={() => clicked = true}/>
);
rendered.simulate('click');
expect(clicked).to.be.true;
});
});

Просмотреть файл

@ -0,0 +1,80 @@
import * as React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import * as Promise from 'bluebird';
import * as dagHistory from 'redux-dag-history/lib/DagHistory';
import History from '../../../src/components/History';
import { createStore } from 'redux';
// It's kind of cheap, but rendering the top-level component
// gives us a lot of baseline statement test-coverage
describe('The History Component', () => {
it('can be rendered in branched mode', () => {
const store = createStore(() => ({}));
const history = dagHistory.createHistory({}, 'initialBranch', 'initialState');
const rendered = mount(
<Provider store={store}>
<History
bookmarksEnabled
history={history}
getSourceFromState={state => "test source"}
historyType="branched"
branchContainerExpanded
mainView="history"
controlBar={{
onConfirmClear: () => Promise.resolve(true),
onLoadHistory: () => Promise.resolve({}),
onSaveHistory: () => Promise.resolve(true),
}}
/>
</Provider>
);
expect(rendered).to.be.ok;
});
it('can be rendered in chronological mode', () => {
const store = createStore(() => ({}));
const history = dagHistory.createHistory({}, 'initialBranch', 'initialState');
const rendered = mount(
<Provider store={store}>
<History
bookmarksEnabled
history={history}
getSourceFromState={state => "test source"}
historyType="chronological"
mainView="history"
controlBar={{
onConfirmClear: () => Promise.resolve(true),
onLoadHistory: () => Promise.resolve({}),
onSaveHistory: () => Promise.resolve(true),
}}
/>
</Provider>
);
expect(rendered).to.be.ok;
});
it('can be rendered in storyboarding mode', () => {
const store = createStore(() => ({}));
const history = dagHistory.createHistory({}, 'initialBranch', 'initialState');
const rendered = mount(
<Provider store={store}>
<History
bookmarksEnabled
history={history}
getSourceFromState={state => "test source"}
historyType="chronological"
mainView="storyboarding"
controlBar={{
onConfirmClear: () => Promise.resolve(true),
onLoadHistory: () => Promise.resolve({}),
onSaveHistory: () => Promise.resolve(true),
}}
/>
</Provider>
);
expect(rendered).to.be.ok;
});
});

20
test/isNumber.spec.ts Normal file
Просмотреть файл

@ -0,0 +1,20 @@
import { expect } from 'chai';
import isNumber from '../src/isNumber';
describe('The isNumber module', () => {
it('returns true on numeric inputs', () => {
expect(isNumber(0)).to.be.true;
expect(isNumber(1)).to.be.true;
expect(isNumber(-1)).to.be.true;
expect(isNumber(Number.MAX_VALUE)).to.be.true;
expect(isNumber(Number.MIN_VALUE)).to.be.true;
});
it('returns false on non-numeric inputs', () => {
expect(isNumber(NaN)).to.be.false;
expect(isNumber(Infinity)).to.be.false;
expect(isNumber({})).to.be.false;
expect(isNumber(() => ({}))).to.be.false;
expect(isNumber('')).to.be.false;
});
});

Просмотреть файл

@ -29,6 +29,15 @@ describe('The Dag-History Component Reducer', () => {
});
});
it('can respond to a SELECT_HISTORY_TYPE action', () => {
const state = reducer()(undefined, { type: 'SELECT_HISTORY_TYPE', payload: 'derp' });
expect(state).to.deep.equal({
mainView: 'history',
historyType: 'derp',
branchContainerExpanded: true,
});
});
it('can respond to a TOGGLE_BRANCH_CONTAINER action', () => {
let state = reducer()(undefined, { type: 'TOGGLE_BRANCH_CONTAINER' });
expect(state).to.deep.equal({

Просмотреть файл

@ -7,7 +7,11 @@
"sourceMap": false,
"experimentalDecorators": true,
"declaration": true,
"outDir": "lib"
"outDir": "lib",
"lib": [
"es2017",
"dom"
]
},
"files": [
"src/index.ts",