Skip to content

Commit

Permalink
fix(snapshot): capitalise environment
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandan13jan committed Nov 23, 2023
1 parent e14e0e7 commit 13c47d0
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8329,6 +8329,33 @@ export const MockEnvironments = [
},
];

export const MockEnvironmentsWithoutDisplayName = [
{
apiVersion: 'appstudio.redhat.com/v1alpha1',
kind: 'Environment',
metadata: {
annotations: {
'toolchain.dev.openshift.com/last-applied-configuration':
'{"apiVersion":"appstudio.redhat.com/v1alpha1","kind":"Environment","metadata":{"labels":{"toolchain.dev.openshift.com/owner":"jephilli","toolchain.dev.openshift.com/provider":"codeready-toolchain"},"name":"development","namespace":"jephilli-tenant"},"spec":{"deploymentStrategy":"AppStudioAutomated","displayName":"Development","type":"Non-POC"}}',
},
resourceVersion: '14576436',
name: 'test',
uid: '68aea4ae-d422-4f73-8baa-9a1f5d8eaee7',
creationTimestamp: '2023-03-01T11:47:57Z',
generation: 1,
namespace: 'jephilli-tenant',
labels: {
'toolchain.dev.openshift.com/owner': 'jephilli',
'toolchain.dev.openshift.com/provider': 'codeready-toolchain',
},
},
spec: {
deploymentStrategy: 'AppStudioAutomated',
type: 'Non-POC',
},
},
];

