Skip to content

Commit

Permalink
fix: added testID
Browse files Browse the repository at this point in the history
  • Loading branch information
azeezat committed Aug 30, 2024
1 parent 49f39f7 commit dc612ad
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 60 deletions.
58 changes: 4 additions & 54 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ export default function App() {
label="Currency"
placeholder="Select multiple currencies..."
options={[
{
name: 'Naira (NGN) \u20A6',
code: 'NGN',
},
{name: 'Naira (NGN) \u20A6', code: 'NGN'},
{name: 'Dollar (USD) \u0024', code: 'USD'},
{name: 'Euro (EUR) \u20AC', code: 'EUR'},
]}
Expand Down Expand Up @@ -84,59 +81,18 @@ export default function App() {
modalControls={{
modalProps: {
onShow: () => logMovies(),
onDismiss: () => console.log('modal was dismissed'), //only works for ios
onDismiss: () => console.log('modal was dismissed'),
},
}}
autoCloseOnSelect={false}
/>

<DropdownSelect
label="Border has been removed"
placeholder="Select users"
options={[
{
value: '01',
labelComponent: (
<View
style={{
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
}}>
<Image
style={styles.avatarStyle}
source={{
uri: 'https://avatar.iran.liara.run/public/boy?username=Ash',
}}
/>

<Text>John Doe</Text>
</View>
),
},
{
value: '02',
labelComponent: (
<View
style={{
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
}}>
<Image
style={styles.avatarStyle}
source={{
uri: 'https://avatar.iran.liara.run/username?username=Azeezat+Raheem',
}}
/>

<Text>Azeezat Raheem</Text>
</View>
),
},
{label: 'John Doe', value: '12'},
{label: 'James Bond', value: '13'},
]}
optionLabel={'labelComponent'}
optionValue={'value'}
selectedValue={users}
onValueChange={(itemValue: any) => setUsers(itemValue)}
isSearchable
Expand Down Expand Up @@ -456,10 +412,4 @@ const styles = StyleSheet.create({
borderWidth: 3,
borderColor: 'white',
},
avatarStyle: {
height: 20,
width: 20,
borderRadius: 20,
marginRight: 5,
},
});
3 changes: 2 additions & 1 deletion src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ describe('Initial state of component', () => {
jest.useRealTimers();
});
const defaultDropdown = (
<DropdownSelect options={[]} onValueChange={() => {}} />
<DropdownSelect options={[]} onValueChange={() => {}} testID='some-random-test-id' />
);

test('show default texts', () => {
render(defaultDropdown);
expect(screen.getByTestId('some-random-test-id'));
expect(screen.getByText('Select an option'));
});

Expand Down
7 changes: 6 additions & 1 deletion src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { colors } from '../../styles/colors';
import { typography } from '../../styles/typography';

const Dropdown = ({
testID,
label,
placeholder,
helperText,
Expand All @@ -31,7 +32,11 @@ const Dropdown = ({
setIndexOfSelectedItem,
}: any) => {
return (
<View style={[styles.dropdownInputContainer, dropdownContainerStyle]}>
<View
style={[styles.dropdownInputContainer, dropdownContainerStyle]}
accessibilityRole="combobox"
testID={testID}
>
{label && label !== '' && (
<Text style={[styles.label, labelStyle]}>{label}</Text>
)}
Expand Down
10 changes: 6 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
import { escapeRegExp, extractPropertyFromArray } from './utils';

export const DropdownSelect: React.FC<DropdownProps> = ({
testID,
placeholder,
label,
error,
Expand Down Expand Up @@ -59,7 +60,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
searchControls,
modalControls,
checkboxControls,
autoCloseOnSelect=true,
autoCloseOnSelect = true,
...rest
}) => {
const [newOptions, setNewOptions] = useState<TFlatList | TSectionList>([]);
Expand Down Expand Up @@ -124,8 +125,8 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
setSelectedItem(value);
onValueChange(value); // send value to parent

if(autoCloseOnSelect){
setOpen(false); // close modal upon selection
if (autoCloseOnSelect) {
setOpen(false); // close modal upon selection
}
}
};
Expand Down Expand Up @@ -356,6 +357,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
return (
<>
<Dropdown
testID={testID}
label={label}
placeholder={placeholder}
helperText={helperText}
Expand Down Expand Up @@ -394,7 +396,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
ListHeaderComponent={
<>
{isSearchable && (
<Input
<Input
value={searchValue}
onChangeText={(text: string) => onSearch(text)}
style={searchControls?.textInputStyle || searchInputStyle}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type DropdownProps = CommonDropdownProps &
TListControls;

export type CommonDropdownProps = {
testID?: string;
label?: string;
options: TFlatList | TSectionList;
optionLabel?: string;
Expand Down

0 comments on commit dc612ad

Please sign in to comment.