Skip to content

Commit

Permalink
Merge pull request #51 from AAkira/v1.4.3
Browse files Browse the repository at this point in the history
V1.4.3
  • Loading branch information
AAkira committed Mar 6, 2016
2 parents 997b85e + 733c520 commit 8f2d741
Show file tree
Hide file tree
Showing 30 changed files with 1,009 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ buildscript {
}
dependencies {
compile 'com.github.aakira:expandable-layout:1.4.2@aar'
compile 'com.github.aakira:expandable-layout:1.4.3@aar'
}
```

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.novoda:bintray-release:0.3.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
}
}

Expand Down
6 changes: 5 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ dependencies:

test:
pre:
- emulator -avd circleci-android21 -no-skin -no-audio -no-window:
- emulator -avd circleci-android21 -no-audio -no-window:
background: true
parallel: true
- circle-android wait-for-boot
override:
# unlock the emulator screen
- sleep 30
- adb shell input keyevent 82
- ./gradlew connectedAndroidTest -PdisablePreDex
post:
- cp -R ./library/build/reports/androidTests/connected/* $CIRCLE_ARTIFACTS
- cp -R ./library-ui-test/build/reports/androidTests/connected/* $CIRCLE_ARTIFACTS
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ COMPILE_SDK_VERSION=23
BUILD_TOOLS_VERSION=22.0.1
MIN_SDK_VERSION=11
TARGET_SDK_VERSION=23
VERSION_CODE=7
VERSION_NAME=1.4.2
VERSION_CODE=8
VERSION_NAME=1.4.3
SUPPORT_TEST_VERSION=0.4.1
HAMCREST_VERSION=1.3
ESPRESSO_VERSION=2.2.1
KOTLIN_VERSION=1.0.0

SUPPORT_APP_COMPAT_VERSION=23.0.1

Expand Down
1 change: 1 addition & 0 deletions library-ui-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
36 changes: 36 additions & 0 deletions library-ui-test/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}

dependencies {
compile project(':library')

compile "com.android.support:appcompat-v7:$SUPPORT_APP_COMPAT_VERSION"
compile "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
androidTestCompile "com.android.support:support-annotations:$SUPPORT_APP_COMPAT_VERSION"
androidTestCompile "com.android.support.test:runner:$SUPPORT_TEST_VERSION"
androidTestCompile "com.android.support.test:rules:$SUPPORT_TEST_VERSION"
androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION"
}
17 changes: 17 additions & 0 deletions library-ui-test/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Applications/android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.github.aakira.expandablelayout.uitest

import android.app.Activity
import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.runner.AndroidJUnit4
import android.test.ActivityInstrumentationTestCase2
import com.github.aakira.expandablelayout.ExpandableRelativeLayout
import com.github.aakira.expandablelayout.uitest.utils.ElapsedIdLingResource
import com.github.aakira.expandablelayout.uitest.utils.equalHeight
import com.github.aakira.expandablelayout.uitest.utils.orMoreHeight
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsNull.notNullValue
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.hamcrest.CoreMatchers.`is` as _is

@RunWith(AndroidJUnit4::class)
class ExpandableRelativeLayoutActivityTest : ActivityInstrumentationTestCase2<ExpandableRelativeLayoutActivity>
(ExpandableRelativeLayoutActivity::class.java) {

companion object {
val DURATION = 500L
}

@Before
@Throws(Exception::class)
public override fun setUp() {
super.setUp()
injectInstrumentation(InstrumentationRegistry.getInstrumentation())
}

@After
@Throws(Exception::class)
public override fun tearDown() {
super.tearDown()
}

@Test
fun testExpandableRelativeLayout() {
val activity = activity
val instrumentation = instrumentation

// check activity
assertThat<Activity>(activity, notNullValue())
assertThat(instrumentation, notNullValue())

val expandableLayout = activity.findViewById(R.id.expandableLayout) as ExpandableRelativeLayout

// default close
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(0)))

// open toggle
instrumentation.runOnMainSync { expandableLayout.toggle() }
var idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
onView(withId(R.id.expandableLayout)).check(matches(orMoreHeight(1)))
Espresso.unregisterIdlingResources(idlingResource)

// move to first layout
instrumentation.runOnMainSync { expandableLayout.moveChild(0) }
idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
onView(withId(R.id.child1)).check(matches(equalHeight(expandableLayout)))
Espresso.unregisterIdlingResources(idlingResource)

// set close height
instrumentation.runOnMainSync { expandableLayout.closePosition = expandableLayout.currentPosition; }

// move to second layout
instrumentation.runOnMainSync { expandableLayout.moveChild(1) }
idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
// second.height != 0 && first.height + second.height == expandableLayout.height
onView(withId(R.id.child2)).check(matches(orMoreHeight(1)))
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(
activity.findViewById(R.id.child1),
activity.findViewById(R.id.child2)
)))
Espresso.unregisterIdlingResources(idlingResource)

// check toggle (close to first)
instrumentation.runOnMainSync { expandableLayout.toggle() }
idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
// move to first position
onView(withId(R.id.child1)).check(matches(equalHeight(expandableLayout)))
Espresso.unregisterIdlingResources(idlingResource)

// check toggle open (full)
instrumentation.runOnMainSync { expandableLayout.toggle() }
idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
// move to first position
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(
activity.findViewById(R.id.child1),
activity.findViewById(R.id.child2),
activity.findViewById(R.id.child3)
)))
Espresso.unregisterIdlingResources(idlingResource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.github.aakira.expandablelayout.uitest

import android.app.Activity
import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.runner.AndroidJUnit4
import android.test.ActivityInstrumentationTestCase2
import com.github.aakira.expandablelayout.ExpandableRelativeLayout
import com.github.aakira.expandablelayout.uitest.utils.ElapsedIdLingResource
import com.github.aakira.expandablelayout.uitest.utils.equalHeight
import com.github.aakira.expandablelayout.uitest.utils.equalWidth
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsNull.notNullValue
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.hamcrest.CoreMatchers.`is` as _is

@RunWith(AndroidJUnit4::class)
class ExpandableRelativeLayoutActivityTest2 : ActivityInstrumentationTestCase2<ExpandableRelativeLayoutActivity2>
(ExpandableRelativeLayoutActivity2::class.java) {

companion object {
val DURATION = 350L
}

@Before
@Throws(Exception::class)
public override fun setUp() {
super.setUp()
injectInstrumentation(InstrumentationRegistry.getInstrumentation())
}

@After
@Throws(Exception::class)
public override fun tearDown() {
super.tearDown()
}

@Test
fun testExpandableRelativeLayout2() {
val activity = activity
val instrumentation = instrumentation
val resources = activity.resources

// check activity
assertThat<Activity>(activity, notNullValue())
assertThat(instrumentation, notNullValue())

val expandableLayout = activity.findViewById(R.id.expandableLayout) as ExpandableRelativeLayout
val expandableLayoutPadding = resources.getDimensionPixelSize(R.dimen.margin_large)

// default close
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(0)))
// width
onView(withId(R.id.child1)).check(matches(
equalWidth(resources.getDimensionPixelSize(R.dimen.relative_layout_2_child_1_width))))
onView(withId(R.id.child2)).check(matches(
equalWidth(resources.getDimensionPixelSize(R.dimen.relative_layout_2_child_2_width))))

// open toggle
instrumentation.runOnMainSync { expandableLayout.toggle() }
var idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(
activity.findViewById(R.id.child1),
activity.findViewById(R.id.child3),
margin = expandableLayoutPadding
)))
Espresso.unregisterIdlingResources(idlingResource)

// move to first layout
instrumentation.runOnMainSync { expandableLayout.moveChild(0) }
idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(
activity.findViewById(R.id.child1),
margin = expandableLayoutPadding
)))
Espresso.unregisterIdlingResources(idlingResource)

// move to second layout
instrumentation.runOnMainSync { expandableLayout.moveChild(1) }
idlingResource = ElapsedIdLingResource(DURATION)
Espresso.registerIdlingResources(idlingResource)
onView(withId(R.id.expandableLayout)).check(matches(equalHeight(
activity.findViewById(R.id.child2),
margin = expandableLayoutPadding
)))
Espresso.unregisterIdlingResources(idlingResource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.aakira.expandablelayout.uitest.utils

import android.content.Context
import android.util.DisplayMetrics
import android.view.WindowManager

fun Context.getDisplayMetrics(): DisplayMetrics {
val metrics = DisplayMetrics()
(getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(metrics)
return metrics
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.aakira.expandablelayout.uitest.utils;

import android.support.test.espresso.IdlingResource;

/**
* Referenced from stack over flow.
* http://stackoverflow.com/questions/30155227/espresso-how-to-wait-for-some-time1-hour
*/
public class ElapsedIdLingResource implements IdlingResource {
private final long startTime;
private final long waitingTime;
private ResourceCallback resourceCallback;

public ElapsedIdLingResource(long waitingTime) {
this.startTime = System.currentTimeMillis();
this.waitingTime = waitingTime;
}

@Override
public String getName() {
return ElapsedIdLingResource.class.getName() + ":" + waitingTime;
}

@Override
public boolean isIdleNow() {
long elapsed = System.currentTimeMillis() - startTime;
boolean idle = (elapsed >= waitingTime);
if (idle) {
resourceCallback.onTransitionToIdle();
}
return idle;
}

@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}
}
Loading

0 comments on commit 8f2d741

Please sign in to comment.