export const MockSnapshotsEB = [
{
apiVersion: 'appstudio.redhat.com/v1alpha1',
Expand Down
9 changes: 6 additions & 3 deletions src/components/SnapshotDetails/SnapshotDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ErrorEmptyState from '../../shared/components/empty-state/ErrorEmptyState
import { LoadingBox } from '../../shared/components/status-box/StatusBox';
import { Timestamp } from '../../shared/components/timestamp/Timestamp';
import { HttpError } from '../../shared/utils/error/http-error';
import { EnvironmentKind } from '../../types';
import { Snapshot, SnapshotEnvironmentBinding } from '../../types/coreBuildService';
import { useApplicationBreadcrumbs } from '../../utils/breadcrumb-utils';
import { createCommitObjectFromPLR } from '../../utils/commits-utils';
Expand Down Expand Up @@ -63,7 +64,7 @@ const SnapshotDetailsView: React.FC<SnapshotDetailsViewProps> = ({
isList: true,
});

const deployedEnvironments = React.useMemo(() => {
const deployedEnvironments: EnvironmentKind[] = React.useMemo(() => {
const envList = [];
sebLoaded &&
!sebLoadError &&
Expand All @@ -76,7 +77,7 @@ const SnapshotDetailsView: React.FC<SnapshotDetailsViewProps> = ({
seb.spec?.snapshot === snapshot?.metadata?.name,
);
if (snapshotWithEnvironment) {
envList.push(env?.metadata.name);
envList.push(env);
}
});
return envList;
Expand Down Expand Up @@ -141,7 +142,9 @@ const SnapshotDetailsView: React.FC<SnapshotDetailsViewProps> = ({
</Text>
<Text component={TextVariants.p} data-test="snapshot-commit-label">
{environments?.map((env) => {
const isDeployed = deployedEnvironments.includes(env.metadata?.name);
const isDeployed = deployedEnvironments.find(
(e) => e.metadata.name === env.metadata?.name,
);
return (
<>
<StatusIconWithTextLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { pipelineWithCommits } from '../../Commits/__data__/pipeline-with-commit
import { useCommitStatus } from '../../Commits/commit-status';
import {
MockEnvironments,
MockEnvironmentsWithoutDisplayName,
MockSnapshots,
} from '../../Commits/CommitDetails/visualization/__data__/MockCommitWorkflowData';
import SnapshotDetails from '../SnapshotDetailsView';
Expand Down Expand Up @@ -104,20 +105,32 @@ describe('SnapshotDetailsView', () => {
routerRenderer(
<SnapshotDetails snapshotName="my-test-output-1" applicationName="my-test-output" />,
);
screen.getByText(/Snapshots/);
expect(screen.getByText(/Snapshots/)).toBeInTheDocument();
});

it('should show environment name in details', () => {
watchResourceMock.mockImplementation(getMockedResources);
mockUseEnvironments.mockReturnValue([MockEnvironmentsWithoutDisplayName, true]);
routerRenderer(
<SnapshotDetails snapshotName="my-test-output-1" applicationName="my-test-output" />,
);
screen.getByText('Deployed to');
screen.getByText('Development');
expect(screen.getByText('Deployed to')).toBeInTheDocument();
expect(screen.getByText('test')).toBeInTheDocument();
});

it('should show environment display name instead of metadata', () => {
watchResourceMock.mockImplementation(getMockedResources);
mockUseEnvironments.mockReturnValue([MockEnvironments, true]);
routerRenderer(
<SnapshotDetails snapshotName="my-test-output-1" applicationName="my-test-output" />,
);
expect(screen.getByText('Deployed to')).toBeInTheDocument();
expect(screen.getByText('Development')).toBeInTheDocument();
});

it('should show environment label in header', () => {
watchResourceMock.mockImplementation(getMockedResources);
mockUseEnvironments.mockReturnValue([MockEnvironments, true]);
routerRenderer(
<SnapshotDetails snapshotName="my-test-output-1" applicationName="my-test-output" />,
);
Expand Down
9 changes: 4 additions & 5 deletions src/components/SnapshotDetails/tabs/SnapshotOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
FlexItem,
Skeleton,
Title,
capitalize,
} from '@patternfly/react-core';
import { ScanStatus } from '../../../components/PipelineRunListView/ScanStatus';
import { useScanResults } from '../../../hooks/useScanResults';
import { Timestamp } from '../../../shared/components/timestamp/Timestamp';
import { Commit } from '../../../types';
import { Commit, EnvironmentKind } from '../../../types';
import { Snapshot } from '../../../types/coreBuildService';
import { useWorkspaceInfo } from '../../../utils/workspace-context-utils';
import EnvironmentProvisionErrorAlert from '../EnvironmentProvisionErrorAlert';
Expand All @@ -26,7 +25,7 @@ interface SnapshotOverviewTabProps {
snapshot: Snapshot;
commit?: Commit;
buildPipelineName?: string;
environments?: string[];
environments?: EnvironmentKind[];
}

const SnapshotOverviewTab: React.FC<SnapshotOverviewTabProps> = ({
Expand Down Expand Up @@ -105,11 +104,11 @@ const SnapshotOverviewTab: React.FC<SnapshotOverviewTabProps> = ({
<EnvironmentProvisionErrorAlert errorStatus={errorStatus} />
) : (
environments.map((env) => (
<div key={env}>
<div key={env.metadata.name}>
<Link
to={`/application-pipeline/workspaces/${workspace}/applications/${snapshot.spec.application}/deployments`}
>
{capitalize(env)}
{env.spec?.displayName ?? env.metadata?.name}
</Link>
</div>
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ describe('SnapshotOverview', () => {
routerRenderer(
<SnapshotOverview
snapshot={mockSnapshots[0]}
environments={['test']}
environments={[
{ kind: 'Environment', apiVersion: 'v1', metadata: { name: 'test' }, spec: null },
]}
buildPipelineName="build-pipeline"
/>,
);
screen.getByText('Created at');
screen.getByText('Deployed to');
screen.getByText('Vulnerabilities');
expect(screen.getByText('Created at')).toBeInTheDocument();
expect(screen.getByText('Deployed to')).toBeInTheDocument();
expect(screen.getByText('Vulnerabilities')).toBeInTheDocument();
});

it('should display commit data and link for snapshots with commit data', () => {
Expand Down Expand Up @@ -112,6 +114,19 @@ describe('SnapshotOverview', () => {
screen.queryByText('Failed for app-sample-go-basic-enterprise-contract');
});

it('should display failed scenario', () => {
watchResourceMock.mockImplementation(getMockedResources);
routerRenderer(
<SnapshotOverview
snapshot={mockSnapshots[1]}
buildPipelineName="build-pipeline"
commit={mockCommits[0]}
/>,
);
expect(screen.queryByTestId('env-provision-err-alert')).toBeInTheDocument();
expect(screen.queryByText('scn 2')).toBeInTheDocument();
});

it('should hide ErrorAlert when different error occurs and display deployment name', () => {
watchResourceMock.mockImplementation(getMockedResources);
routerRenderer(
Expand All @@ -125,3 +140,45 @@ describe('SnapshotOverview', () => {
screen.queryByText('development');
});
});

describe('SnapshotOverview environments', () => {
it('should show Environment display name', () => {
mockSnapshots[2].metadata.deletionTimestamp = '1';
watchResourceMock.mockImplementation(getMockedResources);
routerRenderer(
<SnapshotOverview
snapshot={mockSnapshots[2]}
environments={[
{
kind: 'Environment',
apiVersion: 'v1',
metadata: { name: 'test' },
spec: { displayName: 'test-env', deploymentStrategy: null },
},
]}
buildPipelineName="build-pipeline"
/>,
);
expect(screen.getByText('test-env')).toBeInTheDocument();
});

it('should display Environment metadata name when display name not exists', () => {
mockSnapshots[2].metadata.deletionTimestamp = '1';
watchResourceMock.mockImplementation(getMockedResources);
routerRenderer(
<SnapshotOverview
snapshot={mockSnapshots[2]}
environments={[
{
kind: 'Environment',
apiVersion: 'v1',
metadata: { name: 'test' },
spec: null,
},
]}
buildPipelineName="build-pipeline"
/>,
);
expect(screen.getByText('test')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ describe('snapshot-utils', () => {
});

it('should return formatted error status', () => {
const result = getEnvironmentProvisionError(MockSnapshots[0]);
expect(result.length).toBe(2);
expect(result[0].scenario).toBe('scn 2');
});

it('should filter out single error ', () => {
const result = getEnvironmentProvisionError(MockSnapshots[1]);
expect(result.length).toBe(1);
});
});

describe('snapshot-utils error', () => {
it('should show correct scenario', () => {
const result = getEnvironmentProvisionError(MockSnapshots[1]);
expect(result[0].scenario).toBe('app-sample-go-basic-enterprise-contract');
});

Expand Down

0 comments on commit 13c47d0

Please sign in to comment.