mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 19:07:36 -02:30
Merge pull request #9639 from nixocio/ui_issue_9628
Filter credential type by Container Registry for EE Filter credential type by Container Registry for EE form. See: #9628 Reviewed-by: Jake McDermott <yo@jakemcdermott.me> Reviewed-by: Kersom <None> Reviewed-by: Tiago Góes <tiago.goes2009@gmail.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
|||||||
mountWithContexts,
|
mountWithContexts,
|
||||||
waitForElement,
|
waitForElement,
|
||||||
} from '../../../../testUtils/enzymeHelpers';
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
import { ExecutionEnvironmentsAPI } from '../../../api';
|
import { ExecutionEnvironmentsAPI, CredentialTypesAPI } from '../../../api';
|
||||||
import ExecutionEnvironmentAdd from './ExecutionEnvironmentAdd';
|
import ExecutionEnvironmentAdd from './ExecutionEnvironmentAdd';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
@@ -22,6 +22,17 @@ const executionEnvironmentData = {
|
|||||||
description: 'A simple EE',
|
description: 'A simple EE',
|
||||||
image: 'https://registry.com/image/container',
|
image: 'https://registry.com/image/container',
|
||||||
pull: 'one',
|
pull: 'one',
|
||||||
|
summary_fields: {
|
||||||
|
credential: {
|
||||||
|
id: 4,
|
||||||
|
name: 'Container Registry',
|
||||||
|
description: '',
|
||||||
|
kind: 'registry',
|
||||||
|
cloud: false,
|
||||||
|
kubernetes: false,
|
||||||
|
credential_type_id: 17,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockOptions = {
|
const mockOptions = {
|
||||||
@@ -40,18 +51,32 @@ const mockOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
|
const containerRegistryCredentialResolve = {
|
||||||
ExecutionEnvironmentsAPI.create.mockResolvedValue({
|
|
||||||
data: {
|
data: {
|
||||||
id: 42,
|
results: [
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
name: 'Container Registry',
|
||||||
|
kind: 'registry',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
describe('<ExecutionEnvironmentAdd/>', () => {
|
describe('<ExecutionEnvironmentAdd/>', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let history;
|
let history;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
|
||||||
|
ExecutionEnvironmentsAPI.create.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
id: 42,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
CredentialTypesAPI.read.mockResolvedValue(
|
||||||
|
containerRegistryCredentialResolve
|
||||||
|
);
|
||||||
history = createMemoryHistory({
|
history = createMemoryHistory({
|
||||||
initialEntries: ['/execution_environments'],
|
initialEntries: ['/execution_environments'],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { act } from 'react-dom/test-utils';
|
|||||||
import { createMemoryHistory } from 'history';
|
import { createMemoryHistory } from 'history';
|
||||||
|
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
import { ExecutionEnvironmentsAPI } from '../../../api';
|
import { ExecutionEnvironmentsAPI, CredentialTypesAPI } from '../../../api';
|
||||||
|
|
||||||
import ExecutionEnvironmentEdit from './ExecutionEnvironmentEdit';
|
import ExecutionEnvironmentEdit from './ExecutionEnvironmentEdit';
|
||||||
|
|
||||||
@@ -44,13 +44,27 @@ const mockOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
|
const containerRegistryCredentialResolve = {
|
||||||
|
data: {
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
name: 'Container Registry',
|
||||||
|
kind: 'registry',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
describe('<ExecutionEnvironmentEdit/>', () => {
|
describe('<ExecutionEnvironmentEdit/>', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let history;
|
let history;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
|
||||||
|
CredentialTypesAPI.read.mockResolvedValue(
|
||||||
|
containerRegistryCredentialResolve
|
||||||
|
);
|
||||||
history = createMemoryHistory();
|
history = createMemoryHistory();
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ function ExecutionEnvironmentFormFields({
|
|||||||
options,
|
options,
|
||||||
executionEnvironment,
|
executionEnvironment,
|
||||||
}) {
|
}) {
|
||||||
const [credentialField] = useField('credential');
|
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
||||||
|
'credential'
|
||||||
|
);
|
||||||
const [organizationField, organizationMeta, organizationHelpers] = useField({
|
const [organizationField, organizationMeta, organizationHelpers] = useField({
|
||||||
name: 'organization',
|
name: 'organization',
|
||||||
validate:
|
validate:
|
||||||
@@ -124,8 +126,15 @@ function ExecutionEnvironmentFormFields({
|
|||||||
|
|
||||||
<CredentialLookup
|
<CredentialLookup
|
||||||
label={i18n._(t`Registry credential`)}
|
label={i18n._(t`Registry credential`)}
|
||||||
|
credentialTypeKind="registry"
|
||||||
|
helperTextInvalid={credentialMeta.error}
|
||||||
|
isValid={!credentialMeta.touched || !credentialMeta.error}
|
||||||
|
onBlur={() => credentialHelpers.setTouched()}
|
||||||
onChange={onCredentialChange}
|
onChange={onCredentialChange}
|
||||||
value={credentialField.value}
|
value={credentialField.value}
|
||||||
|
tooltip={i18n._(
|
||||||
|
t`Credential to authenticate with a protected container registry.`
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
mountWithContexts,
|
mountWithContexts,
|
||||||
waitForElement,
|
waitForElement,
|
||||||
} from '../../../../testUtils/enzymeHelpers';
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
import { ExecutionEnvironmentsAPI } from '../../../api';
|
import { ExecutionEnvironmentsAPI, CredentialTypesAPI } from '../../../api';
|
||||||
|
|
||||||
import ExecutionEnvironmentForm from './ExecutionEnvironmentForm';
|
import ExecutionEnvironmentForm from './ExecutionEnvironmentForm';
|
||||||
|
|
||||||
@@ -33,6 +33,11 @@ const executionEnvironment = {
|
|||||||
credential: {
|
credential: {
|
||||||
id: 4,
|
id: 4,
|
||||||
name: 'Container Registry',
|
name: 'Container Registry',
|
||||||
|
description: '',
|
||||||
|
kind: 'registry',
|
||||||
|
cloud: false,
|
||||||
|
kubernetes: false,
|
||||||
|
credential_type_id: 17,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created: '2020-09-17T16:06:57.346128Z',
|
created: '2020-09-17T16:06:57.346128Z',
|
||||||
@@ -60,6 +65,18 @@ const mockOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const containerRegistryCredentialResolve = {
|
||||||
|
data: {
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
name: 'Container Registry',
|
||||||
|
kind: 'registry',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
describe('<ExecutionEnvironmentForm/>', () => {
|
describe('<ExecutionEnvironmentForm/>', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let onCancel;
|
let onCancel;
|
||||||
@@ -69,6 +86,9 @@ describe('<ExecutionEnvironmentForm/>', () => {
|
|||||||
onCancel = jest.fn();
|
onCancel = jest.fn();
|
||||||
onSubmit = jest.fn();
|
onSubmit = jest.fn();
|
||||||
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
|
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
|
||||||
|
CredentialTypesAPI.read.mockResolvedValue(
|
||||||
|
containerRegistryCredentialResolve
|
||||||
|
);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<ExecutionEnvironmentForm
|
<ExecutionEnvironmentForm
|
||||||
|
|||||||
Reference in New Issue
Block a user