Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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}_container`} 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}_starsContainer`} 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