Skip to content

Commit

Permalink
selects option test paired and assigned other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
httpsmenahassan committed Sep 6, 2023
1 parent 8775b49 commit 5a947cd
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/Form/tests/FormAutosuggest.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
✓ renders component with options (5 ms) - Cindy done
✓ renders with error msg (8 ms) - Mena done
controlled behavior
✓ selects option (8 ms) - Pair
✓ when a function is passed to onClick, it is called (6 ms)
✓ when a function is not passed to onClick, it is not called (3 ms)
options list depends on empty field value (2 ms)
✓ options list depends on filled field value (2 ms)
toggles options list (3 ms)
shows options list depends on field value (2 ms)
closes options list on click outside (4 ms)
✓ selects option (8 ms) - Paired done
✓ when a function is passed to onClick, it is called (6 ms) - Cindy

Check failure on line 11 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed

Check failure on line 11 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed
✓ when a function is not passed to onClick, it is not called (3 ms) - Cindy
filters dropdown based on typed field value (2 ms) - Mena
toggles options list (3 ms) - Mena
filters options list based on field value (2 ms) - Cindy
closes options list on click outside (4 ms) - Mena
check focus on input after esc - Cindy
*/


Check failure on line 20 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

More than 1 blank line not allowed

Check failure on line 20 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

More than 1 blank line not allowed
Expand All @@ -33,8 +33,8 @@ function FormAutosuggestWrapper(props) {
);
}

function FormAutosuggestTestComponent(){
const onSelected = jest.fn();
function FormAutosuggestTestComponent(props){

Check failure on line 36 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing space before opening brace

Check failure on line 36 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing space before opening brace
const onSelected = props.onSelected ?? jest.fn()

Check failure on line 37 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

'onSelected' is missing in props validation

Check failure on line 37 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon

Check failure on line 37 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

'onSelected' is missing in props validation

Check failure on line 37 in src/Form/tests/FormAutosuggest.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
const onClick = jest.fn();
return (
<FormAutosuggestWrapper
Expand Down Expand Up @@ -114,12 +114,26 @@ describe('render behavior', () => {
});

describe('controlled behavior', () => {
it('selects option', () => {
container.find('input').simulate('click');
container.find('.pgn__form-autosuggest__dropdown').find('button')
.at(0).simulate('click');
it('sets input value based on clicked option', () => {
const { getByText, getByTestId } = render(<FormAutosuggestTestComponent />);
const input = getByTestId("autosuggest_textbox_input")

fireEvent.click(input)
const menuItem = getByText("Option 1")
fireEvent.click(menuItem)

expect(input.value).toEqual('Option 1');
});

it('calls onSelected based on clicked option', () => {
const onSelected = jest.fn();
const { getByText, getByTestId } = render(<FormAutosuggestTestComponent onSelected={onSelected}/>);
const input = getByTestId("autosuggest_textbox_input")

fireEvent.click(input)
const menuItem = getByText("Option 1")
fireEvent.click(menuItem)

expect(container.find('input').instance().value).toEqual('Option 1');
expect(onSelected).toHaveBeenCalledWith('Option 1');
expect(onSelected).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -256,26 +270,27 @@ describe('render behavior', () => {
// expect(container.find('input').instance().value).toEqual('');
// });

// it('options list depends on filled field value', () => {
// it('filters dropdown based on typed field value', () => {
// container.find('input').simulate('change', { target: { value: 'option 1' } });

// expect(container.find('.pgn__form-autosuggest__dropdown').find('button').length).toEqual(1);
// expect(onSelected).toHaveBeenCalledTimes(0);
// });

// it('toggles options list', () => {
// this is toggling when the dropdown button is clicked
// const dropdownContainer = '.pgn__form-autosuggest__dropdown';

// expect(container.find(dropdownContainer).find('button').length).toEqual(1);
// expect(container.find(dropdownContainer).find('button').length).toEqual(3);

// container.find('button.pgn__form-autosuggest__icon-button').simulate('click');
// expect(container.find(dropdownContainer).find('button').length).toEqual(0);

// container.find('button.pgn__form-autosuggest__icon-button').simulate('click');
// expect(container.find(dropdownContainer).find('button').length).toEqual(1);
// expect(container.find(dropdownContainer).find('button').length).toEqual(3);
// });

// it('shows options list depends on field value', () => {
// it('filters options list based on field value', () => {
// container.find('input').simulate('change', { target: { value: '1' } });

// expect(container.find('.pgn__form-autosuggest__dropdown').find('button').length).toEqual(2);
Expand Down

0 comments on commit 5a947cd

Please sign in to comment.