-
Notifications
You must be signed in to change notification settings - Fork 670
updates test and refactors component for RevisionsOverviewList #3752
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
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
invincibleJai:fix-add-unit-revoverviewlist
Jan 3, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 3 additions & 74 deletions
77
frontend/packages/knative-plugin/src/components/overview/RevisionsOverviewList.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
frontend/packages/knative-plugin/src/components/overview/RevisionsOverviewListItem.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .odc-revision-deployment-list { | ||
| padding: var(--pf-global--spacer--md) var(--pf-global--spacer--lg) var(--pf-global--spacer--sm); | ||
| &__pod { | ||
| width: var(--pf-global--icon--FontSize--lg); | ||
| cursor: default; | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
frontend/packages/knative-plugin/src/components/overview/RevisionsOverviewListItem.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import * as React from 'react'; | ||
| import * as _ from 'lodash'; | ||
| import { PodStatus } from '@console/shared'; | ||
| import { ChartLabel } from '@patternfly/react-charts'; | ||
| import { K8sResourceKind, referenceForModel } from '@console/internal/module/k8s'; | ||
| import { ResourceLink } from '@console/internal/components/utils'; | ||
| import { RevisionModel } from '@console/knative-plugin'; | ||
| import './RevisionsOverviewListItem.scss'; | ||
|
|
||
| export type RevisionsOverviewListItemProps = { | ||
| revision: K8sResourceKind; | ||
| service: K8sResourceKind; | ||
| }; | ||
|
|
||
| const RevisionsOverviewListItem: React.FC<RevisionsOverviewListItemProps> = ({ | ||
| revision, | ||
| service, | ||
| }) => { | ||
| const { | ||
| metadata: { name, namespace }, | ||
| } = revision; | ||
| const { | ||
| status: { traffic }, | ||
| } = service; | ||
| const getTraffic = (revName: string) => { | ||
| if (!traffic || !traffic.length) { | ||
| return null; | ||
| } | ||
| const trafficPercent = _.get(_.find(traffic, { revisionName: revName }), 'percent', null); | ||
| return trafficPercent ? `${trafficPercent}%` : null; | ||
| }; | ||
| const deploymentData = _.get(revision, 'resources.current.obj.metadata.ownerReferences[0]', {}); | ||
| const current = _.get(revision, 'resources.current', null); | ||
| const availableReplicas = _.get(revision, 'resources.current.obj.status.availableReplicas', '0'); | ||
| return ( | ||
| <li className="list-group-item"> | ||
| <div className="row"> | ||
| <div className="col-sm-8 col-xs-9"> | ||
| <ResourceLink kind={referenceForModel(RevisionModel)} name={name} namespace={namespace} /> | ||
| </div> | ||
| <span className="col-sm-4 col-xs-3 text-right">{getTraffic(name)}</span> | ||
| </div> | ||
| {deploymentData.name && ( | ||
| <div className="odc-revision-deployment-list"> | ||
| <div className="row"> | ||
| <div className="col-sm-8 col-xs-9"> | ||
| <ResourceLink | ||
| kind={deploymentData.kind} | ||
| name={deploymentData.name} | ||
| namespace={namespace} | ||
| /> | ||
| </div> | ||
| <div className="col-sm-4 col-xs-3"> | ||
| <div className="odc-revision-deployment-list__pod"> | ||
| <PodStatus | ||
| standalone | ||
| data={current ? current.pods : []} | ||
| size={25} | ||
| innerRadius={8} | ||
| outerRadius={12} | ||
| title={availableReplicas} | ||
| titleComponent={<ChartLabel style={{ fontSize: '10px' }} />} | ||
| showTooltip={false} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </li> | ||
| ); | ||
| }; | ||
|
|
||
| export default RevisionsOverviewListItem; |
29 changes: 0 additions & 29 deletions
29
frontend/packages/knative-plugin/src/components/overview/__mocks__/overview-knative-mock.ts
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
.../packages/knative-plugin/src/components/overview/__tests__/RevisionsOverviewList.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import * as React from 'react'; | ||
| import { shallow, ShallowWrapper } from 'enzyme'; | ||
| import { Button } from '@patternfly/react-core'; | ||
| import * as utils from '@console/internal/components/utils'; | ||
| import { MockKnativeResources } from '@console/dev-console/src/components/topology/__tests__/topology-knative-test-data'; | ||
| import * as modal from '../../modals'; | ||
| import RevisionsOverviewList, { RevisionsOverviewListProps } from '../RevisionsOverviewList'; | ||
| import RevisionsOverviewListItem from '../RevisionsOverviewListItem'; | ||
|
|
||
| describe('RevisionsOverviewList', () => { | ||
| let wrapper: ShallowWrapper<RevisionsOverviewListProps>; | ||
| beforeEach(() => { | ||
| wrapper = shallow( | ||
| <RevisionsOverviewList | ||
| revisions={MockKnativeResources.revisions.data} | ||
| service={MockKnativeResources.ksservices.data[0]} | ||
| />, | ||
| ); | ||
| }); | ||
|
|
||
| it('should have title Revisions', () => { | ||
| expect(wrapper.find(utils.SidebarSectionHeading)).toHaveLength(1); | ||
| expect( | ||
| wrapper | ||
| .find(utils.SidebarSectionHeading) | ||
| .at(0) | ||
| .props().text, | ||
| ).toEqual('Revisions'); | ||
| }); | ||
|
|
||
| it('should show info if no Revisions present and traffic split sshould button should be disabled', () => { | ||
| const spyUseAccessReview = jest.spyOn(utils, 'useAccessReview'); | ||
| spyUseAccessReview.mockReturnValue(true); | ||
| wrapper = shallow( | ||
| <RevisionsOverviewList revisions={[]} service={MockKnativeResources.revisions.data[0]} />, | ||
| ); | ||
| expect(wrapper.find('span')).toHaveLength(1); | ||
| expect(wrapper.text().includes('No Revisions found for this resource.')).toBe(true); | ||
| expect( | ||
| wrapper | ||
| .find(Button) | ||
| .at(0) | ||
| .props().isDisabled, | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('should have button for traffic distribution and enabled', () => { | ||
| const spyUseAccessReview = jest.spyOn(utils, 'useAccessReview'); | ||
| spyUseAccessReview.mockReturnValue(true); | ||
| expect(wrapper.find(Button)).toHaveLength(1); | ||
| expect( | ||
| wrapper | ||
| .find(Button) | ||
| .at(0) | ||
| .props().children, | ||
| ).toEqual('Set Traffic Distribution'); | ||
| expect( | ||
| wrapper | ||
| .find(Button) | ||
| .at(0) | ||
| .props().isDisabled, | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it('should call setTrafficDistributionModal on click', () => { | ||
| const spySetTrafficDistributionModal = jest.spyOn(modal, 'setTrafficDistributionModal'); | ||
| expect(wrapper.find(Button)).toHaveLength(1); | ||
| wrapper.find(Button).simulate('click'); | ||
| expect(spySetTrafficDistributionModal).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not show button for traffic distribution if access is not there', () => { | ||
| const spyUseAccessReview = jest.spyOn(utils, 'useAccessReview'); | ||
| spyUseAccessReview.mockReturnValue(false); | ||
| wrapper = shallow( | ||
| <RevisionsOverviewList | ||
| revisions={MockKnativeResources.revisions.data} | ||
| service={MockKnativeResources.revisions.data[0]} | ||
| />, | ||
| ); | ||
| expect(wrapper.find(Button).exists()).toBe(false); | ||
| }); | ||
|
|
||
| it('should render RevisionsOverviewListItem', () => { | ||
| expect(wrapper.find(RevisionsOverviewListItem)).toHaveLength(1); | ||
| }); | ||
| }); | ||
invincibleJai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use pf variables for padding and width here?