Skip to content

Commit

Permalink
Adds tests for Status.hasCompleted
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyjbauer committed Jan 22, 2019
1 parent 93c9178 commit c5b0588
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 54 deletions.
12 changes: 6 additions & 6 deletions frontend/src/pages/RunDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -695,25 +695,25 @@ describe('RunDetails', () => {
}, 10000);


for(const status of [NodePhase.ERROR, NodePhase.FAILED, NodePhase.SUCCEEDED, NodePhase.SKIPPED]) {
[NodePhase.ERROR, NodePhase.FAILED, NodePhase.SUCCEEDED, NodePhase.SKIPPED].forEach(status =>
it(`sets \'runFinished\' to true if run has status: ${status}`, async () => {
testRun.run!.status = status;
tree = shallow(<RunDetails {...generateProps()} />);
await TestUtils.flushPromises();

expect(tree.state('runFinished')).toBe(true);
});
}
})
);

for(const status of [NodePhase.PENDING, NodePhase.RUNNING, NodePhase.UNKNOWN]) {
[NodePhase.PENDING, NodePhase.RUNNING, NodePhase.UNKNOWN].forEach(status =>
it(`leaves \'runFinished\' false if run has status: ${status}`, async () => {
testRun.run!.status = status;
tree = shallow(<RunDetails {...generateProps()} />);
await TestUtils.flushPromises();

expect(tree.state('runFinished')).toBe(false);
});
}
})
);

it('pauses auto refreshing if window loses focus', async () => {
tree = shallow(<RunDetails {...generateProps()} />);
Expand Down
76 changes: 48 additions & 28 deletions frontend/src/pages/Status.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as Utils from '../lib/Utils';
import { shallow } from 'enzyme';
import { statusToIcon, NodePhase } from './Status';
import { statusToIcon, NodePhase, hasCompleted } from './Status';


describe('Status', () => {
Expand All @@ -33,37 +33,57 @@ describe('Status', () => {
});
});

it('handles an unknown phase', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => null);
const tree = shallow(statusToIcon('bad phase' as any));
expect(tree).toMatchSnapshot();
expect(consoleSpy).toHaveBeenLastCalledWith('Unknown node phase:', 'bad phase');
});
describe('statusToIcon', () => {
it('handles an unknown phase', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => null);
const tree = shallow(statusToIcon('bad phase' as any));
expect(tree).toMatchSnapshot();
expect(consoleSpy).toHaveBeenLastCalledWith('Unknown node phase:', 'bad phase');
});

it('displays start and end dates if both are provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, startDate, endDate));
expect(tree).toMatchSnapshot();
});
it('displays start and end dates if both are provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, startDate, endDate));
expect(tree).toMatchSnapshot();
});

it('does not display a end date if none was provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, startDate));
expect(tree).toMatchSnapshot();
});
it('does not display a end date if none was provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, startDate));
expect(tree).toMatchSnapshot();
});

it('does not display a start date if none was provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, undefined, endDate));
expect(tree).toMatchSnapshot();
});
it('does not display a start date if none was provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, undefined, endDate));
expect(tree).toMatchSnapshot();
});

it('does not display any dates if neither was provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, /* No dates */));
expect(tree).toMatchSnapshot();
});

it('does not display any dates if neither was provided', () => {
const tree = shallow(statusToIcon(NodePhase.SUCCEEDED, /* No dates */));
expect(tree).toMatchSnapshot();
Object.keys(NodePhase).map(status => (
it('renders an icon with tooltip for phase: ' + status, () => {
const tree = shallow(statusToIcon(NodePhase[status]));
expect(tree).toMatchSnapshot();
})
));
});

Object.keys(NodePhase).map(status => (
it('renders an icon with tooltip for phase: ' + status, () => {
const tree = shallow(statusToIcon(NodePhase[status]));
expect(tree).toMatchSnapshot();
})
));
describe('hasCompleted', () => {
[NodePhase.ERROR, NodePhase.FAILED, NodePhase.SUCCEEDED, NodePhase.SKIPPED].forEach(status =>
it(`returns \'true\' to true if status is: ${status}`, () => {
expect(hasCompleted(status)).toBe(true);
})
);

[NodePhase.PENDING, NodePhase.RUNNING, NodePhase.UNKNOWN].forEach(status =>
it(`returns \'false\' to true if status is: ${status}`, () => {
expect(hasCompleted(status)).toBe(false);
})
);

it('returns \'false\' to true if status is undefined', () => {
expect(hasCompleted(undefined)).toBe(false);
});
});
});
16 changes: 8 additions & 8 deletions frontend/src/pages/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function hasCompleted(status?: NodePhase): boolean {
return false;
}

