-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4513 from wix/4512-create-test-for-alert-api
test(e2e): add tests for interactions with React Native alerts.
- Loading branch information
Showing
4 changed files
with
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe('alerts', () => { | ||
|
||
beforeAll(async () => { | ||
await device.launchApp({ | ||
delete: true, | ||
newInstance: true, | ||
}); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await device.reloadReactNative(); | ||
await element(by.text('Alerts')).tap(); | ||
}); | ||
|
||
it('should click on ok and cancel buttons', async () => { | ||
await expect(element(by.id('AlertScreen.Text'))).toHaveText('Not Pressed'); | ||
await element(by.id('AlertScreen.Button')).tap(); | ||
await expect(element(by.text('Alert Title'))).toBeVisible(); | ||
await expect(element(by.text('My Alert Msg'))).toBeVisible(); | ||
await element(by.text('OK')).tap(); | ||
await expect(element(by.id('AlertScreen.Text'))).toHaveText('OK Pressed'); | ||
await element(by.id('AlertScreen.Button')).tap(); | ||
await element(by.text('Cancel')).tap(); | ||
await expect(element(by.id('AlertScreen.Text'))).toHaveText('Cancel Pressed'); | ||
}); | ||
}); |
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,37 @@ | ||
import React, { Component, useState } from 'react'; | ||
import { Alert, Button, SafeAreaView, Text, View } from 'react-native'; | ||
|
||
|
||
const AlertComponent = () => { | ||
const [textState, setTextState] = useState('Not Pressed'); | ||
|
||
return ( | ||
<SafeAreaView style={{ flex: 1 }}> | ||
<View style={{ flex: 1, alignContent: 'center' }}> | ||
<Text style={{ padding: 16 }} testID='AlertScreen.Text'>{textState}</Text> | ||
|
||
<Button title={'Show Alert'} testID='AlertScreen.Button' onPress={() => { | ||
Alert.alert( | ||
'Alert Title', | ||
'My Alert Msg', | ||
[{ | ||
text: 'Cancel', | ||
onPress: () => setTextState('Cancel Pressed') | ||
}, { | ||
text: 'OK', | ||
onPress: () => setTextState('OK Pressed') | ||
} | ||
]); | ||
}} /> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default class AlertScreen extends Component { | ||
render() { | ||
return ( | ||
<AlertComponent /> | ||
); | ||
} | ||
} |
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