Browse Source

Merge pull request #218 from henninghall/timezone-offset-tests

add timezone offset tests
master
Henning Hall 5 years ago
committed by GitHub
parent
commit
8a11f599b8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 2 deletions
  1. +81
    -0
      examples/detox/e2e/tests/timezoneOffset.spec.js
  2. +1
    -0
      examples/detox/e2e/utils.js
  3. +1
    -0
      examples/detox/src/CustomPropValue.js
  4. +8
    -2
      examples/detox/src/propPickers/DateChange.js

+ 81
- 0
examples/detox/e2e/tests/timezoneOffset.spec.js View File

@ -0,0 +1,81 @@
const {
setTimeZoneOffsetInMinutes,
expectDate,
scrollWheel,
expectDateString,
setMaximumDate,
setDate,
} = require('../utils')
const scrollMinuteWheel = () => scrollWheel(2, 1)
// I haven't found a way to change the timezone on the emulator to be able to run these tests.
// Until possible, run these tests locally when needed with Europe/Stockholm timezone.
describe.skip('Timezone offset', () => {
before(async () => {
await device.reloadReactNative()
await element(by.text('Advanced')).tap()
})
it('undefined (default)', async () => {
await setTimeZoneOffsetInMinutes(undefined)
await scrollMinuteWheel()
await expectDate('2000-01-01 00:01:00')
await expectDateString('Sat Jan 11201 AM ')
})
it('0', async () => {
await setTimeZoneOffsetInMinutes(0)
await scrollMinuteWheel()
await expectDate('2000-01-01 00:01:00')
await expectDateString('Fri Dec 311101 PM ')
})
it('180', async () => {
await setTimeZoneOffsetInMinutes(180)
await scrollMinuteWheel()
await expectDate('2000-01-01 00:01:00')
await expectDateString('Sat Jan 1201 AM ')
})
it('-180', async () => {
await setTimeZoneOffsetInMinutes(-180)
await scrollMinuteWheel()
await expectDate('2000-01-01 00:01:00')
await expectDateString('Fri Dec 31801 PM ')
})
describe('daylight saving', () => {
const firstOfJuly = new Date(2000, 6, 1, 0, 0)
const firstOfJune = new Date(2000, 5, 1, 0, 0)
before(async () => {
await setMaximumDate(firstOfJuly)
await setDate(firstOfJune)
})
it('undefined', async () => {
await setDate(firstOfJune)
await setTimeZoneOffsetInMinutes(undefined)
await scrollMinuteWheel()
await expectDate('2000-06-01 00:01:00')
await expectDateString('Thu Jun 11201 AM ')
})
it('0', async () => {
await setDate(firstOfJune)
await setTimeZoneOffsetInMinutes(0)
await scrollMinuteWheel()
await expectDate('2000-06-01 00:01:00')
await expectDateString('Wed May 311001 PM ')
})
it('180', async () => {
await setDate(firstOfJune)
await setTimeZoneOffsetInMinutes(180)
await scrollMinuteWheel()
await expectDate('2000-06-01 00:01:00')
await expectDateString('Thu Jun 1101 AM ')
})
})
})

+ 1
- 0
examples/detox/e2e/utils.js View File

@ -35,6 +35,7 @@ exports.setLocale = changeProp('locale')
exports.setMinimumDate = changeProp('minimumDate')
exports.setMaximumDate = changeProp('maximumDate')
exports.setMinuteInterval = changeProp('minuteInterval')
exports.setTimeZoneOffsetInMinutes = changeProp('timeZoneOffsetInMinutes')
exports.setMode = changeProp('mode')
exports.scrollWheel = scrollWheel
exports.expectDate = expectDate

+ 1
- 0
examples/detox/src/CustomPropValue.js View File

@ -8,6 +8,7 @@ export default function CustomPropValue(props) {
const getPropValue = () => {
if (propValue === "undefined") return undefined
if (propName === "minuteInterval") return parseInt(propValue)
if (propName === "timeZoneOffsetInMinutes") return parseInt(propValue)
if (["date", "maximumDate", "minimumDate"].includes(propName)) return new Date(propValue)
return propValue
}

+ 8
- 2
examples/detox/src/propPickers/DateChange.js View File

@ -13,7 +13,6 @@ export default class extends Component {
)
}
/>
<Text />
<Button
title="Add 1 hour"
onPress={() =>
@ -22,7 +21,6 @@ export default class extends Component {
)
}
/>
<Text />
<Button
title="Add 24 hours"
onPress={() =>
@ -31,6 +29,14 @@ export default class extends Component {
)
}
/>
<Button
title="Add 1 year"
onPress={() =>
this.props.onChange(
new Date(this.props.value.getTime() + 60 * 60 * 24 * 1000 * 365)
)
}
/>
</React.Fragment>
)
}

Loading…
Cancel
Save