-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added integration for SourceEditor app with new screen manager SDK (#47)
Added integration for SourceEditor app with new screen manager SDK
- Loading branch information
Showing
21 changed files
with
602 additions
and
205 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
27 changes: 0 additions & 27 deletions
27
...oidTest/java/com/microsoft/device/display/samples/sourceeditor/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
121 changes: 0 additions & 121 deletions
121
...src/androidTest/java/com/microsoft/device/display/samples/sourceeditor/InteractiveTest.kt
This file was deleted.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
...app/src/androidTest/java/com/microsoft/device/display/samples/sourceeditor/PreviewTest.kt
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,111 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
* | ||
*/ | ||
|
||
package com.microsoft.device.display.samples.sourceeditor | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.action.ViewActions.replaceText | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.web.assertion.WebViewAssertions.webMatches | ||
import androidx.test.espresso.web.sugar.Web.onWebView | ||
import androidx.test.espresso.web.webdriver.DriverAtoms.findElement | ||
import androidx.test.espresso.web.webdriver.DriverAtoms.getText | ||
import androidx.test.espresso.web.webdriver.Locator | ||
import androidx.test.filters.MediumTest | ||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import androidx.test.rule.ActivityTestRule | ||
import com.microsoft.device.display.samples.sourceeditor.utils.ScreenInfoListenerImpl | ||
import com.microsoft.device.display.samples.sourceeditor.utils.moveToLeft | ||
import com.microsoft.device.display.samples.sourceeditor.utils.moveToRight | ||
import com.microsoft.device.display.samples.sourceeditor.utils.spanFromLeft | ||
import com.microsoft.device.display.samples.sourceeditor.utils.spanFromRight | ||
import com.microsoft.device.display.samples.sourceeditor.utils.switchFromSingleToDualScreen | ||
import com.microsoft.device.display.samples.sourceeditor.utils.unspanToLeft | ||
import com.microsoft.device.display.samples.sourceeditor.utils.unspanToRight | ||
import com.microsoft.device.dualscreen.ScreenManagerProvider | ||
import org.hamcrest.core.StringContains.containsString | ||
import org.junit.After | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@MediumTest | ||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
class PreviewTest { | ||
@get:Rule | ||
val activityRule = ActivityTestRule(MainActivity::class.java, false, false) | ||
private var screenInfoListener = ScreenInfoListenerImpl() | ||
private val testString = "Testing in a different browser" | ||
|
||
@Before | ||
fun setup() { | ||
val screenManager = ScreenManagerProvider.getScreenManager() | ||
screenManager.addScreenInfoListener(screenInfoListener) | ||
activityRule.launchActivity(null) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
val screenManager = ScreenManagerProvider.getScreenManager() | ||
screenManager.removeScreenInfoListener(screenInfoListener) | ||
screenInfoListener.resetScreenInfo() | ||
screenInfoListener.resetScreenInfoCounter() | ||
activityRule.finishActivity() | ||
} | ||
|
||
@Test | ||
fun previewTextInSingleScreenMode() { | ||
screenInfoListener.waitForScreenInfoChanges() | ||
|
||
onView(withId(R.id.btn_switch_to_preview)).perform(click()) | ||
onWebView() | ||
.withElement(findElement(Locator.TAG_NAME, "h1")) | ||
.check(webMatches(getText(), containsString("Testing in a browser"))) | ||
} | ||
|
||
@Test | ||
fun previewTextInDualScreenMode() { | ||
screenInfoListener.waitForScreenInfoChanges() | ||
|
||
onView(withId(R.id.textinput_code)).perform(replaceText("<h1>$testString</h1>")) | ||
switchFromSingleToDualScreen() | ||
assert(isSpanned()) | ||
onWebView() | ||
.withElement(findElement(Locator.TAG_NAME, "h1")) | ||
.check(webMatches(getText(), containsString(testString))) | ||
} | ||
|
||
@Test | ||
fun testSpanning() { | ||
screenInfoListener.waitForScreenInfoChanges() | ||
screenInfoListener.resetScreenInfo() | ||
|
||
spanFromLeft() | ||
waitForScreenInfoAndAssert { assertTrue(isSpanned()) } | ||
unspanToRight() | ||
waitForScreenInfoAndAssert { assertFalse(isSpanned()) } | ||
spanFromRight() | ||
waitForScreenInfoAndAssert { assertTrue(isSpanned()) } | ||
unspanToLeft() | ||
waitForScreenInfoAndAssert { assertFalse(isSpanned()) } | ||
moveToRight() | ||
moveToLeft() | ||
} | ||
|
||
private fun waitForScreenInfoAndAssert(assert: () -> Unit) { | ||
screenInfoListener.waitForScreenInfoChanges() | ||
assert() | ||
screenInfoListener.resetScreenInfo() | ||
} | ||
|
||
private fun isSpanned(): Boolean { | ||
return screenInfoListener.screenInfo?.isDualMode() == true | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...st/java/com/microsoft/device/display/samples/sourceeditor/SourceEditorInDualScreenTest.kt
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,62 @@ | ||
package com.microsoft.device.display.samples.sourceeditor | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.filters.MediumTest | ||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import androidx.test.rule.ActivityTestRule | ||
import com.microsoft.device.display.samples.sourceeditor.utils.childOf | ||
import com.microsoft.device.display.samples.sourceeditor.utils.setOrientationLeft | ||
import com.microsoft.device.display.samples.sourceeditor.utils.setOrientationRight | ||
import com.microsoft.device.display.samples.sourceeditor.utils.switchFromSingleToDualScreen | ||
import com.microsoft.device.display.samples.sourceeditor.utils.unfreezeRotation | ||
import org.hamcrest.Matchers | ||
import org.junit.After | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
@MediumTest | ||
class SourceEditorInDualScreenTest { | ||
@get:Rule | ||
val activityRule = ActivityTestRule(MainActivity::class.java) | ||
|
||
@After | ||
fun tearDown() { | ||
unfreezeRotation() | ||
} | ||
|
||
@Test | ||
fun previewWithoutOrientation() { | ||
switchFromSingleToDualScreen() | ||
testPreview() | ||
} | ||
|
||
@Test | ||
fun previewWithOrientationLeft() { | ||
switchFromSingleToDualScreen() | ||
setOrientationLeft() | ||
testPreview() | ||
} | ||
|
||
@Test | ||
fun previewWithOrientationRight() { | ||
switchFromSingleToDualScreen() | ||
setOrientationRight() | ||
testPreview() | ||
} | ||
|
||
private fun testPreview() { | ||
onView( | ||
childOf(withId(R.id.first_container_id), withId(R.id.btn_switch_to_editor)) | ||
).check(matches(Matchers.not(ViewMatchers.isDisplayed()))) | ||
onView( | ||
childOf(withId(R.id.first_container_id), withId(R.id.btn_switch_to_preview)) | ||
).check(matches(Matchers.not(ViewMatchers.isDisplayed()))) | ||
onView(withId(R.id.textinput_code)).check(matches(ViewMatchers.isDisplayed())) | ||
onView(withId(R.id.webview_preview)).check(matches(ViewMatchers.isDisplayed())) | ||
} | ||
} |
Oops, something went wrong.