mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03: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:
parent
882d2fdbe8
commit
c94dc08cf3
@ -59,13 +59,14 @@ function PlaybookSelect({
|
||||
onToggle={setIsOpen}
|
||||
placeholderText={t`Select a playbook`}
|
||||
typeAheadAriaLabel={t`Select a playbook`}
|
||||
isCreatable={false}
|
||||
isCreatable
|
||||
createText=""
|
||||
onSelect={(event, value) => {
|
||||
setIsOpen(false);
|
||||
onChange(value);
|
||||
}}
|
||||
id="template-playbook"
|
||||
isValid={isValid}
|
||||
validated={isValid ? 'default' : 'error'}
|
||||
onBlur={onBlur}
|
||||
isDisabled={isLoading || isDisabled}
|
||||
maxHeight="1000%"
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
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 { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||
import PlaybookSelect from './PlaybookSelect';
|
||||
|
||||
jest.mock('../../../api');
|
||||
jest.mock('api');
|
||||
|
||||
describe('<PlaybookSelect />', () => {
|
||||
beforeEach(() => {
|
||||
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 () => {
|
||||
let wrapper;
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<PlaybookSelect
|
||||
projectId={1}
|
||||
isValid
|
||||
onChange={() => {}}
|
||||
onError={() => {}}
|
||||
/>
|
||||
const { rerender } = render(
|
||||
<PlaybookSelect
|
||||
projectId={1}
|
||||
isValid
|
||||
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 act(async () => {
|
||||
wrapper.setProps({ projectId: 15 });
|
||||
});
|
||||
await waitFor(() => {
|
||||
// A new select option is displayed ("foo.yml")
|
||||
expect(
|
||||
screen.getByText('"foo.yml"', { selector: '[role="option"]' })
|
||||
).toBeVisible();
|
||||
expect(screen.getAllByRole('option').length).toBe(1);
|
||||
|
||||
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledTimes(2);
|
||||
expect(ProjectsAPI.readPlaybooks).toHaveBeenCalledWith(15);
|
||||
fireEvent.click(
|
||||
screen.getByText('"foo.yml"', { selector: '[role="option"]' })
|
||||
);
|
||||
|
||||
expect(mockCallback).toHaveBeenCalledWith('foo.yml');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user