Skip to content

Commit

Permalink
Added integration for SourceEditor app with new screen manager SDK (#47)
Browse files Browse the repository at this point in the history
Added integration for SourceEditor app with new screen manager SDK
  • Loading branch information
ancirja-m authored Dec 9, 2020
1 parent 7f6602d commit 6c24aaa
Show file tree
Hide file tree
Showing 21 changed files with 602 additions and 205 deletions.
6 changes: 4 additions & 2 deletions SourceEditor/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ android {
}

dependencies {
implementation microsoftDependencies.screenManager
implementation microsoftDependencies.layouts
implementation microsoftDependencies.fragmentsHandler

implementation googleDependencies.material
implementation kotlinDependencies.kotlinStdlib

Expand All @@ -33,8 +37,6 @@ dependencies {
implementation androidxDependencies.ktxCore
implementation androidxDependencies.ktxFragment

implementation microsoftDependencies.dualScreenLayout

testImplementation testDependencies.junit

androidTestImplementation instrumentationTestDependencies.junit
Expand Down

This file was deleted.

This file was deleted.

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
}
}
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()))
}
}
Loading

0 comments on commit 6c24aaa

Please sign in to comment.