mirror of
https://github.com/ansible/awx.git
synced 2026-04-13 22:19:27 -02:30
Allow entering playbook filename manually in Job Template
Signed-off-by: Vidya Nambiar <vnambiar@redhat.com> Prettier Signed-off-by: Vidya Nambiar <vnambiar@redhat.com>
This commit is contained in:
@@ -59,13 +59,14 @@ function PlaybookSelect({
|
|||||||
onToggle={setIsOpen}
|
onToggle={setIsOpen}
|
||||||
placeholderText={t`Select a playbook`}
|
placeholderText={t`Select a playbook`}
|
||||||
typeAheadAriaLabel={t`Select a playbook`}
|
typeAheadAriaLabel={t`Select a playbook`}
|
||||||
isCreatable={false}
|
isCreatable
|
||||||
|
createText=""
|
||||||
onSelect={(event, value) => {
|
onSelect={(event, value) => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
onChange(value);
|
onChange(value);
|
||||||
}}
|
}}
|
||||||
id="template-playbook"
|
id="template-playbook"
|
||||||
isValid={isValid}
|
validated={isValid ? 'default' : 'error'}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
isDisabled={isLoading || isDisabled}
|
isDisabled={isLoading || isDisabled}
|
||||||
maxHeight="1000%"
|
maxHeight="1000%"
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
import { ProjectsAPI } from 'api';
|
import { ProjectsAPI } from 'api';
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
|
||||||
import PlaybookSelect from './PlaybookSelect';
|
import PlaybookSelect from './PlaybookSelect';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('api');
|
||||||
|
|
||||||
describe('<PlaybookSelect />', () => {
|
describe('<PlaybookSelect />', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ProjectsAPI.readPlaybooks.mockReturnValue({
|
ProjectsAPI.readPlaybooks.mockReturnValue({
|
||||||
data: ['debug.yml'],
|
data: ['debug.yml', 'test.yml'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -18,24 +18,90 @@ describe('<PlaybookSelect />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should reload playbooks when project value changes', async () => {
|
test('should reload playbooks when project value changes', async () => {
|
||||||
let wrapper;
|
const { rerender } = render(
|
||||||
await act(async () => {
|
<PlaybookSelect
|
||||||
wrapper = mountWithContexts(
|
projectId={1}
|
||||||
<PlaybookSelect
|
isValid
|
||||||
projectId={1}
|
onChange={() => {}}
|
||||||
isValid
|
onError={() => {}}
|
||||||
onChange={() => {}}
|
/>
|
||||||
onError={() => {}}
|
);
|
||||||
/>
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledWith(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
rerender(
|
||||||
|
<PlaybookSelect
|
||||||
|
projectId={15}
|
||||||
|
isValid
|
||||||
|
onChange={() => {}}
|
||||||
|
onError={() => {}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledTimes(2);
|
||||||
|
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledWith(15);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should trigger the onChange callback for the option selected from the list', async () => {
|
||||||
|
const mockCallback = jest.fn();
|
||||||
|
|
||||||
|
const { container } = render(
|
||||||
|
<PlaybookSelect
|
||||||
|
projectId={1}
|
||||||
|
isValid={true}
|
||||||
|
onChange={mockCallback}
|
||||||
|
onError={() => {}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
const selectToggleButton = container.querySelector(
|
||||||
|
'button.pf-c-select__toggle-button'
|
||||||
);
|
);
|
||||||
|
fireEvent.click(selectToggleButton);
|
||||||
|
// Select options are displayed
|
||||||
|
expect(screen.getAllByRole('option').length).toBe(2);
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByText('debug.yml'));
|
||||||
|
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith('debug.yml');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow entering playbook file name manually', async () => {
|
||||||
|
const mockCallback = jest.fn();
|
||||||
|
|
||||||
|
const { container } = render(
|
||||||
|
<PlaybookSelect
|
||||||
|
projectId={1}
|
||||||
|
isValid={true}
|
||||||
|
onChange={mockCallback}
|
||||||
|
onError={() => {}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
const input = container.querySelector('input.pf-c-form-control');
|
||||||
|
expect(input).toBeVisible();
|
||||||
|
fireEvent.change(input, { target: { value: 'foo.yml' } });
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledWith(1);
|
await waitFor(() => {
|
||||||
await act(async () => {
|
// A new select option is displayed ("foo.yml")
|
||||||
wrapper.setProps({ projectId: 15 });
|
expect(
|
||||||
});
|
screen.getByText('"foo.yml"', { selector: '[role="option"]' })
|
||||||
|
).toBeVisible();
|
||||||
|
expect(screen.getAllByRole('option').length).toBe(1);
|
||||||
|
|
||||||
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledTimes(2);
|
fireEvent.click(
|
||||||
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledWith(15);
|
screen.getByText('"foo.yml"', { selector: '[role="option"]' })
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith('foo.yml');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user