Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds spec for RevisionRow component #3833

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is wrong dependency. knative-plugin should have no dependency on dev-console packages. Not for this PR but create a task to fix this dependency issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have this dependency right now. Knative Plugin depends on dev-console to render stuff in topology and a lot of other such instances. We probably need to come up with a runtime extensibility framework to fully eliminate the dependency.

import RevisionRow from '../RevisionRow';
import { ConditionTypes } from '../../../types';

type RevisionRowProps = React.ComponentProps<typeof RevisionRow>;
let revData: RevisionRowProps;
describe('RevisionRow', () => {
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