switch(status) {
switch (status) {
case NodePhase.SUCCEEDED: // Fall through
case NodePhase.FAILED: // Fall through
case NodePhase.ERROR: // Fall through
Expand Down Expand Up @@ -98,13 +98,13 @@ export function statusToIcon(status: NodePhase, startDate?: Date | string, endDa

return (
<Tooltip title={
<div>
<div>{title}</div>
{/* These dates may actually be strings, not a Dates due to a bug in swagger's handling of dates */}
{startDate && (<div>Start: {formatDateString(startDate)}</div>)}
{endDate && (<div>End: {formatDateString(endDate)}</div>)}
</div>
}>
<div>
<div>{title}</div>
{/* These dates may actually be strings, not a Dates due to a bug in swagger's handling of dates */}
{startDate && (<div>Start: {formatDateString(startDate)}</div>)}
{endDate && (<div>End: {formatDateString(endDate)}</div>)}
</div>
}>
<span style={{ height: 18 }}>
<IconComponent style={{ color: iconColor, height: 18, width: 18 }} />
</span>
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/pages/__snapshots__/Status.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Status displays start and end dates if both are provided 1`] = `
exports[`Status statusToIcon displays start and end dates if both are provided 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -422,7 +422,7 @@ exports[`Status displays start and end dates if both are provided 1`] = `
</Tooltip>
`;

exports[`Status does not display a end date if none was provided 1`] = `
exports[`Status statusToIcon does not display a end date if none was provided 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -840,7 +840,7 @@ exports[`Status does not display a end date if none was provided 1`] = `
</Tooltip>
`;

exports[`Status does not display a start date if none was provided 1`] = `
exports[`Status statusToIcon does not display a start date if none was provided 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -1258,7 +1258,7 @@ exports[`Status does not display a start date if none was provided 1`] = `
</Tooltip>
`;

exports[`Status does not display any dates if neither was provided 1`] = `
exports[`Status statusToIcon does not display any dates if neither was provided 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -1672,7 +1672,7 @@ exports[`Status does not display any dates if neither was provided 1`] = `
</Tooltip>
`;

exports[`Status handles an unknown phase 1`] = `
exports[`Status statusToIcon handles an unknown phase 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -2086,7 +2086,7 @@ exports[`Status handles an unknown phase 1`] = `
</Tooltip>
`;

exports[`Status renders an icon with tooltip for phase: ERROR 1`] = `
exports[`Status statusToIcon renders an icon with tooltip for phase: ERROR 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -2500,7 +2500,7 @@ exports[`Status renders an icon with tooltip for phase: ERROR 1`] = `
</Tooltip>
`;

exports[`Status renders an icon with tooltip for phase: FAILED 1`] = `
exports[`Status statusToIcon renders an icon with tooltip for phase: FAILED 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -2914,7 +2914,7 @@ exports[`Status renders an icon with tooltip for phase: FAILED 1`] = `
</Tooltip>
`;

exports[`Status renders an icon with tooltip for phase: PENDING 1`] = `
exports[`Status statusToIcon renders an icon with tooltip for phase: PENDING 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -3328,7 +3328,7 @@ exports[`Status renders an icon with tooltip for phase: PENDING 1`] = `
</Tooltip>
`;

exports[`Status renders an icon with tooltip for phase: RUNNING 1`] = `
exports[`Status statusToIcon renders an icon with tooltip for phase: RUNNING 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -3742,7 +3742,7 @@ exports[`Status renders an icon with tooltip for phase: RUNNING 1`] = `
</Tooltip>
`;

exports[`Status renders an icon with tooltip for phase: SKIPPED 1`] = `
exports[`Status statusToIcon renders an icon with tooltip for phase: SKIPPED 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -4156,7 +4156,7 @@ exports[`Status renders an icon with tooltip for phase: SKIPPED 1`] = `
</Tooltip>
`;

exports[`Status renders an icon with tooltip for phase: SUCCEEDED 1`] = `
exports[`Status statusToIcon renders an icon with tooltip for phase: SUCCEEDED 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down Expand Up @@ -4570,7 +4570,7 @@ exports[`Status renders an icon with tooltip for phase: SUCCEEDED 1`] = `
</Tooltip>
`;

exports[`Status renders an icon with tooltip for phase: UNKNOWN 1`] = `
exports[`Status statusToIcon renders an icon with tooltip for phase: UNKNOWN 1`] = `
<Tooltip
TransitionComponent={[Function]}
classes={
Expand Down

0 comments on commit c5b0588

Please sign in to comment.