Skip to content

Commit

Permalink
adds spec for RevisionRow component
Browse files Browse the repository at this point in the history
  • Loading branch information
invincibleJai committed Dec 27, 2019
1 parent 28cfe3b commit e7fa628
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FirehoseResult } from '@console/internal/components/utils';
import { DeploymentKind, PodKind } from '@console/internal/module/k8s';
import { DeploymentKind, PodKind, K8sResourceConditionStatus } from '@console/internal/module/k8s';
import {
ConfigurationModel,
RouteModel,
Expand All @@ -9,6 +9,8 @@ import {
EventSourceContainerModel,
EventSourceCamelModel,
EventSourceKafkaModel,
ConditionTypes,
RevisionKind,
} from '@console/knative-plugin';
import { TopologyDataResources } from '../topology-types';

Expand Down Expand Up @@ -221,43 +223,72 @@ const sampleKnativeConfigurations: FirehoseResult = {
],
};

export const revisionObj: RevisionKind = {
apiVersion: `${RevisionModel.apiGroup}/${RevisionModel.apiVersion}`,
kind: RevisionModel.kind,
metadata: {
name: 'overlayimage-fdqsf',
namespace: 'testproject3',
selfLink: '/api/v1/namespaces/testproject3/revisions/overlayimage',
uid: '02c34a0e-9638-11e9-b134-06a61d886b62',
resourceVersion: '1157349',
creationTimestamp: '2019-06-12T07:07:57Z',
labels: {
'serving.knative.dev/configuration': 'overlayimage',
'serving.knative.dev/configurationGeneration': '2',
'serving.knative.dev/service': 'overlayimage',
},
ownerReferences: [
{
apiVersion: `${ConfigurationModel.apiGroup}/${ConfigurationModel.apiVersion}`,
kind: RouteModel.kind,
name: 'overlayimage',
uid: '1317f615-9636-11e9-b134-06a61d886b62',
controller: true,
blockOwnerDeletion: true,
},
],
},
spec: {},
status: {
observedGeneration: 1,
serviceName: 'overlayimage-fdqsf',
conditions: [
{
lastTransitionTime: '2019-12-27T05:07:47Z',
message: 'The target is not receiving traffic.',
reason: 'NoTraffic',
status: K8sResourceConditionStatus.False,
type: ConditionTypes.Active,
},
{
lastTransitionTime: '2019-12-27T05:06:47Z',
status: K8sResourceConditionStatus.True,
type: ConditionTypes.ContainerHealthy,
message: '',
reason: '',
},
{
lastTransitionTime: '2019-12-27T05:06:47Z',
status: K8sResourceConditionStatus.True,
type: ConditionTypes.Ready,
message: '',
reason: '',
},
{
lastTransitionTime: '2019-12-27T05:06:16Z',
status: K8sResourceConditionStatus.True,
type: ConditionTypes.ResourcesAvailable,
message: '',
reason: '',
},
],
},
};
const sampleKnativeRevisions: FirehoseResult = {
loaded: true,
loadError: '',
data: [
{
apiVersion: `${RevisionModel.apiGroup}/${RevisionModel.apiVersion}`,
kind: RevisionModel.kind,
metadata: {
name: 'overlayimage-fdqsf',
namespace: 'testproject3',
selfLink: '/api/v1/namespaces/testproject3/revisions/overlayimage',
uid: '02c34a0e-9638-11e9-b134-06a61d886b62',
resourceVersion: '1157349',
creationTimestamp: '2019-06-12T07:07:57Z',
labels: {
'serving.knative.dev/configuration': 'overlayimage',
'serving.knative.dev/configurationGeneration': '2',
'serving.knative.dev/service': 'overlayimage',
},
ownerReferences: [
{
apiVersion: `${ConfigurationModel.apiGroup}/${ConfigurationModel.apiVersion}`,
kind: RouteModel.kind,
name: 'overlayimage',
uid: '1317f615-9636-11e9-b134-06a61d886b62',
controller: true,
blockOwnerDeletion: true,
},
],
},
spec: {},
status: {
observedGeneration: 1,
serviceName: 'overlayimage-fdqsf',
},
},
],
data: [revisionObj],
};

