Skip to content

Commit

Permalink
Merge pull request openshift#7547 from karthikjeeyar/pipeline-list-lo…
Browse files Browse the repository at this point in the history
…ader

Bug 1907888: Fix pipeline list page loader
  • Loading branch information
openshift-merge-robot authored Dec 22, 2020
2 parents 4d353ad + b434822 commit 092f305
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as _ from 'lodash';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { ListPageWrapper_ as ListPageWrapper } from '@console/internal/components/factory';
import { Firehose } from '@console/internal/components/utils';
import { EmptyBox, Firehose, LoadingBox } from '@console/internal/components/utils';
import { Resource, getResources } from '../../../utils/pipeline-augment';
import { PipelineModel } from '../../../models';
import PipelineAugmentRuns, { filters } from './PipelineAugmentRuns';
import PipelineList from './PipelineList';

Expand All @@ -14,13 +14,15 @@ interface PipelineAugmentRunsWrapperProps {
}

const PipelineAugmentRunsWrapper: React.FC<PipelineAugmentRunsWrapperProps> = (props) => {
const { t } = useTranslation();
const pipelineData = _.get(props.pipeline, 'data', []);
if (pipelineData.length < 1) {
return (
<div className="cos-status-box">
<div className="text-center">No {PipelineModel.labelPlural} Found</div>
</div>
);

if (!props.pipeline.loaded) {
return <LoadingBox />;
}

if (pipelineData.length === 0) {
return <EmptyBox label={t('pipelines-plugin~Pipelines')} />;
}
const firehoseResources: Resource = getResources(props.pipeline.data);
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { EmptyBox, LoadingBox } from '@console/internal/components/utils';
import { ListPageWrapper_ as ListPageWrapper } from '@console/internal/components/factory';
import { PipelineExampleNames, pipelineTestData } from '../../../../test-data/pipeline-data';
import PipelineAugmentRunsWrapper from '../PipelineAugmentRunsWrapper';

const mockData = pipelineTestData[PipelineExampleNames.WORKSPACE_PIPELINE];
const { pipeline } = mockData;

type PipelineAugmentRunsWrapperProps = React.ComponentProps<typeof PipelineAugmentRunsWrapper>;

jest.mock('react-i18next', () => {
const reactI18next = require.requireActual('react-i18next');
return {
...reactI18next,
useTranslation: () => ({ t: (key) => key }),
};
});

describe('Pipeline Augment Run Wrapper', () => {
let pipelineAugmentRunsWrapperProps: PipelineAugmentRunsWrapperProps;
let wrapper: ShallowWrapper;
beforeEach(() => {
pipelineAugmentRunsWrapperProps = {
pipeline: {
data: [pipeline],
loaded: false,
},
};
wrapper = shallow(<PipelineAugmentRunsWrapper {...pipelineAugmentRunsWrapperProps} />);
});

it('Should render loader if data not yet loaded', () => {
expect(wrapper.find(LoadingBox).exists()).toBeTruthy();
});

it('Should render the EmptyBox if the data is empty', () => {
wrapper.setProps({ pipeline: { data: [], loaded: true } });
expect(wrapper.find(EmptyBox).exists()).toBeTruthy();
});

it('Should render ListpageWrapper if the pipeline data is loaded and available', () => {
wrapper.setProps({ pipeline: { data: [pipeline], loaded: true } });
expect(wrapper.find(ListPageWrapper).exists()).toBeTruthy();
});
});

0 comments on commit 092f305

Please sign in to comment.