Skip to content

Commit

Permalink
Merge pull request ansible#9639 from nixocio/ui_issue_9628
Browse files Browse the repository at this point in the history
Filter credential type by Container Registry for EE

Filter credential type by Container Registry for EE form.
See: ansible#9628

Reviewed-by: Jake McDermott <yo@jakemcdermott.me>
Reviewed-by: Kersom <None>
Reviewed-by: Tiago Góes <tiago.goes2009@gmail.com>
  • Loading branch information
softwarefactory-project-zuul[bot] authored Mar 23, 2021
2 parents e042abb + 87d51c1 commit 646c9cc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { ExecutionEnvironmentsAPI } from '../../../api';
import { ExecutionEnvironmentsAPI, CredentialTypesAPI } from '../../../api';
import ExecutionEnvironmentAdd from './ExecutionEnvironmentAdd';

jest.mock('../../../api');
Expand All @@ -22,6 +22,17 @@ const executionEnvironmentData = {
description: 'A simple EE',
image: 'https://registry.com/image/container',
pull: 'one',
summary_fields: {
credential: {
id: 4,
name: 'Container Registry',
description: '',
kind: 'registry',
cloud: false,
kubernetes: false,
credential_type_id: 17,
},
},
};

const mockOptions = {
Expand All @@ -40,18 +51,32 @@ const mockOptions = {
},
};

ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
ExecutionEnvironmentsAPI.create.mockResolvedValue({
const containerRegistryCredentialResolve = {
data: {
id: 42,
results: [
{
id: 4,
name: 'Container Registry',
kind: 'registry',
},
],
},
});
};

describe('<ExecutionEnvironmentAdd/>', () => {
let wrapper;
let history;

beforeEach(async () => {
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
ExecutionEnvironmentsAPI.create.mockResolvedValue({
data: {
id: 42,
},
});
CredentialTypesAPI.read.mockResolvedValue(
containerRegistryCredentialResolve
);
history = createMemoryHistory({
initialEntries: ['/execution_environments'],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { act } from 'react-dom/test-utils';
import { createMemoryHistory } from 'history';

import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import { ExecutionEnvironmentsAPI } from '../../../api';
import { ExecutionEnvironmentsAPI, CredentialTypesAPI } from '../../../api';

import ExecutionEnvironmentEdit from './ExecutionEnvironmentEdit';

Expand Down Expand Up @@ -44,13 +44,27 @@ const mockOptions = {
},
};

ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
const containerRegistryCredentialResolve = {
data: {
results: [
{
id: 4,
name: 'Container Registry',
kind: 'registry',
},
],
},
};

describe('<ExecutionEnvironmentEdit/>', () => {
let wrapper;
let history;

beforeAll(async () => {
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
CredentialTypesAPI.read.mockResolvedValue(
containerRegistryCredentialResolve
);
history = createMemoryHistory();
await act(async () => {
wrapper = mountWithContexts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function ExecutionEnvironmentFormFields({
options,
executionEnvironment,
}) {
const [credentialField] = useField('credential');
const [credentialField, credentialMeta, credentialHelpers] = useField(
'credential'
);
const [organizationField, organizationMeta, organizationHelpers] = useField({
name: 'organization',
validate:
Expand Down Expand Up @@ -124,8 +126,15 @@ function ExecutionEnvironmentFormFields({

<CredentialLookup
label={i18n._(t`Registry credential`)}
credentialTypeKind="registry"
helperTextInvalid={credentialMeta.error}
isValid={!credentialMeta.touched || !credentialMeta.error}
onBlur={() => credentialHelpers.setTouched()}
onChange={onCredentialChange}
value={credentialField.value}
tooltip={i18n._(
t`Credential to authenticate with a protected container registry.`
)}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { ExecutionEnvironmentsAPI } from '../../../api';
import { ExecutionEnvironmentsAPI, CredentialTypesAPI } from '../../../api';

import ExecutionEnvironmentForm from './ExecutionEnvironmentForm';

Expand Down Expand Up @@ -33,6 +33,11 @@ const executionEnvironment = {
credential: {
id: 4,
name: 'Container Registry',
description: '',
kind: 'registry',
cloud: false,
kubernetes: false,
credential_type_id: 17,
},
},
created: '2020-09-17T16:06:57.346128Z',
Expand Down Expand Up @@ -60,6 +65,18 @@ const mockOptions = {
},
};

const containerRegistryCredentialResolve = {
data: {
results: [
{
id: 4,
name: 'Container Registry',
kind: 'registry',
},
],
},
};

describe('<ExecutionEnvironmentForm/>', () => {
let wrapper;
let onCancel;
Expand All @@ -69,6 +86,9 @@ describe('<ExecutionEnvironmentForm/>', () => {
onCancel = jest.fn();
onSubmit = jest.fn();
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(mockOptions);
CredentialTypesAPI.read.mockResolvedValue(
containerRegistryCredentialResolve
);
await act(async () => {
wrapper = mountWithContexts(
<ExecutionEnvironmentForm
Expand Down

0 comments on commit 646c9cc

Please sign in to comment.