Skip to content

Commit

Permalink
Merge pull request #13506 from AlexSCorey/13422-JTTabOnCreds
Browse files Browse the repository at this point in the history
Conditionally applies the job templates tab to credentials that can be on a JT
  • Loading branch information
AlexSCorey committed Mar 2, 2023
2 parents a47cfc5 + 2fe1ea9 commit 1411d11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
30 changes: 20 additions & 10 deletions awx/ui/src/screens/Credential/Credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions awx/ui/src/screens/Credential/Credential.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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({
Expand Down Expand Up @@ -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'],
Expand All @@ -85,3 +104,4 @@ describe('<Credential />', () => {
await waitForElement(wrapper, 'ContentError', (el) => el.length === 1);
});
});
describe('<Credential> should not show job template tab', () => {});

0 comments on commit 1411d11

Please sign in to comment.