mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
Conditionally applies the job templates tab to credentials that can be on a JT
This commit is contained in:
parent
a47cfc55ab
commit
2fe1ea94bd
@ -22,14 +22,19 @@ import { CredentialsAPI } from 'api';
|
||||
import CredentialDetail from './CredentialDetail';
|
||||
import CredentialEdit from './CredentialEdit';
|
||||
|
||||
const jobTemplateCredentialTypes = [
|
||||
'machine',
|
||||
'cloud',
|
||||
'net',
|
||||
'ssh',
|
||||
'vault',
|
||||
'kubernetes',
|
||||
'cryptography',
|
||||
const unacceptableCredentialTypes = [
|
||||
'centrify_vault_kv',
|
||||
'aim',
|
||||
'conjur',
|
||||
'hashivault_kv',
|
||||
'hashivault_ssh',
|
||||
'azure_kv',
|
||||
'thycotic_dsv',
|
||||
'thycotic_tss',
|
||||
'galaxy_api_token',
|
||||
'insights',
|
||||
'registry',
|
||||
'scm',
|
||||
];
|
||||
|
||||
function Credential({ setBreadcrumb }) {
|
||||
@ -86,7 +91,10 @@ function Credential({ setBreadcrumb }) {
|
||||
id: 1,
|
||||
},
|
||||
];
|
||||
if (jobTemplateCredentialTypes.includes(credential?.kind)) {
|
||||
if (
|
||||
!unacceptableCredentialTypes.includes(credential?.kind) &&
|
||||
credential !== null
|
||||
) {
|
||||
tabsArray.push({
|
||||
name: t`Job Templates`,
|
||||
link: `/credentials/${id}/job_templates`,
|
||||
@ -115,12 +123,14 @@ function Credential({ setBreadcrumb }) {
|
||||
</PageSection>
|
||||
);
|
||||
}
|
||||
if (hasContentLoading) {
|
||||
return <ContentLoading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<PageSection>
|
||||
<Card>
|
||||
{showCardHeader && <RoutedTabs tabsArray={tabsArray} />}
|
||||
{hasContentLoading && <ContentLoading />}
|
||||
{!hasContentLoading && credential && (
|
||||
<Switch>
|
||||
<Redirect
|
||||
|
||||
@ -8,6 +8,7 @@ import {
|
||||
} from '../../../testUtils/enzymeHelpers';
|
||||
import mockMachineCredential from './shared/data.machineCredential.json';
|
||||
import mockSCMCredential from './shared/data.scmCredential.json';
|
||||
import mockCyberArkCredential from './shared/data.cyberArkCredential.json';
|
||||
import Credential from './Credential';
|
||||
|
||||
jest.mock('../../api');
|
||||
@ -21,6 +22,11 @@ jest.mock('react-router-dom', () => ({
|
||||
|
||||
describe('<Credential />', () => {
|
||||
let wrapper;
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('initially renders user-based machine credential successfully', async () => {
|
||||
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 () => {
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/credentials/2/foobar'],
|
||||
@ -85,3 +104,4 @@ describe('<Credential />', () => {
|
||||
await waitForElement(wrapper, 'ContentError', (el) => el.length === 1);
|
||||
});
|
||||
});
|
||||
describe('<Credential> should not show job template tab', () => {});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user