Conditionally applies the job templates tab to credentials that can be on a JT

This commit is contained in:
Alex Corey
2023-02-01 16:00:28 -05:00
parent a47cfc55ab
commit 2fe1ea94bd
2 changed files with 40 additions and 10 deletions

View File

@@ -22,14 +22,19 @@ import { CredentialsAPI } from 'api';
import CredentialDetail from './CredentialDetail'; import CredentialDetail from './CredentialDetail';
import CredentialEdit from './CredentialEdit'; import CredentialEdit from './CredentialEdit';
const jobTemplateCredentialTypes = [ const unacceptableCredentialTypes = [
'machine', 'centrify_vault_kv',
'cloud', 'aim',
'net', 'conjur',
'ssh', 'hashivault_kv',
'vault', 'hashivault_ssh',
'kubernetes', 'azure_kv',
'cryptography', 'thycotic_dsv',
'thycotic_tss',
'galaxy_api_token',
'insights',
'registry',
'scm',
]; ];
function Credential({ setBreadcrumb }) { function Credential({ setBreadcrumb }) {
@@ -86,7 +91,10 @@ function Credential({ setBreadcrumb }) {
id: 1, id: 1,
}, },
]; ];
if (jobTemplateCredentialTypes.includes(credential?.kind)) { if (
!unacceptableCredentialTypes.includes(credential?.kind) &&
credential !== null
) {
tabsArray.push({ tabsArray.push({
name: t`Job Templates`, name: t`Job Templates`,
link: `/credentials/${id}/job_templates`, link: `/credentials/${id}/job_templates`,
@@ -115,12 +123,14 @@ function Credential({ setBreadcrumb }) {
</PageSection> </PageSection>
); );
} }
if (hasContentLoading) {
return <ContentLoading />;
}
return ( return (
<PageSection> <PageSection>
<Card> <Card>
{showCardHeader && <RoutedTabs tabsArray={tabsArray} />} {showCardHeader && <RoutedTabs tabsArray={tabsArray} />}
{hasContentLoading && <ContentLoading />}
{!hasContentLoading && credential && ( {!hasContentLoading && credential && (
<Switch> <Switch>
<Redirect <Redirect

View File

@@ -8,6 +8,7 @@ import {
} from '../../../testUtils/enzymeHelpers'; } from '../../../testUtils/enzymeHelpers';
import mockMachineCredential from './shared/data.machineCredential.json'; import mockMachineCredential from './shared/data.machineCredential.json';
import mockSCMCredential from './shared/data.scmCredential.json'; import mockSCMCredential from './shared/data.scmCredential.json';
import mockCyberArkCredential from './shared/data.cyberArkCredential.json';
import Credential from './Credential'; import Credential from './Credential';
jest.mock('../../api'); jest.mock('../../api');
@@ -21,6 +22,11 @@ jest.mock('react-router-dom', () => ({
describe('<Credential />', () => { describe('<Credential />', () => {
let wrapper; let wrapper;
afterEach(() => {
jest.clearAllMocks();
wrapper.unmount();
});
test('initially renders user-based machine credential successfully', async () => { test('initially renders user-based machine credential successfully', async () => {
CredentialsAPI.readDetail.mockResolvedValueOnce({ CredentialsAPI.readDetail.mockResolvedValueOnce({
@@ -61,6 +67,19 @@ describe('<Credential />', () => {
}); });
}); });
test('should not render job template tab', async () => {
CredentialsAPI.readDetail.mockResolvedValueOnce({
data: { ...mockCyberArkCredential, kind: 'registry' },
});
const expectedTabs = ['Back to Credentials', 'Details', 'Access'];
await act(async () => {
wrapper = mountWithContexts(<Credential setBreadcrumb={() => {}} />);
});
wrapper.find('RoutedTabs li').forEach((tab, index) => {
expect(tab.text()).toEqual(expectedTabs[index]);
});
});
test('should show content error when user attempts to navigate to erroneous route', async () => { test('should show content error when user attempts to navigate to erroneous route', async () => {
const history = createMemoryHistory({ const history = createMemoryHistory({
initialEntries: ['/credentials/2/foobar'], initialEntries: ['/credentials/2/foobar'],
@@ -85,3 +104,4 @@ describe('<Credential />', () => {
await waitForElement(wrapper, 'ContentError', (el) => el.length === 1); await waitForElement(wrapper, 'ContentError', (el) => el.length === 1);
}); });
}); });
describe('<Credential> should not show job template tab', () => {});