-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/react-native/extend-expect'; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react-native'; | ||
|
||
import Button from './Button'; | ||
|
||
describe('Button', () => { | ||
const buttonTitle = 'Close'; | ||
it('should render correctly', () => { | ||
render(<Button title={buttonTitle} onPress={() => null} />); | ||
|
||
expect(screen.getByText(buttonTitle)).toBeTruthy(); | ||
}); | ||
|
||
it('should render loading correctly', () => { | ||
render(<Button title={buttonTitle} onPress={() => null} />); | ||
expect(screen.queryAllByTestId('buttonLoading')).toHaveLength(0); | ||
|
||
render(<Button title={buttonTitle} onPress={() => null} isLoading />); | ||
expect(screen.getByTestId('buttonLoading')).toBeTruthy(); | ||
}); | ||
|
||
it('should call onPress when presses the button', async () => { | ||
const onPress = jest.fn(); | ||
render(<Button title={buttonTitle} onPress={onPress} />); | ||
|
||
const button = screen.getByRole('button', { name: buttonTitle }); | ||
fireEvent.press(button); | ||
|
||
await waitFor(() => { | ||
expect(onPress).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react-native'; | ||
import { Search } from 'lucide-react-native'; | ||
|
||
import Input from './Input'; | ||
|
||
describe('Input', () => { | ||
it('should render correctly', () => { | ||
render( | ||
<Input | ||
onChangeText={() => {}} | ||
placeholder="Search..." | ||
rightIcon={<Search testID="searchIcon" />} | ||
/>, | ||
); | ||
|
||
expect(screen.getByPlaceholderText('Search...')).toBeTruthy(); | ||
expect(screen.getAllByTestId('searchIcon')).toBeTruthy(); | ||
|
||
render( | ||
<Input | ||
value="search keyword" | ||
onChangeText={() => {}} | ||
placeholder="Search..." | ||
rightIcon={<Search testID="searchIcon" />} | ||
/>, | ||
); | ||
|
||
expect(screen.getByDisplayValue('search keyword')).toBeTruthy(); | ||
}); | ||
|
||
it('Should call onChangeText function when text input changes', () => { | ||
const onChangeText = jest.fn(); | ||
|
||
render( | ||
<Input | ||
placeholder="Search..." | ||
onChangeText={onChangeText} | ||
rightIcon={<Search testID="searchIcon" />} | ||
/>, | ||
); | ||
|
||
fireEvent(screen.getByPlaceholderText('Search...'), 'changeText', 'article 1'); | ||
|
||
expect(onChangeText).toHaveBeenCalledWith('article 1'); | ||
}); | ||
}); |