Skip to content

Commit

Permalink
Reuse dropdown and add test for addautocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant25062002 committed Jul 17, 2023
1 parent 17a6c34 commit 4c31c7a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 80 deletions.
8 changes: 0 additions & 8 deletions src/components/UI/Dropdown/DropDown.module.css

This file was deleted.

68 changes: 0 additions & 68 deletions src/components/UI/Dropdown/DropDown.tsx

This file was deleted.

46 changes: 46 additions & 0 deletions src/components/UI/Form/AddAutoComplete/AddAutoComplete.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { MockedProvider } from '@apollo/client/testing';
import { render } from '@testing-library/react';
import { AddAutoComplete } from './AddAutoComplete';
import { CREATE_LABEL } from 'graphql/mutations/Tags';
describe('<AddAutoComplete />', () => {
const mocks = [
{
request: {
query: CREATE_LABEL,
},
result: {
data: {
addAutoComplete: {
id: 1,
},
},
},
},
];
const option: any[] = [
{
description: null,
id: '1',
label: 'Messages',
},
];

const mockHandleChange = vi.fn();
const defaultProps = {
label: 'Example',
options: option,
optionLabel: 'label',
onChange: mockHandleChange,
field: { name: 'example', value: [] },
form: { dirty: false, touched: false, errors: false, setFieldValue: mockHandleChange },
};

it('renders <AddAutoComplete /> component', () => {
const wrapper = render(
<MockedProvider mocks={mocks}>
<AddAutoComplete {...defaultProps} />
</MockedProvider>
);
expect(wrapper).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.Input {
display: flex;
padding: 8px 0px;
min-width: 180px;
}

.Input label {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useNavigate } from 'react-router-dom';
import styles from './InteractiveMessageList.module.css';
import { useQuery } from '@apollo/client';
import { GET_TAGS } from 'graphql/queries/Tags';
import { DropDown } from 'components/UI/Dropdown/DropDown';
import { AutoComplete } from 'components/UI/Form/AutoComplete/AutoComplete';

const getLabel = (text: string) => (
<p data-testid="label" className={styles.LabelText}>
Expand Down Expand Up @@ -130,8 +130,28 @@ export const InteractiveMessageList = () => {
fetchPolicy: 'network-only',
});

// OnChange handler for the dropdown
const handleDropdownChange = (event: any) => {
setSelectedTag(event.target.value);
};

const tagFilter = (
<DropDown tag={tag} selectedtag={selectedtag} setSelectedTag={setSelectedTag} />
<AutoComplete
options={tag ? tag.tags : []}
optionLabel="label"
disabled={false}
hasCreateOption={false}
multiple={false}
onChange={(value: any) => {
setSelectedTag(value);
}}
form={{ setFieldValue: handleDropdownChange }}
field={{ value: selectedtag, onChange: handleDropdownChange }}
textFieldProps={{
variant: 'outlined',
label: t('Select Label'),
}}
/>
);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/containers/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const List = ({
orderWith: tableVals.sortCol,
},
};
}, [searchVal, tableVals, filters, filtersTag]);
}, [searchVal, tableVals, filters]);

// Get the total number of items here
const {
Expand Down
4 changes: 4 additions & 0 deletions src/graphql/queries/InteractiveMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const GET_INTERACTIVE_MESSAGE = gql`
id
label
}
tag {
id
label
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,6 @@
"Update ticket": "Update ticket",
"Opened by": "Opened by",
"Change assignee": "Change assignee",
"Select Tag": "Select Tag"
"Select Tag": "Select Tag",
"Select Label": "Select Label"
}

0 comments on commit 4c31c7a

Please sign in to comment.