Skip to content

Commit

Permalink
Add android tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Henning Hall committed Feb 5, 2020
1 parent e6654a5 commit 30b3bb3
Show file tree
Hide file tree
Showing 52 changed files with 12,340 additions and 95 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Android: build & test"

on: [push, pull_request]

jobs:
build_and_test:
name: Build & test
runs-on: macos-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Node
uses: actions/setup-node@v1

- name: Use specific Java version for sdkmanager to work
uses: joschi/setup-jdk@v1
with:
java-version: 'openjdk8'
architecture: 'x64'

- name: Download Android Emulator Image
run: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-29;google_apis;x86"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name emu --device "Nexus 5X" -k 'system-images;android-29;google_apis;x86'
$ANDROID_HOME/emulator/emulator -list-avds
- name: Install npm dependencies
working-directory: ./examples/detox
run: |
yarn install --frozen-lockfile
- name: Build
working-directory: ./examples/detox
run: |
yarn build:android-ci
- name: Start android emulator
working-directory: ./examples/detox
continue-on-error: true
run: |
echo "Starting emulator"
nohup $ANDROID_HOME/emulator/emulator -avd emu -no-audio -no-snapshot -no-window &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb devices
echo "Emulator started"
- name: Run tests
working-directory: ./examples/detox
run: yarn start & yarn test:android-ci

- name: Upload artifacts
uses: actions/upload-artifact@v1
if: failure()
with:
name: Failing tests
path: ./examples/detox/artifacts
1 change: 1 addition & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# React Native Date Picker [![npm](https://img.shields.io/npm/v/react-native-date-picker.svg)](https://www.npmjs.com/package/react-native-date-picker) <!--[![Build status](https://img.shields.io/bitrise/288d828c2f6731e6/master.svg?token=mGBI2QhCJBx18ffiS-MfpA&label=build)](https://app.bitrise.io/app/288d828c2f6731e6#/builds)--> [![npm](https://img.shields.io/npm/dm/react-native-date-picker.svg)](https://www.npmjs.com/package/react-native-date-picker)
# React Native Date Picker [![npm](https://img.shields.io/npm/v/react-native-date-picker.svg)](https://www.npmjs.com/package/react-native-date-picker) [![Build status](https://img.shields.io/github/workflow/status/henninghall/react-native-date-picker/Android:%20build%20&%20test?label=tests)](https://github.com/henninghall/react-native-date-picker/actions) [![npm](https://img.shields.io/npm/dm/react-native-date-picker.svg)](https://www.npmjs.com/package/react-native-date-picker)

