Fixes 'Not Found' error on looking up credentials

remove redundant console logs

typo

Signed-off-by: Vidya Nambiar <vnambiar@redhat.com>
This commit is contained in:
Vidya Nambiar 2022-12-07 13:40:00 -05:00
parent adbcb5c5e4
commit ed74d80ecb
5 changed files with 93 additions and 1 deletions

View File

@ -74,7 +74,7 @@
"prestart-instrumented": "lingui compile",
"pretest": "lingui compile",
"pretest-watch": "lingui compile",
"start": "GENERATE_SOURCEMAP=false ESLINT_NO_DEV_ERRORS=true PORT=3001 HTTPS=true DANGEROUSLY_DISABLE_HOST_CHECK=true react-scripts start",
"start": "GENERATE_SOURCEMAP=false ESLINT_NO_DEV_ERRORS=true PORT=3003 HTTPS=true DANGEROUSLY_DISABLE_HOST_CHECK=true react-scripts start",
"start-instrumented": "ESLINT_NO_DEV_ERRORS=true DEBUG=instrument-cra PORT=3001 HTTPS=true DANGEROUSLY_DISABLE_HOST_CHECK=true react-scripts -r @cypress/instrument-cra start",
"build": "INLINE_RUNTIME_CHUNK=false react-scripts build",
"test": "TZ='UTC' react-scripts test --watchAll=false",

View File

@ -153,6 +153,10 @@ function CredentialsStep({
}))}
value={selectedType && selectedType.id}
onChange={(e, id) => {
// Reset query params when the category of credentials is changed
history.replace({
search: '',
});
setSelectedType(types.find((o) => o.id === parseInt(id, 10)));
}}
/>

View File

@ -4,6 +4,7 @@ import { Formik } from 'formik';
import { CredentialsAPI, CredentialTypesAPI } from 'api';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import CredentialsStep from './CredentialsStep';
import { createMemoryHistory } from 'history';
jest.mock('../../../api/models/CredentialTypes');
jest.mock('../../../api/models/Credentials');
@ -164,6 +165,41 @@ describe('CredentialsStep', () => {
});
});
test('should reset query params (credential.page) when selected credential type is changed', async () => {
let wrapper;
const history = createMemoryHistory({
initialEntries: ['?credential.page=2'],
});
await act(async () => {
wrapper = mountWithContexts(
<Formik>
<CredentialsStep allowCredentialsWithPasswords />
</Formik>,
{
context: { router: { history } },
}
);
});
wrapper.update();
expect(CredentialsAPI.read).toHaveBeenCalledWith({
credential_type: 1,
order_by: 'name',
page: 2,
page_size: 5,
});
await act(async () => {
wrapper.find('AnsibleSelect').invoke('onChange')({}, 3);
});
expect(CredentialsAPI.read).toHaveBeenCalledWith({
credential_type: 3,
order_by: 'name',
page: 1,
page_size: 5,
});
});
test("error should be shown when a credential that prompts for passwords is selected on a step that doesn't allow it", async () => {
let wrapper;
await act(async () => {

View File

@ -173,6 +173,10 @@ function MultiCredentialsLookup({
}))}
value={selectedType && selectedType.id}
onChange={(e, id) => {
// Reset query params when the category of credentials is changed
history.replace({
search: '',
});
setSelectedType(
credentialTypes.find((o) => o.id === parseInt(id, 10))
);

View File

@ -7,6 +7,7 @@ import {
waitForElement,
} from '../../../testUtils/enzymeHelpers';
import MultiCredentialsLookup from './MultiCredentialsLookup';
import { createMemoryHistory } from 'history';
jest.mock('../../api');
@ -228,6 +229,53 @@ describe('<Formik><MultiCredentialsLookup /></Formik>', () => {
]);
});
test('should reset query params (credentials.page) when selected credential type is changed', async () => {
const history = createMemoryHistory({
initialEntries: ['?credentials.page=2'],
});
await act(async () => {
wrapper = mountWithContexts(
<Formik>
<MultiCredentialsLookup
value={credentials}
tooltip="This is credentials look up"
onChange={() => {}}
onError={() => {}}
/>
</Formik>,
{
context: { router: { history } },
}
);
});
const searchButton = await waitForElement(
wrapper,
'Button[aria-label="Search"]'
);
await act(async () => {
searchButton.invoke('onClick')();
});
expect(CredentialsAPI.read).toHaveBeenCalledWith({
credential_type: 400,
order_by: 'name',
page: 2,
page_size: 5,
});
const select = await waitForElement(wrapper, 'AnsibleSelect');
await act(async () => {
select.invoke('onChange')({}, 500);
});
wrapper.update();
expect(CredentialsAPI.read).toHaveBeenCalledWith({
credential_type: 500,
order_by: 'name',
page: 1,
page_size: 5,
});
});
test('should only add 1 credential per credential type except vault(see below)', async () => {
const onChange = jest.fn();
await act(async () => {