Replaced external image icon with MaterialIcons for money image
This commit is contained in:
parent
83776bc651
commit
76342ed534
@ -4,29 +4,29 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
TextInput,
|
TextInput,
|
||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
Image,
|
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
|
import { MaterialIcons } from "@expo/vector-icons";
|
||||||
|
|
||||||
interface BuyInSelectorProps {
|
interface BuyInSelectorProps {
|
||||||
setBuyInAmount: React.Dispatch<React.SetStateAction<number | null>>;
|
setBuyInAmount: React.Dispatch<React.SetStateAction<number | null>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultBuyInOptions = [10, 25, 50]; // Default buy-in values
|
const defaultBuyInOptions = [10, 25, 50];
|
||||||
|
|
||||||
const BuyInSelector: React.FC<BuyInSelectorProps> = ({ setBuyInAmount }) => {
|
const BuyInSelector: React.FC<BuyInSelectorProps> = ({ setBuyInAmount }) => {
|
||||||
const [customAmount, setCustomAmount] = useState("");
|
const [customAmount, setCustomAmount] = useState("");
|
||||||
const [buyInAmount, setBuyInAmountState] = useState<number | null>(null); // Store the selected amount locally
|
const [buyInAmount, setBuyInAmountState] = useState<number | null>(null);
|
||||||
|
|
||||||
const handleCustomAmountChange = (value: string) => {
|
const handleCustomAmountChange = (value: string) => {
|
||||||
const numericValue = parseFloat(value);
|
const numericValue = parseFloat(value);
|
||||||
if (!isNaN(numericValue) && numericValue >= 0) {
|
if (!isNaN(numericValue) && numericValue >= 0) {
|
||||||
setCustomAmount(value);
|
setCustomAmount(value);
|
||||||
setBuyInAmountState(numericValue); // Update buy-in amount
|
setBuyInAmountState(numericValue);
|
||||||
setBuyInAmount(numericValue); // Pass it back to parent component
|
setBuyInAmount(numericValue);
|
||||||
} else {
|
} else {
|
||||||
setCustomAmount("");
|
setCustomAmount("");
|
||||||
setBuyInAmountState(null); // Reset if invalid
|
setBuyInAmountState(null);
|
||||||
setBuyInAmount(null);
|
setBuyInAmount(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -34,23 +34,16 @@ const BuyInSelector: React.FC<BuyInSelectorProps> = ({ setBuyInAmount }) => {
|
|||||||
const handleBuyInSelection = (amount: number) => {
|
const handleBuyInSelection = (amount: number) => {
|
||||||
setBuyInAmountState(amount);
|
setBuyInAmountState(amount);
|
||||||
setCustomAmount("");
|
setCustomAmount("");
|
||||||
setBuyInAmount(amount); // Pass it back to parent component
|
setBuyInAmount(amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
{/* Title with Money Icon */}
|
|
||||||
<View style={styles.header}>
|
<View style={styles.header}>
|
||||||
<Image
|
<MaterialIcons name="monetization-on" size={30} color="green" />
|
||||||
source={{
|
|
||||||
uri: "https://png.pngtree.com/png-vector/20191128/ourmid/pngtree-coin-money-icon-png-image_2049478.jpg",
|
|
||||||
}}
|
|
||||||
style={styles.icon}
|
|
||||||
/>
|
|
||||||
<Text style={styles.title}>Select Buy-in Amount:</Text>
|
<Text style={styles.title}>Select Buy-in Amount:</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Default Buy-In Options */}
|
|
||||||
<View style={styles.optionsContainer}>
|
<View style={styles.optionsContainer}>
|
||||||
{defaultBuyInOptions.map((amount) => (
|
{defaultBuyInOptions.map((amount) => (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
@ -66,7 +59,6 @@ const BuyInSelector: React.FC<BuyInSelectorProps> = ({ setBuyInAmount }) => {
|
|||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Custom Amount Input */}
|
|
||||||
<Text style={styles.orText}>Or enter a custom amount:</Text>
|
<Text style={styles.orText}>Or enter a custom amount:</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
@ -76,7 +68,6 @@ const BuyInSelector: React.FC<BuyInSelectorProps> = ({ setBuyInAmount }) => {
|
|||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Display the selected buy-in amount */}
|
|
||||||
<Text style={styles.selectionText}>
|
<Text style={styles.selectionText}>
|
||||||
Selected Buy-in: {buyInAmount !== null ? buyInAmount : "None"}
|
Selected Buy-in: {buyInAmount !== null ? buyInAmount : "None"}
|
||||||
</Text>
|
</Text>
|
||||||
@ -93,13 +84,9 @@ const styles = StyleSheet.create({
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
},
|
},
|
||||||
icon: {
|
|
||||||
width: 50,
|
|
||||||
height: 50,
|
|
||||||
marginRight: 15,
|
|
||||||
},
|
|
||||||
title: {
|
title: {
|
||||||
fontSize: 22,
|
fontSize: 22,
|
||||||
|
marginLeft: 10,
|
||||||
},
|
},
|
||||||
optionsContainer: {
|
optionsContainer: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
|
@ -2,6 +2,14 @@ import React from "react";
|
|||||||
import { fireEvent, render } from "@testing-library/react-native";
|
import { fireEvent, render } from "@testing-library/react-native";
|
||||||
import BuyInSelector from "@/components/BuyInSelector";
|
import BuyInSelector from "@/components/BuyInSelector";
|
||||||
|
|
||||||
|
jest.mock("@expo/vector-icons", () => {
|
||||||
|
const React = require("react");
|
||||||
|
const { Text } = require("react-native");
|
||||||
|
return {
|
||||||
|
MaterialIcons: () => <Text>MaterialIcons</Text>,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe("BuyInSelector Component", () => {
|
describe("BuyInSelector Component", () => {
|
||||||
it("renders the buy-in options and input correctly", () => {
|
it("renders the buy-in options and input correctly", () => {
|
||||||
const setBuyInAmount = jest.fn();
|
const setBuyInAmount = jest.fn();
|
||||||
@ -23,6 +31,7 @@ describe("BuyInSelector Component", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fireEvent.press(getByText("25"));
|
fireEvent.press(getByText("25"));
|
||||||
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(25);
|
expect(setBuyInAmount).toHaveBeenCalledWith(25);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -33,6 +42,7 @@ describe("BuyInSelector Component", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "100");
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "100");
|
||||||
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(100);
|
expect(setBuyInAmount).toHaveBeenCalledWith(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -43,6 +53,7 @@ describe("BuyInSelector Component", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "-10");
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "-10");
|
||||||
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(null);
|
expect(setBuyInAmount).toHaveBeenCalledWith(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,7 +64,25 @@ describe("BuyInSelector Component", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "100");
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "100");
|
||||||
|
|
||||||
fireEvent.press(getByText("50"));
|
fireEvent.press(getByText("50"));
|
||||||
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(50);
|
expect(setBuyInAmount).toHaveBeenCalledWith(50);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("handles valid and invalid input for custom amount correctly", () => {
|
||||||
|
const setBuyInAmount = jest.fn();
|
||||||
|
const { getByPlaceholderText } = render(
|
||||||
|
<BuyInSelector setBuyInAmount={setBuyInAmount} />
|
||||||
|
);
|
||||||
|
|
||||||
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "75");
|
||||||
|
expect(setBuyInAmount).toHaveBeenCalledWith(75);
|
||||||
|
|
||||||
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "-5");
|
||||||
|
expect(setBuyInAmount).toHaveBeenCalledWith(null);
|
||||||
|
|
||||||
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "abc");
|
||||||
|
expect(setBuyInAmount).toHaveBeenCalledWith(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user