mirror of
https://github.com/ansible/awx.git
synced 2026-02-25 15:06:02 -03:30
fix pagination page input and componentDidUpdate tests
This commit is contained in:
@@ -206,34 +206,73 @@ describe('<Pagination />', () => {
|
|||||||
expect(itemCount.text()).toEqual('Items 1 – 3 of 3');
|
expect(itemCount.text()).toEqual('Items 1 – 3 of 3');
|
||||||
});
|
});
|
||||||
|
|
||||||
// test('submit a new page by typing in input works', () => {
|
test('submitting a new page by typing in input works', () => {
|
||||||
// const textInputSelector = '.awx-pagination__page-input.pf-c-form-control';
|
const textInputSelector = '.awx-pagination__page-input.pf-c-form-control';
|
||||||
// const submitFormSelector = '.awx-pagination__page-input-form';
|
const submitFormSelector = '.awx-pagination__page-input-form';
|
||||||
// const onSetPage = jest.fn();
|
const onSetPage = jest.fn();
|
||||||
|
|
||||||
// pagination = mount(
|
pagination = mount(
|
||||||
// <I18nProvider>
|
<I18nProvider>
|
||||||
// <Pagination
|
<Pagination
|
||||||
// count={21}
|
count={21}
|
||||||
// page={1}
|
page={1}
|
||||||
// pageCount={5}
|
pageCount={5}
|
||||||
// page_size={5}
|
page_size={5}
|
||||||
// pageSizeOptions={[5, 10, 25, 50]}
|
pageSizeOptions={[5, 10, 25, 50]}
|
||||||
// onSetPage={onSetPage}
|
onSetPage={onSetPage}
|
||||||
// />
|
/>
|
||||||
// </I18nProvider>
|
</I18nProvider>
|
||||||
// );
|
);
|
||||||
// pagination.instance().onPageChange = jest.fn();
|
const paginationElem = pagination.find('Pagination');
|
||||||
|
expect(paginationElem.state().value).toBe(1);
|
||||||
|
const textInput = pagination.find(textInputSelector);
|
||||||
|
expect(textInput.length).toBe(1);
|
||||||
|
expect(textInput.at(0).prop('value')).toBe(1);
|
||||||
|
const input = pagination.find('TextInput');
|
||||||
|
expect(input.prop('value')).toBe(1);
|
||||||
|
input.prop('onChange')(2);
|
||||||
|
pagination.update();
|
||||||
|
const submitForm = pagination.find(submitFormSelector);
|
||||||
|
expect(submitForm.length).toBe(1);
|
||||||
|
submitForm.simulate('submit');
|
||||||
|
expect(pagination.find('TextInput').prop('value')).toBe(2);
|
||||||
|
// assert onPageChange was called
|
||||||
|
expect(paginationElem.state().value).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
// const textInput = pagination.find(textInputSelector);
|
test('submitting a new page by typing in input does not work when invalid', () => {
|
||||||
// expect(textInput.length).toBe(1);
|
const textInputSelector = '.awx-pagination__page-input.pf-c-form-control';
|
||||||
// textInput.simulate('change', { target: { value: '2' } });
|
const submitFormSelector = '.awx-pagination__page-input-form';
|
||||||
|
const onSetPage = jest.fn();
|
||||||
|
|
||||||
// const submitForm = pagination.find(submitFormSelector);
|
pagination = mount(
|
||||||
// expect(submitForm.length).toBe(1);
|
<I18nProvider>
|
||||||
// submitForm.simulate('submit');
|
<Pagination
|
||||||
// expect(pagination.instance().onPageChange).toBeCalledWith(2)
|
count={21}
|
||||||
// });
|
page={1}
|
||||||
|
pageCount={5}
|
||||||
|
page_size={5}
|
||||||
|
pageSizeOptions={[5, 10, 25, 50]}
|
||||||
|
onSetPage={onSetPage}
|
||||||
|
/>
|
||||||
|
</I18nProvider>
|
||||||
|
);
|
||||||
|
const paginationElem = pagination.find('Pagination');
|
||||||
|
expect(paginationElem.state().value).toBe(1);
|
||||||
|
const textInput = pagination.find(textInputSelector);
|
||||||
|
expect(textInput.length).toBe(1);
|
||||||
|
expect(textInput.at(0).prop('value')).toBe(1);
|
||||||
|
const input = pagination.find('TextInput');
|
||||||
|
expect(input.prop('value')).toBe(1);
|
||||||
|
input.prop('onChange')('!invalid');
|
||||||
|
pagination.update();
|
||||||
|
const submitForm = pagination.find(submitFormSelector);
|
||||||
|
expect(submitForm.length).toBe(1);
|
||||||
|
submitForm.simulate('submit');
|
||||||
|
expect(pagination.find('TextInput').prop('value')).toBe(1);
|
||||||
|
// assert onPageChange was not called
|
||||||
|
expect(paginationElem.state().value).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('text input page change is not displayed when only 1 page', () => {
|
test('text input page change is not displayed when only 1 page', () => {
|
||||||
const onSetPage = jest.fn();
|
const onSetPage = jest.fn();
|
||||||
@@ -269,25 +308,36 @@ describe('<Pagination />', () => {
|
|||||||
expect(pageInput.length).toBe(1);
|
expect(pageInput.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// test('make sure componentDidUpdate calls onPageChange', () => {
|
test('make sure componentDidUpdate calls onPageChange', () => {
|
||||||
// const onSetPage = jest.fn();
|
const onSetPage = jest.fn();
|
||||||
|
|
||||||
// pagination = mount(
|
pagination = mount(
|
||||||
// <I18nProvider>
|
<I18nProvider>
|
||||||
// <Pagination
|
<Pagination
|
||||||
// count={7}
|
count={7}
|
||||||
// page={1}
|
page={1}
|
||||||
// pageCount={2}
|
pageCount={2}
|
||||||
// page_size={5}
|
page_size={5}
|
||||||
// pageSizeOptions={[5, 10, 25, 50]}
|
pageSizeOptions={[5, 10, 25, 50]}
|
||||||
// onSetPage={onSetPage}
|
onSetPage={onSetPage}
|
||||||
// />
|
/>
|
||||||
// </I18nProvider>
|
</I18nProvider>
|
||||||
// );
|
);
|
||||||
// pagination.instance().onPageChange = jest.fn();
|
const paginationElem = pagination.find('Pagination');
|
||||||
// pagination.setProps({ page: 2 });
|
expect(paginationElem.state().value).toBe(1);
|
||||||
// pagination.update();
|
pagination.setProps({
|
||||||
// expect(pagination.instance().onPageChange).toHaveBeenCalledTimes(1);
|
children: (
|
||||||
// expect(pagination.instance().onPageChange).toBeCalledWith(2);
|
<Pagination
|
||||||
// });
|
count={7}
|
||||||
|
page={2}
|
||||||
|
pageCount={2}
|
||||||
|
page_size={5}
|
||||||
|
pageSizeOptions={[5, 10, 25, 50]}
|
||||||
|
onSetPage={onSetPage}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
});
|
||||||
|
paginationElem.update();
|
||||||
|
expect(paginationElem.state().value).toBe(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user