[JENKINS-35837] fix exceptions thrown by card when props were undefined

This commit is contained in:
Cliff Meyers 2016-07-06 14:22:37 -04:00
parent 1c8ba045a8
commit 0f4750c5b9
2 changed files with 10 additions and 2 deletions

View File

@ -22,7 +22,7 @@ import { Favorite, LiveStatusIndicator } from '@jenkins-cd/design-language';
export class PipelineCard extends Component {
static _getBackgroundClass(status) {
return status !== null && status.length > 0 ?
return status && status.length > 0 ?
`${status.toLowerCase()}-bg-lite` :
'';
}
@ -71,7 +71,7 @@ export class PipelineCard extends Component {
render() {
const { status } = this.props;
const bgClass = PipelineCard._getBackgroundClass(status);
const showRun = status && status.toLowerCase() === 'failure' || status.toLowerCase() === 'aborted';
const showRun = status && (status.toLowerCase() === 'failure' || status.toLowerCase() === 'aborted');
return (
<div className={`pipeline-card ${bgClass}`}>

View File

@ -8,6 +8,14 @@ import { shallow } from 'enzyme';
import { PipelineCard } from '../../../main/js/components/PipelineCard';
describe('PipelineCard', () => {
it('renders without error for empty props', () => {
const wrapper = shallow(
<PipelineCard />
);
assert.isOk(wrapper);
});
it('renders basic child elements', () => {
const status = 'SUCCESS';
const wrapper = shallow(