Skip to content

Commit

Permalink
fix(snapshot): add test plrs, capitalize breadcrumb and environment
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandan13jan committed Oct 31, 2023
1 parent 01b7b7b commit b78ff9a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/components/SnapshotDetails/SnapshotDetailsView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useK8sWatchResource } from '@openshift/dynamic-plugin-sdk-utils';
import { Bullseye, Spinner, Text, TextVariants } from '@patternfly/react-core';
import { Bullseye, Spinner, Text, TextVariants, capitalize } from '@patternfly/react-core';
import { useEnvironments } from '../../hooks/useEnvironments';
import { usePipelineRun } from '../../hooks/usePipelineRuns';
import { SnapshotEnvironmentBindingGroupVersionKind, SnapshotGroupVersionKind } from '../../models';
Expand Down Expand Up @@ -113,7 +113,7 @@ const SnapshotDetailsView: React.FC<SnapshotDetailsViewProps> = ({
...applicationBreadcrumbs,
{
path: `#`,
name: 'snapshots',
name: 'Snapshots',
},
{
path: `/application-pipeline/workspaces/${workspace}/applications/${applicationName}/snapshots/${snapshotName}`,
Expand Down Expand Up @@ -147,7 +147,7 @@ const SnapshotDetailsView: React.FC<SnapshotDetailsViewProps> = ({
<>
<StatusIconWithTextLabel
key={env.metadata?.name}
text={env.metadata.name}
text={capitalize(env.metadata.name)}
dataTestAttribute="snapshot-env-label"
status={isDeployed ? runStatus.Succeeded : runStatus.Cancelling}
/>{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ describe('SnapshotDetailsView', () => {
expect(screen.getByTestId('snapshot-name').innerHTML).toBe('my-test-output-1');
});

it('should display correct breadcrumbs', () => {
watchResourceMock.mockImplementation(getMockedResources);
routerRenderer(
<SnapshotDetails snapshotName="my-test-output-1" applicationName="my-test-output" />,
);
screen.getByText(/Snapshots/);
});

it('should show correct details', () => {
mockSnapshots[0].metadata.deletionTimestamp = '1';
watchResourceMock.mockImplementation(getMockedResources);
Expand Down
3 changes: 2 additions & 1 deletion src/components/SnapshotDetails/tabs/SnapshotOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FlexItem,
Skeleton,
Title,
capitalize,
} from '@patternfly/react-core';
import { ScanStatus } from '../../../components/PipelineRunListView/ScanStatus';
import { useScanResults } from '../../../hooks/useScanResults';
Expand Down Expand Up @@ -101,7 +102,7 @@ const SnapshotOverviewTab: React.FC<SnapshotOverviewTabProps> = ({
<Link
to={`/application-pipeline/workspaces/${workspace}/applications/${snapshot.spec.application}/deployments`}
>
{env}
{capitalize(env)}
</Link>
</div>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ToolbarGroup,
ToolbarItem,
debounce,
capitalize,
} from '@patternfly/react-core';
import {
Select,
Expand Down Expand Up @@ -183,7 +184,7 @@ const SnapshotPipelineRunsList: React.FC<SnapshotPipelineRunListProps> = ({
isChecked={typeFilters.includes(filter)}
itemCount={statusFilterObj[filter] ?? 0}
>
{filter}
{capitalize(filter)}
</SelectOption>
))}
</SelectGroup>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ const snapShotPLRs = [
spec: null,
status: null,
},

{
apiVersion: mockPipelineRuns[0].apiVersion,
kind: mockPipelineRuns[0].kind,
metadata: {
...mockPipelineRuns[2].metadata,
name: 'plr-with snapshot-label-only',
labels: {
...mockPipelineRuns[2].metadata.labels,
[PipelineRunLabel.PIPELINE_TYPE]: PipelineRunType.TEST,
[PipelineRunLabel.SNAPSHOT]: 'test-snapshot',
},
annotations: {
...mockPipelineRuns[2].metadata.annotations,
},
},
spec: null,
status: null,
},
];

describe('SnapshotPipelinerunsTab', () => {
Expand Down Expand Up @@ -175,6 +194,18 @@ describe('SnapshotPipelinerunsTab', () => {
);
});

it('should render pipelineruns with snapshot labels instead of annotations', () => {
render(
<SnapshotPipelineRunsList
applicationName={appName}
getNextPage={null}
snapshotPipelineRuns={snapShotPLRs}
loaded={true}
/>,
);
expect(screen.queryByText('plr-with snapshot-label-only')).toBeInTheDocument();
});

it('should render entire pipelineRuns list when no filter value', () => {
render(
<SnapshotPipelineRunsList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,37 @@ describe('SnapshotPipelinerunsTab', () => {
screen.queryByText('python-sample-942fq');
screen.queryByText('go-sample-s2f4f');
});

it('should render pipelineruns with Snapshot label instead of annotation as well', () => {
usePipelineRunsMock.mockReturnValue([
[
{
...mockPipelineRuns[0],
metadata: {
...mockPipelineRuns[0].metadata,
labels: {
...mockPipelineRuns[0].metadata.labels,
[PipelineRunLabel.PIPELINE_TYPE]: 'test',
[PipelineRunLabel.SNAPSHOT]: 'test-snapshot',
},
annotations: {
...mockPipelineRuns[2].metadata.annotations,
},
},
},
],
true,
false,
]);
render(
<SnapshotPipelineRunsTab
applicationName={appName}
namespace="test"
snapshotName="test-snapshot"
/>,
);

screen.queryByText('Test');
screen.queryByText('go-sample-s2f4f');
});
});

0 comments on commit b78ff9a

Please sign in to comment.