Skip to content

Commit

Permalink
fix detox tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luancurti committed May 22, 2020
1 parent 943796b commit 087813c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ DerivedData
*.xcuserstate
project.xcworkspace

#Detox
#
artifacts

# Android/IntelliJ
#
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
minSdkVersion safeExtGet('minSdkVersion', 18)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
versionCode 1
versionName "1.0"
Expand Down
21 changes: 13 additions & 8 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const App = () => {
'{dayofweek.abbreviated(2)}',
);

const hidePicker = () => setShow(false);

const handleResetPress = () => {
setDate(undefined);
};
Expand Down Expand Up @@ -72,16 +74,20 @@ export const App = () => {

const showTimepickerDefaultWithInterval = () => {
showMode('time');
setDisplay('default');
setMinInterval(5);
setDisplay('default');
};

const showTimepickerSpinnerWithInterval = () => {
showMode('time');
setDisplay('spinner');
setMinInterval(5);
setDisplay('spinner');
};

const currentDateTime = moment
.utc(date)
.format(mode === 'time' ? 'HH:mm' : 'MM/DD/YYYY');

if (Platform.OS !== 'windows') {
return (
<>
Expand Down Expand Up @@ -146,7 +152,7 @@ export const App = () => {
</View>
<View style={styles.button}>
<Button
testID="timePickerIntervalButton"
testID="timePickerDefaultIntervalButton"
onPress={showTimepickerDefaultWithInterval}
title="Show time picker default (with 5 min interval)!"
/>
Expand All @@ -160,19 +166,18 @@ export const App = () => {
</View>
<View style={styles.header}>
<Text testID="dateTimeText" style={styles.dateTimeText}>
{mode === 'time' && moment.utc(date).format('HH:mm')}
{mode === 'date' && moment.utc(date).format('MM/DD/YYYY')}
{currentDateTime}
</Text>
<Button
testID="hidePicker"
onPress={() => setShow(false)}
onPress={hidePicker}
title="hide picker"
/>
</View>
{show && (
<DateTimePicker
testID="dateTimePicker"
minuteInterval={5}
minuteInterval={interval}
timeZoneOffsetInMinutes={0}
value={date}
mode={mode}
Expand Down Expand Up @@ -212,7 +217,7 @@ export const App = () => {
<Picker
style={{width: 200, height: 35}}
selectedValue={dateFormat}
onValueChange={value => setDateFormat(value)}>
onValueChange={setDateFormat}>
<Picker.Item
label="day month year"
value="day month year"
Expand Down
8 changes: 4 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
buildscript {
ext {
kotlinVersion = "1.3.71"
buildToolsVersion = "29.0.3"
buildToolsVersion = "28.0.3"
minSdkVersion = 18
compileSdkVersion = 29
targetSdkVersion = 29
compileSdkVersion = 28
targetSdkVersion = 26
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:3.5.2')
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
112 changes: 44 additions & 68 deletions example/e2e/detoxTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ describe('Example', () => {
});

it('should have title and hermes indicator on android', async () => {
await expect(element(by.id('appRootView'))).toBeVisible();
await expect(element(by.text('Example DateTime Picker'))).toBeVisible();
if (device.getPlatform() === 'android') {
await expect(element(by.id('hermesIndicator'))).toExist();
}
});

it('should show date picker after tapping datePicker button', async () => {
element(by.id('datePickerButton')).tap();
await element(by.id('datePickerButton')).tap();

if (global.device.getPlatform() === 'ios') {
await expect(
Expand All @@ -42,7 +41,7 @@ describe('Example', () => {
});

it('Nothing should happen if date doesn`t change', async () => {
element(by.id('datePickerButton')).tap();
await element(by.id('datePickerButton')).tap();
const dateTimeText = element(by.id('dateTimeText'));

if (global.device.getPlatform() === 'ios') {
Expand All @@ -57,23 +56,23 @@ describe('Example', () => {
);
testElement.swipe('left', 'fast', '100');
testElement.tapAtPoint({x: 50, y: 200});
element(by.text('CANCEL')).tap();
await element(by.text('CANCEL')).tap();
}

await expect(dateTimeText).toHaveText('08/21/2020');
});

it('should update dateTimeText when date changes', async () => {
element(by.id('datePickerButton')).tap();
await element(by.id('datePickerButton')).tap();
const dateTimeText = element(by.id('dateTimeText'));

if (global.device.getPlatform() === 'ios') {
const testElement = element(
by.type('UIPickerView').withAncestor(by.id('dateTimePicker')),
);
testElement.setColumnToValue(0, 'November');
testElement.setColumnToValue(1, '3');
testElement.setColumnToValue(2, '1800');
await testElement.setColumnToValue(0, 'November');
await testElement.setColumnToValue(1, '3');
await testElement.setColumnToValue(2, '1800');

await expect(dateTimeText).toHaveText('11/03/1800');
} else {
Expand All @@ -82,16 +81,16 @@ describe('Example', () => {
.type('android.widget.ScrollView')
.withAncestor(by.type('android.widget.DatePicker')),
);
testElement.swipe('left', 'fast', '100');
testElement.tapAtPoint({x: 50, y: 200});
element(by.text('OK')).tap();
await testElement.swipe('left', 'fast', '100');
await testElement.tapAtPoint({x: 50, y: 200});
await element(by.text('OK')).tap();

await expect(dateTimeText).toHaveText('09/13/2020');
}
});

it('should show time picker after tapping timePicker button', async () => {
element(by.id('timePickerButton')).tap();
await element(by.id('timePickerButton')).tap();

if (global.device.getPlatform() === 'ios') {
await expect(
Expand All @@ -103,7 +102,7 @@ describe('Example', () => {
});

it('Nothing should happen if time doesn`t change', async () => {
element(by.id('timePickerButton')).tap();
await element(by.id('timePickerButton')).tap();
const dateTimeText = element(by.id('dateTimeText'));

if (global.device.getPlatform() === 'ios') {
Expand All @@ -119,16 +118,16 @@ describe('Example', () => {
});

it('should change time text when time changes', async () => {
element(by.id('timePickerButton')).tap();
await element(by.id('timePickerButton')).tap();
const dateTimeText = element(by.id('dateTimeText'));

if (global.device.getPlatform() === 'ios') {
const testElement = element(
by.type('UIPickerView').withAncestor(by.id('dateTimePicker')),
);
testElement.setColumnToValue(0, '2');
testElement.setColumnToValue(1, '44');
testElement.setColumnToValue(2, 'PM');
await testElement.setColumnToValue(0, '2');
await testElement.setColumnToValue(1, '44');
await testElement.setColumnToValue(2, 'PM');

await expect(dateTimeText).toHaveText('14:44');
} else {
Expand All @@ -139,105 +138,82 @@ describe('Example', () => {
}
});

it("shouldn't change time text when time changes to less than half of minuteInterval", async () => {
element(by.id('timePickerIntervalButton')).tap();
it('should correct time text when using minuteInterval', async () => {
await element(by.id('timePickerDefaultIntervalButton')).tap();
const dateTimeText = element(by.id('dateTimeText'));

if (global.device.getPlatform() === 'ios') {
const testElement = element(
by.type('UIPickerView').withAncestor(by.id('dateTimePicker')),
);
testElement.setColumnToValue(0, '2');
testElement.setColumnToValue(1, '42');
testElement.setColumnToValue(2, 'PM');

await expect(dateTimeText).toHaveText('14:40');
} else {
const keyboardButton = element(
by.type('androidx.appcompat.widget.AppCompatImageButton'),
);
keyboardButton.tap();
const testElement = element(
by
.type('androidx.appcompat.widget.AppCompatEditText')
.and(by.text('15')),
);
testElement.tap();
testElement.replaceText('17');
element(by.text('OK')).tap();

await expect(dateTimeText).toHaveText('23:15');
}
});

it('should change time text when time changes to more than half of minuteInterval', async () => {
element(by.id('timePickerIntervalButton')).tap();
const dateTimeText = element(by.id('dateTimeText'));

if (global.device.getPlatform() === 'ios') {
const testElement = element(
by.type('UIPickerView').withAncestor(by.id('dateTimePicker')),
);
testElement.setColumnToValue(0, '2');
testElement.setColumnToValue(1, '44');
testElement.setColumnToValue(2, 'PM');
await testElement.setColumnToValue(0, '2');
await testElement.setColumnToValue(1, '45');
await testElement.setColumnToValue(2, 'PM');

await expect(dateTimeText).toHaveText('14:45');
} else {
const keyboardButton = element(
by.type('androidx.appcompat.widget.AppCompatImageButton'),
);
keyboardButton.tap();
await keyboardButton.tap();
const testElement = element(
by
.type('androidx.appcompat.widget.AppCompatEditText')
.and(by.text('15')),
);
testElement.tap();
testElement.replaceText('18');
element(by.text('OK')).tap();
await testElement.tap();
await testElement.replaceText('18');
await element(by.text('OK')).tap();

await expect(dateTimeText).toHaveText('23:20');
}
});

it('should correct input on the fly on android', async () => {
element(by.id('timePickerIntervalButton')).tap();
it('should change minutes when pressing in default interval button', async () => {
await element(by.id('timePickerDefaultIntervalButton')).tap();
const dateTimeText = element(by.id('dateTimeText'));

if (global.device.getPlatform() !== 'ios') {
if (global.device.getPlatform() === 'android') {
const keyboardButton = element(
by.type('androidx.appcompat.widget.AppCompatImageButton'),
);
keyboardButton.tap();
await keyboardButton.tap();

element(
await element(
by
.type('androidx.appcompat.widget.AppCompatEditText')
.and(by.text('15')),
).tap();
element(

await element(
by
.type('androidx.appcompat.widget.AppCompatEditText')
.and(by.text('15')),
).tapBackspaceKey();

element(
by
.type('androidx.appcompat.widget.AppCompatEditText')
.and(by.text('1')),
).typeText('8');
);

const minuteTextinput = element(
by.type('androidx.appcompat.widget.AppCompatEditText'),
).atIndex(1);

await minuteTextinput.replaceText('55');

await expect(
element(
by
.type('androidx.appcompat.widget.AppCompatEditText')
.and(by.text('18')),
.and(by.text('55')),
),
).toExist();
).toBeVisible();

element(by.text('OK')).tap();
await element(by.text('OK')).tap();

await expect(dateTimeText).toHaveText('23:20');
await expect(dateTimeText).toHaveText('23:55');
}
});
});
2 changes: 1 addition & 1 deletion example/e2e/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ detoxCircus.getEnv().addEventsListener(assignReporter);
detoxCircus.getEnv().addEventsListener(specReporter);

// Set the default timeout
jest.setTimeout(130000);
jest.setTimeout(13000);

beforeAll(async () => {
await detox.init(config);
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ PODS:
- React-cxxreact (= 0.62.2)
- React-jsi (= 0.62.2)
- ReactCommon/callinvoker (= 0.62.2)
- RNDateTimePicker (2.3.2):
- RNDateTimePicker (2.4.0):
- React
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -453,7 +453,7 @@ SPEC CHECKSUMS:
React-RCTText: fae545b10cfdb3d247c36c56f61a94cfd6dba41d
React-RCTVibration: 4356114dbcba4ce66991096e51a66e61eda51256
ReactCommon: ed4e11d27609d571e7eee8b65548efc191116eb3
RNDateTimePicker: 4bd49e09f91ca73d69119a9e1173b0d43b82f5e5
RNDateTimePicker: c4285bfdd87430f1e575b81a4742b7586a09d53e
Yoga: 3ebccbdd559724312790e7742142d062476b698e
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down

0 comments on commit 087813c

Please sign in to comment.