<!--
[![Foo](https://7pjewxutn7.execute-api.us-east-1.amazonaws.com/default/date-picker-badge)](https://app.bitrise.io/app/288d828c2f6731e6#/builds)
[![Foo](https://app.bitrise.io/app/288d828c2f6731e6/status.svg?token=mGBI2QhCJBx18ffiS-MfpA&branch=master)](https://app.bitrise.io/app/288d828c2f6731e6#/builds)
-->

This is a React Native Date Picker with following main features:

Expand All @@ -13,10 +8,6 @@ This is a React Native Date Picker with following main features:
🌍 Multiple languages<br>
🎨 Customizable<br>

<!--
[![Monthly download](https://img.shields.io/npm/dm/react-native-date-picker.svg)](https://img.shields.io/npm/dm/react-native-date-picker.svg)
[![Total downloads](https://img.shields.io/npm/dt/react-native-date-picker.svg)](https://img.shields.io/npm/dt/react-native-date- picker.svg) -->

<table>
<tr>
<td align="center"><b>iOS</b></td>
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.facebook.react:react-native:+'
implementation 'com.henninghall.android:NumberPickerView:1.1.1'
implementation 'org.apache.commons:commons-lang3:3.6'
implementation 'com.henninghall.android:NumberPickerView:1.1.2'
implementation 'org.apache.commons:commons-lang3:3.7'
implementation group: 'net.time4j', name: 'time4j-android', version: '4.2-2018i'
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.henninghall.date_picker;

import android.content.res.Resources;
import android.util.Log;
import android.util.TypedValue;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
Expand All @@ -19,6 +16,8 @@
public class DatePickerManager extends SimpleViewManager<PickerView> {

public static final String REACT_CLASS = "DatePickerManager";
private static final int SCROLL = 1;

public static ThemedReactContext context;
private String date;

Expand Down Expand Up @@ -92,6 +91,21 @@ public void setStyle(PickerView view, int index, Integer style) {
if(index == 0) view.style.setHeight(style);
}

@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of(
"scroll", SCROLL
);
}

public void receiveCommand(final PickerView view, int command, final ReadableArray args) {
if (command == SCROLL) {
int wheelIndex = args.getInt(0);
int scrollTimes = args.getInt(1);
view.scroll(wheelIndex, scrollTimes);
}
}

@Override
protected void onAfterUpdateTransaction(PickerView view) {
super.onAfterUpdateTransaction(view);
Expand Down
14 changes: 12 additions & 2 deletions android/src/main/java/com/henninghall/date_picker/PickerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
Expand Down Expand Up @@ -130,7 +129,7 @@ public void setMinuteInterval(int interval) {
}

// Rounding cal to closest minute interval
public Calendar getInitialDate() {
public Calendar getInitialDate() {
Calendar cal = Calendar.getInstance();
if(minuteInterval <= 1) return cal;
int exactMinute = Integer.valueOf(minutesWheel.format.format(cal.getTime()));
Expand Down Expand Up @@ -232,4 +231,15 @@ protected SimpleDateFormat getDateFormat() {
return new SimpleDateFormat(getFormatPattern(), locale);
}

public void scroll(int wheelIndex, int scrollTimes) {
NumberPickerView picker = wheelOrder.getVisibleWheel(wheelIndex).picker;
int currentIndex = picker.getValue();
int maxValue = picker.getMaxValue();
boolean isWrapping = picker.getWrapSelectorWheel();
int nextValue = currentIndex + scrollTimes;
if(nextValue <= maxValue || isWrapping) {
picker.smoothScrollToValue(nextValue % (maxValue + 1));
}

}
}
2 changes: 0 additions & 2 deletions android/src/main/java/com/henninghall/date_picker/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.henninghall.date_picker.wheelFunctions.SetShowCount;
import com.henninghall.date_picker.wheelFunctions.TextColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class WheelOrder
}};
}

private void updateValueWheels(final Locale locale) {
private void updateAllWheels(final Locale locale) {
try {
this.orderedWheels = getOrderedWheels(locale);
pickerView.wheelsWrapper.removeAllViews();
Expand All @@ -45,7 +45,7 @@ private void updateValueWheels(final Locale locale) {


void update(final Locale locale) {
updateValueWheels(locale);
updateAllWheels(locale);
pickerView.emptyWheelUpdater.update();
}

Expand Down
7 changes: 7 additions & 0 deletions android/src/main/res/layout/datepicker_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/>
<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/year"
android:tag="year"
android:layout_width="wrap_content"
android:layout_height="match_parent"
custom:npv_ShownCount="5"
Expand Down Expand Up @@ -58,6 +59,7 @@
/>
<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/month"
android:tag="month"
android:layout_width="wrap_content"
android:layout_height="match_parent"
custom:npv_ShownCount="5"
Expand Down Expand Up @@ -87,6 +89,7 @@
/>
<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/date"
android:tag="date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
custom:npv_ShownCount="5"
Expand Down Expand Up @@ -116,6 +119,7 @@
/>
<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/day"
android:tag="day"
android:layout_height="match_parent"
android:layout_width="wrap_content"
custom:npv_ShownCount="5"
Expand All @@ -130,6 +134,7 @@
/>
<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/hour"
android:tag="hour"
android:layout_height="match_parent"
android:layout_width="wrap_content"
custom:npv_DividerColor="#cccccc"
Expand All @@ -145,6 +150,7 @@

<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/minutes"
android:tag="minutes"
android:layout_width="wrap_content"
android:layout_height="match_parent"
custom:npv_DividerColor="#cccccc"
Expand All @@ -160,6 +166,7 @@

<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/ampm"
android:tag="ampm"
android:layout_width="wrap_content"
android:layout_height="match_parent"
custom:npv_DividerColor="#cccccc"
Expand Down
4 changes: 2 additions & 2 deletions examples/detox/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.android.build.OutputFile
apply from: "../../node_modules/react-native/react.gradle"

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.detox.rn.example"
Expand Down
3 changes: 3 additions & 0 deletions examples/detox/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
buildscript {
ext.kotlinVersion = '1.3.0'
ext.compileSdkVersion = 28
ext.buildToolsVersion = '28.0.3'

ext.detoxKotlinVersion = ext.kotlinVersion

repositories {
Expand Down
2 changes: 1 addition & 1 deletion examples/detox/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rootProject.name = 'DetoxRNExample'
include ':react-native-date-picker'
project(':react-native-date-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-date-picker/android')
project(':react-native-date-picker').projectDir = new File(rootProject.projectDir, '../../../android')

include ':app'
6 changes: 4 additions & 2 deletions examples/detox/e2e/init.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const detox = require('detox')
const config = require('../package.json').detox
const adapter = require('detox/runners/mocha/adapter')
const { reset } = require("./utils")

before(async () => {
await detox.init(config)
})

beforeEach(async function() {
beforeEach(async function () {
await reset()
await adapter.beforeEach(this)
})

afterEach(async function() {
afterEach(async function () {
await adapter.afterEach(this)
})

Expand Down
2 changes: 1 addition & 1 deletion examples/detox/e2e/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--recursive
--timeout 300000
--bail
--file e2e/init.js
--slow 30000
28 changes: 28 additions & 0 deletions examples/detox/e2e/tests/24h-mode/hourWheel.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { scrollWheel, expectDate } = require("../../utils")


describe('Hour wheel', () => {

before(async () => {
await device.reloadReactNative()
await element(by.text('Advanced')).tap()
})

it('should have 24 hours', async () => {
await scroll3HoursAndExpect("2000-01-01 03:00:00")
await scroll3HoursAndExpect("2000-01-01 06:00:00")
await scroll3HoursAndExpect("2000-01-01 09:00:00")
await scroll3HoursAndExpect("2000-01-01 12:00:00")
await scroll3HoursAndExpect("2000-01-01 15:00:00")
await scroll3HoursAndExpect("2000-01-01 18:00:00")
await scroll3HoursAndExpect("2000-01-01 21:00:00")
await scroll3HoursAndExpect("2000-01-01 00:00:00")
})

const scroll3HoursAndExpect = async (date) => {
await scrollWheel(1, 3)
await expectDate(date)
}

})

49 changes: 49 additions & 0 deletions examples/detox/e2e/tests/24h-mode/mode.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { setMode } = require("../../utils")

describe('Modes - 24h', () => {

before(async () => {
await device.reloadReactNative()
await element(by.text('Advanced')).tap()
})

it('datetime', async () => {
await setMode("datetime")

await expect(element(by.id('day'))).toBeVisible()
await expect(element(by.id('minutes'))).toBeVisible()
await expect(element(by.id('hour'))).toBeVisible()

await expect(element(by.id('ampm'))).toNotExist()
await expect(element(by.id('month'))).toNotExist()
await expect(element(by.id('date'))).toNotExist()
await expect(element(by.id('year'))).toNotExist()
})

it('date', async () => {
await setMode("date")

await expect(element(by.id('month'))).toBeVisible()
await expect(element(by.id('date'))).toBeVisible()
await expect(element(by.id('year'))).toBeVisible()

await expect(element(by.id('day'))).toNotExist()
await expect(element(by.id('minutes'))).toNotExist()
await expect(element(by.id('hour'))).toNotExist()
await expect(element(by.id('ampm'))).toNotExist()
})

it('time', async () => {
await setMode("time")

await expect(element(by.id('minutes'))).toBeVisible()
await expect(element(by.id('hour'))).toBeVisible()

await expect(element(by.id('ampm'))).toNotExist()
await expect(element(by.id('day'))).toNotExist()
await expect(element(by.id('month'))).toNotExist()
await expect(element(by.id('date'))).toNotExist()
await expect(element(by.id('year'))).toNotExist()
})

})
Loading

0 comments on commit 30b3bb3

Please sign in to comment.