Skip to content

Commit

Permalink
test: add coverage to missing lines
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoPedroPP committed Nov 1, 2024
1 parent 8a066aa commit 86dcc71
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import '@testing-library/jest-dom';
import { useK8sWatchResource } from '@openshift/dynamic-plugin-sdk-utils';
import { screen, fireEvent, act, waitFor } from '@testing-library/react';
import { useSecrets } from '../../../../hooks/useSecrets';
import { useAccessReviewForModels } from '../../../../utils/rbac';
import { formikRenderer } from '../../../../utils/test-utils';
import SecretSection from '../SecretSection';
Expand All @@ -15,13 +16,35 @@ jest.mock('../../../../utils/rbac', () => ({
useAccessReviewForModels: jest.fn(),
}));

jest.mock('../../../../hooks/useSecrets', () => ({
useSecrets: jest.fn(),
}));

const watchResourceMock = useK8sWatchResource as jest.Mock;
const accessReviewMock = useAccessReviewForModels as jest.Mock;
const useSecretsMock = useSecrets as jest.Mock;

describe('SecretSection', () => {
beforeEach(() => {
watchResourceMock.mockReturnValue([[], true]);
accessReviewMock.mockReturnValue([true, true]);
useSecretsMock.mockReturnValue([
[
{
metadata: {
name: 'snyk-secret',
namespace: 'test-ws',
},
data: {
'snyk-token': 'c255ay1zZWNyZXQ=',
},
type: 'Opaque',
apiVersion: 'v1',
kind: 'Secret',
},
],
true,
]);
});

it('should render secret section', () => {
Expand Down
18 changes: 17 additions & 1 deletion src/components/Secrets/__tests___/secret-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { k8sCreateResource } from '@openshift/dynamic-plugin-sdk-utils';
import { k8sCreateResource, k8sGetResource } from '@openshift/dynamic-plugin-sdk-utils';
import {
AddSecretFormValues,
ImagePullSecretType,
Expand Down Expand Up @@ -27,12 +27,14 @@ import {
typeToLabel,
getSecretRowLabels,
getSecretTypetoLabel,
getSecretResource,
} from '../utils/secret-utils';
import { sampleImagePullSecret, sampleOpaqueSecret, sampleRemoteSecrets } from './secret-data';

jest.mock('@openshift/dynamic-plugin-sdk-utils');

const createResourceMock = k8sCreateResource as jest.Mock;
const getSecretResourceMock = k8sGetResource as jest.Mock;

describe('getSupportedPartnerTaskKeyValuePairs', () => {
it('should return empty array ', () => {
Expand Down Expand Up @@ -67,6 +69,20 @@ describe('getSupportedPartnerTaskSecrets', () => {
});
});

describe('getSecretResource', () => {
it('should retrive secrets from a namespace', () => {
getSecretResource('test-ns');

expect(getSecretResourceMock).toHaveBeenCalledWith(
expect.objectContaining({
queryOptions: expect.objectContaining({
ns: 'test-ns',
}),
}),
);
});
});

describe('createSecretResource', () => {
it('should create Opaque secret resource', () => {
createSecretResource(sampleOpaqueSecret, 'test-ns', false);
Expand Down

0 comments on commit 86dcc71

Please sign in to comment.