Skip to content

Commit

Permalink
chore: Add snapshot tests for registry configuration (#130)
Browse files Browse the repository at this point in the history
Jira: EPMDPEDP-13007
Related: #130
Change-Id: I716355d7b12d6e5f4d456f464896f3b3f3c2fc7c
  • Loading branch information
callmevladik committed Jan 5, 2024
1 parent 95131d5 commit 4024cb8
Show file tree
Hide file tree
Showing 18 changed files with 6,580 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/HeadlampTileChart/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TileChart } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import { TileChartProps } from '@kinvolk/headlamp-plugin/lib/components/common/TileChart/TileChart';
import { makeStyles } from '@material-ui/core';
import React from 'react';

const useStyles = makeStyles(() => ({
root: {
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
registerRoute,
registerSidebarEntry,
} from '@kinvolk/headlamp-plugin/lib';
import React from 'react';
import { LogoWithText } from './Logo';
import routes from './routes';
import { SIDEBAR_LIST } from './routes/sidebar-list';
Expand Down
43 changes: 43 additions & 0 deletions src/k8s/ConfigMap/mocks/edp-config-map.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ValueOf } from '../../../types/global';
import { CONTAINER_REGISTRY_PLATFORM, CONTAINER_REGISTRY_TYPE } from '../constants';

export const createEmptyEdpConfigMapMock = (
platform: ValueOf<typeof CONTAINER_REGISTRY_PLATFORM>
) => ({
metadata: {
name: 'edp-config',
namespace: 'test-namespace',
},
data: {
aws_region: 'eu-central-1',
container_registry_host: 'registry.test.com',
container_registry_space: 'test-namespace',
container_registry_type: '',
dns_wildcard: 'test-dns-wildcard',
edp_name: 'test-namespace',
edp_version: '3.8.0-SNAPSHOT.23',
platform: platform,
},
kind: 'ConfigMap',
});

export const createEdpConfigMapMock = (
type: ValueOf<typeof CONTAINER_REGISTRY_TYPE>,
platform: ValueOf<typeof CONTAINER_REGISTRY_PLATFORM>
) => ({
metadata: {
name: 'edp-config',
namespace: 'test-namespace',
},
data: {
aws_region: 'eu-central-1',
container_registry_host: 'registry.test.com',
container_registry_space: 'test-namespace',
container_registry_type: type,
dns_wildcard: 'test-dns-wildcard',
edp_name: 'test-namespace',
edp_version: '3.8.0-SNAPSHOT.23',
platform: platform,
},
kind: 'ConfigMap',
});
65 changes: 65 additions & 0 deletions src/k8s/Secret/mocks/kaniko-config-secret.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Encoded data
"auths": {
"registry.test.com": {
"username": "test-username",
"password": "test-password",
"auth": "test-auth"
}
}
*/

export const kanikoDockerSecretMock = {
metadata: {
name: 'kaniko-docker-config',
namespace: 'test-namespace',
labels: {
'app.edp.epam.com/integration-secret': 'true',
'app.edp.epam.com/secret-type': 'registry',
},
annotations: {
'app.edp.epam.com/integration-secret-connected': 'true',
},
},
immutable: false,
data: {
'.dockerconfigjson':
'eyJhdXRocyI6eyJyZWdpc3RyeS50ZXN0LmNvbSI6eyJ1c2VybmFtZSI6InRlc3QtdXNlcm5hbWUiLCJwYXNzd29yZCI6InRlc3QtcGFzc3dvcmQiLCJhdXRoIjoidGVzdC1hdXRoIn19fQ==',
},
type: 'kubernetes.io/dockerconfigjson',
kind: 'Secret',
apiVersion: 'v1',
};

export const kanikoDockerSecretWithOwnerMock = {
metadata: {
name: 'kaniko-docker-config',
namespace: 'test-namespace',
labels: {
'app.edp.epam.com/integration-secret': 'true',
'app.edp.epam.com/secret-type': 'registry',
},
annotations: {
'app.edp.epam.com/integration-secret-connected': 'true',
},
ownerReferences: [
{
apiVersion: 'external-secrets.io/v1beta1',
kind: 'ExternalSecret',
name: 'kaniko-docker-config',
controller: true,
blockOwnerDeletion: true,
},
],
},
immutable: false,
data: {
'.dockerconfigjson':
'eyJhdXRocyI6eyJyZWdpc3RyeS50ZXN0LmNvbSI6eyJ1c2VybmFtZSI6InRlc3QtdXNlcm5hbWUiLCJwYXNzd29yZCI6InRlc3QtcGFzc3dvcmQiLCJhdXRoIjoidGVzdC1hdXRoIn19fQ==',
},
type: 'kubernetes.io/dockerconfigjson',
kind: 'Secret',
apiVersion: 'v1',
};
65 changes: 65 additions & 0 deletions src/k8s/Secret/mocks/regcred-config-secret.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Encoded data
"auths": {
"registry.test.com": {
"username": "test-username",
"password": "test-password",
"auth": "test-auth"
}
}
*/

export const regcredSecretMock = {
metadata: {
name: 'regcred',
namespace: 'test-namespace',
labels: {
'app.edp.epam.com/integration-secret': 'true',
'app.edp.epam.com/secret-type': 'registry',
},
annotations: {
'app.edp.epam.com/integration-secret-connected': 'true',
},
},
immutable: false,
data: {
'.dockerconfigjson':
'eyJhdXRocyI6eyJyZWdpc3RyeS50ZXN0LmNvbSI6eyJ1c2VybmFtZSI6InRlc3QtdXNlcm5hbWUiLCJwYXNzd29yZCI6InRlc3QtcGFzc3dvcmQiLCJhdXRoIjoidGVzdC1hdXRoIn19fQ==',
},
type: 'kubernetes.io/dockerconfigjson',
kind: 'Secret',
apiVersion: 'v1',
};

export const regcredSecretWithOwnerMock = {
metadata: {
name: 'regcred',
namespace: 'test-namespace',
labels: {
'app.edp.epam.com/integration-secret': 'true',
'app.edp.epam.com/secret-type': 'registry',
},
annotations: {
'app.edp.epam.com/integration-secret-connected': 'true',
},
ownerReferences: [
{
apiVersion: 'external-secrets.io/v1beta1',
kind: 'ExternalSecret',
name: 'regcred',
controller: true,
blockOwnerDeletion: true,
},
],
},
immutable: false,
data: {
'.dockerconfigjson':
'eyJhdXRocyI6eyJyZWdpc3RyeS50ZXN0LmNvbSI6eyJ1c2VybmFtZSI6InRlc3QtdXNlcm5hbWUiLCJwYXNzd29yZCI6InRlc3QtcGFzc3dvcmQiLCJhdXRoIjoidGVzdC1hdXRoIn19fQ==',
},
type: 'kubernetes.io/dockerconfigjson',
kind: 'Secret',
apiVersion: 'v1',
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { MetadataTable } from '../../../../components/MetadataTable';
import { useRows } from './hooks/useRows';
import { CodebaseMetadataTableProps } from './types';
Expand Down
2 changes: 2 additions & 0 deletions src/pages/edp-configuration/pages/edp-registry-list/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const PageView = () => {
isLoading,
} = useDynamicDataContext();

console.log(EDPConfigMap, pullAccountSecret, pushAccountSecret, tektonServiceAccount);

return (
<PageWithSubMenu list={menu}>
<PageWrapper containerMaxWidth={'xl'}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Grid } from '@material-ui/core';
import React from 'react';
import { LoadingWrapper } from '../../../../components/LoadingWrapper';
import { EDPComponentKubeObject } from '../../../../k8s/EDPComponent';
import { getDefaultNamespace } from '../../../../utils/getDefaultNamespace';
Expand Down
1 change: 1 addition & 0 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import RouteEDPCDPipelineDetailsPage from '../pages/edp-cdpipeline-details/page';
import { routeEDPCDPipelineDetails } from '../pages/edp-cdpipeline-details/route';
import RouteEDPCDPipelineListPage from '../pages/edp-cdpipeline-list/page';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

export const NoDataSvg = ({ className }: { className: string }) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 20" className={className}>
Expand Down
1,780 changes: 1,780 additions & 0 deletions src/widgets/ManageRegistry/__snapshots__/index.create.test.tsx.snap

Large diffs are not rendered by default.

2,247 changes: 2,247 additions & 0 deletions src/widgets/ManageRegistry/__snapshots__/index.edit.test.tsx.snap

Large diffs are not rendered by default.

2,260 changes: 2,260 additions & 0 deletions src/widgets/ManageRegistry/__snapshots__/index.read.test.tsx.snap

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/widgets/ManageRegistry/index.create.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @jest-environment jsdom
*/

import { render, screen } from '@testing-library/react';
import React from 'react';
import { TestWrapper } from '../../../mocks/wrappers/default';
import { CONTAINER_REGISTRY_PLATFORM } from '../../k8s/ConfigMap/constants';
import { createEmptyEdpConfigMapMock } from '../../k8s/ConfigMap/mocks/edp-config-map.mock';
import { ConfigMapKubeObjectInterface } from '../../k8s/ConfigMap/types';
import { ManageRegistry } from './index';

test('renders ManageRegistry Kubernetes Create component', () => {
render(
<TestWrapper>
<ManageRegistry
formData={{
EDPConfigMap: createEmptyEdpConfigMapMock(
CONTAINER_REGISTRY_PLATFORM.KUBERNETES
) as unknown as ConfigMapKubeObjectInterface,
pullAccountSecret: null,
pushAccountSecret: null,
tektonServiceAccount: null,
}}
/>
</TestWrapper>
);

const dialog = screen.getByTestId('form');
expect(dialog).toMatchSnapshot();
});
39 changes: 39 additions & 0 deletions src/widgets/ManageRegistry/index.edit.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @jest-environment jsdom
*/

import { render, screen } from '@testing-library/react';
import React from 'react';
import { TestWrapper } from '../../../mocks/wrappers/default';
import {
CONTAINER_REGISTRY_PLATFORM,
CONTAINER_REGISTRY_TYPE,
} from '../../k8s/ConfigMap/constants';
import { createEdpConfigMapMock } from '../../k8s/ConfigMap/mocks/edp-config-map.mock';
import { ConfigMapKubeObjectInterface } from '../../k8s/ConfigMap/types';
import { kanikoDockerSecretMock } from '../../k8s/Secret/mocks/kaniko-config-secret.mock';
import { regcredSecretMock } from '../../k8s/Secret/mocks/regcred-config-secret.mock';
import { SecretKubeObjectInterface } from '../../k8s/Secret/types';
import { ManageRegistry } from './index';

test('renders ManageRegistry Kubernetes Edit component', () => {
render(
<TestWrapper>
<ManageRegistry
formData={{
EDPConfigMap: createEdpConfigMapMock(
CONTAINER_REGISTRY_TYPE.HARBOR,
CONTAINER_REGISTRY_PLATFORM.KUBERNETES
) as unknown as ConfigMapKubeObjectInterface,
pullAccountSecret: regcredSecretMock as unknown as SecretKubeObjectInterface,
pushAccountSecret:
kanikoDockerSecretMock as unknown as SecretKubeObjectInterface,
tektonServiceAccount: null,
}}
/>
</TestWrapper>
);

const dialog = screen.getByTestId('form');
expect(dialog).toMatchSnapshot();
});
39 changes: 39 additions & 0 deletions src/widgets/ManageRegistry/index.read.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @jest-environment jsdom
*/
import { render, screen } from '@testing-library/react';
import React from 'react';
import { TestWrapper } from '../../../mocks/wrappers/default';
import {
CONTAINER_REGISTRY_PLATFORM,
CONTAINER_REGISTRY_TYPE,
} from '../../k8s/ConfigMap/constants';
import { createEdpConfigMapMock } from '../../k8s/ConfigMap/mocks/edp-config-map.mock';
import { ConfigMapKubeObjectInterface } from '../../k8s/ConfigMap/types';
import { kanikoDockerSecretWithOwnerMock } from '../../k8s/Secret/mocks/kaniko-config-secret.mock';
import { regcredSecretWithOwnerMock } from '../../k8s/Secret/mocks/regcred-config-secret.mock';
import { SecretKubeObjectInterface } from '../../k8s/Secret/types';
import { ManageRegistry } from './index';

test('renders ManageRegistry Kubernetes Edit (read-only) component', () => {
render(
<TestWrapper>
<ManageRegistry
formData={{
EDPConfigMap: createEdpConfigMapMock(
CONTAINER_REGISTRY_TYPE.HARBOR,
CONTAINER_REGISTRY_PLATFORM.KUBERNETES
) as unknown as ConfigMapKubeObjectInterface,
pullAccountSecret:
regcredSecretWithOwnerMock as unknown as SecretKubeObjectInterface,
pushAccountSecret:
kanikoDockerSecretWithOwnerMock as unknown as SecretKubeObjectInterface,
tektonServiceAccount: null,
}}
/>
</TestWrapper>
);

const dialog = screen.getByTestId('form');
expect(dialog).toMatchSnapshot();
});
2 changes: 0 additions & 2 deletions src/widgets/ManageRegistry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export const ManageRegistry = ({ formData }: ManageRegistryProps) => {

const _formData = React.useMemo(() => ({ ...formData, handleClosePanel }), [formData]);

console.log('render ManageRegistry', 'registryType', registryType);

return (
<Grid container spacing={2} data-testid="form">
<Grid item xs={12}>
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"baseUrl": "./src",
"types": ["node", "jest"]
"types": ["node", "jest"],
"jsx": "react"
},
"include": ["./src/**/*"],
"extends": "./node_modules/@kinvolk/headlamp-plugin/config/plugins-tsconfig.json",
Expand Down

0 comments on commit 4024cb8

Please sign in to comment.