Skip to content

Commit 6c24aaa

Browse files
authored
Added integration for SourceEditor app with new screen manager SDK (#47)
Added integration for SourceEditor app with new screen manager SDK
1 parent 7f6602d commit 6c24aaa

File tree

21 files changed

+602
-205
lines changed

21 files changed

+602
-205
lines changed

SourceEditor/app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ android {
2424
}
2525

2626
dependencies {
27+
implementation microsoftDependencies.screenManager
28+
implementation microsoftDependencies.layouts
29+
implementation microsoftDependencies.fragmentsHandler
30+
2731
implementation googleDependencies.material
2832
implementation kotlinDependencies.kotlinStdlib
2933

@@ -33,8 +37,6 @@ dependencies {
3337
implementation androidxDependencies.ktxCore
3438
implementation androidxDependencies.ktxFragment
3539

36-
implementation microsoftDependencies.dualScreenLayout
37-
3840
testImplementation testDependencies.junit
3941

4042
androidTestImplementation instrumentationTestDependencies.junit

SourceEditor/app/src/androidTest/java/com/microsoft/device/display/samples/sourceeditor/ExampleInstrumentedTest.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

SourceEditor/app/src/androidTest/java/com/microsoft/device/display/samples/sourceeditor/InteractiveTest.kt

Lines changed: 0 additions & 121 deletions
This file was deleted.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*
5+
*/
6+
7+
package com.microsoft.device.display.samples.sourceeditor
8+
9+
import androidx.test.espresso.Espresso.onView
10+
import androidx.test.espresso.action.ViewActions.click
11+
import androidx.test.espresso.action.ViewActions.replaceText
12+
import androidx.test.espresso.matcher.ViewMatchers.withId
13+
import androidx.test.espresso.web.assertion.WebViewAssertions.webMatches
14+
import androidx.test.espresso.web.sugar.Web.onWebView
15+
import androidx.test.espresso.web.webdriver.DriverAtoms.findElement
16+
import androidx.test.espresso.web.webdriver.DriverAtoms.getText
17+
import androidx.test.espresso.web.webdriver.Locator
18+
import androidx.test.filters.MediumTest
19+
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
20+
import androidx.test.rule.ActivityTestRule
21+
import com.microsoft.device.display.samples.sourceeditor.utils.ScreenInfoListenerImpl
22+
import com.microsoft.device.display.samples.sourceeditor.utils.moveToLeft
23+
import com.microsoft.device.display.samples.sourceeditor.utils.moveToRight
24+
import com.microsoft.device.display.samples.sourceeditor.utils.spanFromLeft
25+
import com.microsoft.device.display.samples.sourceeditor.utils.spanFromRight
26+
import com.microsoft.device.display.samples.sourceeditor.utils.switchFromSingleToDualScreen
27+
import com.microsoft.device.display.samples.sourceeditor.utils.unspanToLeft
28+
import com.microsoft.device.display.samples.sourceeditor.utils.unspanToRight
29+
import com.microsoft.device.dualscreen.ScreenManagerProvider
30+
import org.hamcrest.core.StringContains.containsString
31+
import org.junit.After
32+
import org.junit.Assert.assertFalse
33+
import org.junit.Assert.assertTrue
34+
import org.junit.Before
35+
import org.junit.Rule
36+
import org.junit.Test
37+
import org.junit.runner.RunWith
38+
39+
@MediumTest
40+
@RunWith(AndroidJUnit4ClassRunner::class)
41+
class PreviewTest {
42+
@get:Rule
43+
val activityRule = ActivityTestRule(MainActivity::class.java, false, false)
44+
private var screenInfoListener = ScreenInfoListenerImpl()
45+
private val testString = "Testing in a different browser"
46+
47+
@Before
48+
fun setup() {
49+
val screenManager = ScreenManagerProvider.getScreenManager()
50+
screenManager.addScreenInfoListener(screenInfoListener)
51+
activityRule.launchActivity(null)
52+
}
53+
54+
@After
55+
fun tearDown() {
56+
val screenManager = ScreenManagerProvider.getScreenManager()
57+
screenManager.removeScreenInfoListener(screenInfoListener)
58+
screenInfoListener.resetScreenInfo()
59+
screenInfoListener.resetScreenInfoCounter()
60+
activityRule.finishActivity()
61+
}
62+
63+
@Test
64+
fun previewTextInSingleScreenMode() {
65+
screenInfoListener.waitForScreenInfoChanges()
66+
67+
onView(withId(R.id.btn_switch_to_preview)).perform(click())
68+
onWebView()
69+
.withElement(findElement(Locator.TAG_NAME, "h1"))
70+
.check(webMatches(getText(), containsString("Testing in a browser")))
71+
}
72+
73+
@Test
74+
fun previewTextInDualScreenMode() {
75+
screenInfoListener.waitForScreenInfoChanges()
76+
77+
onView(withId(R.id.textinput_code)).perform(replaceText("<h1>$testString</h1>"))
78+
switchFromSingleToDualScreen()
79+
assert(isSpanned())
80+
onWebView()
81+
.withElement(findElement(Locator.TAG_NAME, "h1"))
82+
.check(webMatches(getText(), containsString(testString)))
83+
}
84+
85+
@Test
86+
fun testSpanning() {
87+
screenInfoListener.waitForScreenInfoChanges()
88+
screenInfoListener.resetScreenInfo()
89+
90+
spanFromLeft()
91+
waitForScreenInfoAndAssert { assertTrue(isSpanned()) }
92+
unspanToRight()
93+
waitForScreenInfoAndAssert { assertFalse(isSpanned()) }
94+
spanFromRight()
95+
waitForScreenInfoAndAssert { assertTrue(isSpanned()) }
96+
unspanToLeft()
97+
waitForScreenInfoAndAssert { assertFalse(isSpanned()) }
98+
moveToRight()
99+
moveToLeft()
100+
}
101+
102+
private fun waitForScreenInfoAndAssert(assert: () -> Unit) {
103+
screenInfoListener.waitForScreenInfoChanges()
104+
assert()
105+
screenInfoListener.resetScreenInfo()
106+
}
107+
108+
private fun isSpanned(): Boolean {
109+
return screenInfoListener.screenInfo?.isDualMode() == true
110+
}
111+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.microsoft.device.display.samples.sourceeditor
2+
3+
import androidx.test.espresso.Espresso.onView
4+
import androidx.test.espresso.assertion.ViewAssertions.matches
5+
import androidx.test.espresso.matcher.ViewMatchers
6+
import androidx.test.espresso.matcher.ViewMatchers.withId
7+
import androidx.test.filters.MediumTest
8+
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
9+
import androidx.test.rule.ActivityTestRule
10+
import com.microsoft.device.display.samples.sourceeditor.utils.childOf
11+
import com.microsoft.device.display.samples.sourceeditor.utils.setOrientationLeft
12+
import com.microsoft.device.display.samples.sourceeditor.utils.setOrientationRight
13+
import com.microsoft.device.display.samples.sourceeditor.utils.switchFromSingleToDualScreen
14+
import com.microsoft.device.display.samples.sourceeditor.utils.unfreezeRotation
15+
import org.hamcrest.Matchers
16+
import org.junit.After
17+
import org.junit.Rule
18+
import org.junit.Test
19+
import org.junit.runner.RunWith
20+
21+
@RunWith(AndroidJUnit4ClassRunner::class)
22+
@MediumTest
23+
class SourceEditorInDualScreenTest {
24+
@get:Rule
25+
val activityRule = ActivityTestRule(MainActivity::class.java)
26+
27+
@After
28+
fun tearDown() {
29+
unfreezeRotation()
30+
}
31+
32+
@Test
33+
fun previewWithoutOrientation() {
34+
switchFromSingleToDualScreen()
35+
testPreview()
36+
}
37+
38+
@Test
39+
fun previewWithOrientationLeft() {
40+
switchFromSingleToDualScreen()
41+
setOrientationLeft()
42+
testPreview()
43+
}
44+
45+
@Test
46+
fun previewWithOrientationRight() {
47+
switchFromSingleToDualScreen()
48+
setOrientationRight()
49+
testPreview()
50+
}
51+
52+
private fun testPreview() {
53+
onView(
54+
childOf(withId(R.id.first_container_id), withId(R.id.btn_switch_to_editor))
55+
).check(matches(Matchers.not(ViewMatchers.isDisplayed())))
56+
onView(
57+
childOf(withId(R.id.first_container_id), withId(R.id.btn_switch_to_preview))
58+
).check(matches(Matchers.not(ViewMatchers.isDisplayed())))
59+
onView(withId(R.id.textinput_code)).check(matches(ViewMatchers.isDisplayed()))
60+
onView(withId(R.id.webview_preview)).check(matches(ViewMatchers.isDisplayed()))
61+
}
62+
}

0 commit comments

Comments
 (0)