Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature add test ids #190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/TapRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export type TapRatingProps = {
* Pass in a custom base image source
*/
starImage?: string;

/**
* Testing ID for Jest
*/
testId?: string;
};

const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
Expand Down Expand Up @@ -126,7 +131,7 @@ const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
setPosition(position);
};

const { count, reviews, showRating, reviewColor, reviewSize } = props;
const { count, reviews, showRating, reviewColor, reviewSize, testID } = props;
const rating_array = [];
const starContainerStyle = [styles.starContainer];

Expand All @@ -143,6 +148,7 @@ const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
_.times(count, (index) => {
rating_array.push(
<Star
testID={`${testID}_star_${index}`}
key={index}
position={index + 1}
starSelectedInPosition={(value) => {
Expand All @@ -155,9 +161,10 @@ const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
});

return (
<View style={ratingContainerStyle}>
<View testID={`${testID}_ratingContainer`} style={ratingContainerStyle}>
{showRating && (
<Text
testID={`${testID}_ratingText`}
style={[
styles.reviewText,
{ fontSize: reviewSize, color: reviewColor },
Expand All @@ -166,7 +173,9 @@ const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
{reviews[position - 1]}
</Text>
)}
<View style={starContainerStyle}>{renderStars(rating_array)}</View>
<View testID={`${testID}_starContainer`} style={starContainerStyle}>
{renderStars(rating_array)}
</View>
</View>
);
};
Expand All @@ -178,6 +187,7 @@ TapRating.defaultProps = {
showRating: true,
reviewColor: "rgba(230, 196, 46, 1)",
reviewSize: 25,
testID: "rating",
};

const styles = StyleSheet.create({
Expand Down
11 changes: 9 additions & 2 deletions src/components/Star.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type StarProps = {
starStyle?: StyleProp<ViewStyle>;
position?: number;
starSelectedInPosition?: ( number ) => void;
testId?: string;
};

const Star: React.FunctionComponent<StarProps> = props => {
Expand Down Expand Up @@ -51,14 +52,20 @@ const Star: React.FunctionComponent<StarProps> = props => {
selectedColor,
unSelectedColor,
isDisabled,
starStyle
starStyle,
testId
} = props;

const starSource =
fill && selectedColor === null ? STAR_SELECTED_IMAGE : starImage;

return (
<TouchableOpacity activeOpacity={1} onPress={spring} disabled={isDisabled}>
<TouchableOpacity
testId={testId}
activeOpacity={1}
onPress={spring}
disabled={isDisabled}
>
<Animated.Image
source={starSource}
style={[
Expand Down