export const sampleKnativeRoutes: FirehoseResult = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import * as _ from 'lodash';
import { TableData } from '@console/internal/components/factory';
import { ResourceLink } from '@console/internal/components/utils';
import { K8sResourceConditionStatus } from '@console/internal/module/k8s';
import { revisionObj } from '@console/dev-console/src/components/topology/__tests__/topology-knative-test-data';
import RevisionRow from '../RevisionRow';
import { ConditionTypes } from '../../../types';

type RevisionRowProps = React.ComponentProps<typeof RevisionRow>;
let revData: RevisionRowProps;
describe('RoutesOverviewList', () => {
beforeEach(() => {
revData = {
obj: revisionObj,
index: 0,
style: {
height: 'auto',
left: 0,
position: 'absolute',
top: 0,
width: '100%',
},
};
});

it('should show ResourceLink for associated service', () => {
const wrapper = shallow(<RevisionRow {...revData} />);
const serviceDataTable = wrapper.find(TableData).at(2);
expect(wrapper.find(TableData)).toHaveLength(8);
expect(serviceDataTable.find(ResourceLink)).toHaveLength(1);
expect(serviceDataTable.find(ResourceLink).props().kind).toEqual(
'serving.knative.dev~v1beta1~Service',
);
});

it('should not show ResourceLink for associated service if not found in labels', () => {
revData.obj.metadata = {
...revData.obj.metadata,
...{
labels: {
'serving.knative.dev/configuration': 'overlayimage',
'serving.knative.dev/configurationGeneration': '2',
},
},
};
const wrapper = shallow(<RevisionRow {...revData} />);
const serviceDataTable = wrapper.find(TableData).at(2);
expect(wrapper.find(TableData)).toHaveLength(8);
expect(serviceDataTable.find(ResourceLink)).toHaveLength(0);
});

it('should show appropriate conditions', () => {
const wrapper = shallow(<RevisionRow {...revData} />);
const conditionColData = wrapper.find(TableData).at(4);
expect(conditionColData.props().children).toEqual('3 OK / 4');
});

it('should show "-" in case of no status', () => {
revData = _.omit(revData, 'obj.status');
const wrapper = shallow(<RevisionRow {...revData} />);
const conditionColData = wrapper.find(TableData).at(4);
expect(conditionColData.props().children).toEqual('-');
});

it('should show appropriate ready status and reason for ready state', () => {
const wrapper = shallow(<RevisionRow {...revData} />);
const readyColData = wrapper.find(TableData).at(5);
const reasonColData = wrapper.find(TableData).at(6);
expect(readyColData.props().children).toEqual('True');
expect(reasonColData.props().children).toEqual('-');
});

it('should show appropriate ready status and reason for not ready state', () => {
revData.obj.status = {
...revData.obj.status,
...{
conditions: [
{
lastTransitionTime: '2019-12-27T05:06:47Z',
status: K8sResourceConditionStatus.False,
type: ConditionTypes.Ready,
message: 'Something went wrong.',
reason: 'Something went wrong.',
},
],
},
};
const wrapper = shallow(<RevisionRow {...revData} />);
const readyColData = wrapper.find(TableData).at(5);
const reasonColData = wrapper.find(TableData).at(6);
expect(readyColData.props().children).toEqual('False');
expect(reasonColData.props().children).toEqual('Something went wrong.');
});
});
1 change: 1 addition & 0 deletions frontend/packages/knative-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './const';
export * from './models';
export * from './utils/create-knative-utils';
export * from './utils/get-knative-icon';
export * from './types';
3 changes: 3 additions & 0 deletions frontend/packages/knative-plugin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export type RouteKind = {

export enum ConditionTypes {
Ready = 'Ready',
Active = 'Active',
ContainerHealthy = 'ContainerHealthy',
ResourcesAvailable = 'ResourcesAvailable',
}

export type Traffic = {
Expand Down

0 comments on commit e7fa628

Please sign in to comment.