Last active
January 31, 2022 02:38
-
-
Save shubhnik/2f1880718260c45ef72fab2ee04ae227 to your computer and use it in GitHub Desktop.
PL component for demonstration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("should add a note", async () => { | |
const { | |
getByTestId, | |
getByText | |
} = render( < PaymentLink / > ); | |
fireEvent.press(getByText("+Add")); | |
expect(getByTestId("note-title")).toBeTruthy(); | |
expect(getByTestId("note-description")).toBeTruthy(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Button = ({ children, onClick }) => ( | |
<TouchableOpacity style={SOME_STYLES} onPress={onclick}> | |
{title} | |
</TouchableOpacity> | |
); | |
const Section = ({ title, onClick, testID }) => ( | |
<View style={SOME_STYLES}> | |
<Text>{title}</Text> | |
<Button testID={testID}>+Add</Button> | |
</View> | |
); | |
const Note = () => ( | |
<View style={SOME_STYLES}> | |
<TextInput testID="note-title" placeholder="Title" /> | |
<TextInput testID="note-description" placeholder="Description" /> | |
</View> | |
); | |
export default class PaymentLink extends React.Component { | |
state = { | |
note: undefined, | |
}; | |
handleNoteAddition = note => { | |
this.setState({note: {id: RANDOM_ID, title: '', description: ''}}); | |
}; | |
render() { | |
return ( | |
<React.Fragment> | |
<AmountInput /> | |
<TextInput placeholder="Payment Link for?" /> | |
<Section | |
testID="add-note" | |
title="Internal Notes" | |
onClick={handleNoteAddition} | |
/> | |
{note ? <Note /> : null} | |
</React.Fragment> | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('should add a note', () => { | |
const wrapper = shallow( < PaymentLink / > ); | |
wrapper.find('Section').props().onClick(); | |
expect(wrapper.instance().state).toBe({ | |
note: { | |
id: RANDOM_ID, | |
title: "', description: | |
'' | |
} | |
}); | |
expect(wrapper).toMatchSnapshot(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment