Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paintroid 611 - Add main options to landing page #1291

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.catrobat.paintroid.test.espresso

import android.content.Context
import androidx.appcompat.widget.Toolbar
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import org.catrobat.paintroid.LandingPageActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.test.espresso.util.wrappers.OptionsMenuViewInteraction
import org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.hamcrest.core.IsNot
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LandingPageActivityIntegrationTest {

@get:Rule
var launchActivityRule = ActivityTestRule(LandingPageActivity::class.java)

@get:Rule
var screenshotOnFailRule = ScreenshotOnFailRule()

private lateinit var activity: LandingPageActivity

@Before
fun setUp() {
activity = launchActivityRule.activity
}

@Test
fun testTopAppBarDisplayed() {
onView(isAssignableFrom(Toolbar::class.java))
.check(matches(isDisplayed()))
}

@Test
fun testAppBarTitleDisplayPocketPaint() {
onView(withText("Pocket Paint"))
.check(matches(isDisplayed()))
}

@Test
fun testMoreOptionsAllItemsExist() {
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
OptionsMenuViewInteraction.onOptionsMenu()
.checkItemExists(R.string.menu_rate_us)
.checkItemExists(R.string.help_title)
.checkItemExists(R.string.pocketpaint_menu_about)
.checkItemExists(R.string.menu_feedback)
}

@Test
fun testMoreOptionsItemHelpClick() {
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.help_title))
.perform(click())
}

@Test
fun testOnHelpDisabled() {
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.help_title))
.check(matches(IsNot.not(ViewMatchers.isClickable())))
}

@Test
fun testMoreOptionsItemAboutClick() {
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.pocketpaint_about_title))
.perform(click())
}

@Test
fun testShowAboutClickedThenShowAboutDialog() {
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.pocketpaint_menu_about))
.perform(click())
val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
val aboutTextExpected: String = context.getString(
R.string.pocketpaint_about_content,
context.getString(R.string.pocketpaint_about_license)
)
onView(withText(aboutTextExpected))
.check(matches(isDisplayed()))
}

@Test
fun testMoreOptionsMenuAboutClosesMoreOptions() {
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.pocketpaint_menu_about))
.perform(click())
Espresso.pressBack()
onView(withText(R.string.pocketpaint_menu_about))
.check(ViewAssertions.doesNotExist())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.catrobat.paintroid.test.espresso

import android.content.Intent
import android.net.Uri
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.matcher.IntentMatchers.hasData
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.catrobat.paintroid.LandingPageActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.WelcomeActivity
import org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.hamcrest.CoreMatchers.allOf
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LandingPageActivityIntentTest {
@get:Rule
var launchActivityRule = ActivityTestRule(LandingPageActivity::class.java)

@get:Rule
var screenshotOnFailRule = ScreenshotOnFailRule()

@Before
fun setup() {
Intents.init()
}

@After
fun teardown() {
Intents.release()
}

@Test
fun testPlayStoreOpenedOnRateUsClicked() {
val applicationId = "org.catrobat.paintroid"
val uri = Uri.parse("market://details?id=$applicationId")
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.menu_rate_us))
.perform(click())
intended(
allOf(
hasAction(Intent.ACTION_VIEW),
hasData(uri)
)
)
}

@Test
fun testShowHelpClickedThenStartWelcomeActivity() {
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.help_title))
.perform(click())
intended(hasComponent(WelcomeActivity::class.java.name))
}

@Test
fun testMailOpenedOnFeedbackClicked() {
val uri = Uri.parse("mailto:[email protected]")
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.menu_feedback))
.perform(click())
intended(
allOf(
hasAction(Intent.ACTION_SENDTO),
hasData(uri)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ class LandscapeIntegrationTest {
onOptionsMenu()
.checkItemExists(R.string.menu_load_image)
.checkItemExists(R.string.menu_hide_menu)
.checkItemExists(R.string.help_title)
.checkItemExists(R.string.pocketpaint_menu_about)
.checkItemExists(R.string.menu_rate_us)
.checkItemExists(R.string.menu_save_image)
.checkItemExists(R.string.menu_save_copy)
.checkItemExists(R.string.menu_new_image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,9 @@ package org.catrobat.paintroid.test.espresso

import android.app.Activity
import android.content.Context
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.UserPreferences
import org.catrobat.paintroid.command.CommandFactory
import org.catrobat.paintroid.command.CommandManager
Expand All @@ -43,7 +34,6 @@ import org.catrobat.paintroid.contract.MainActivityContracts.Interactor
import org.catrobat.paintroid.contract.MainActivityContracts.MainView
import org.catrobat.paintroid.controller.ToolController
import org.catrobat.paintroid.presenter.MainActivityPresenter
import org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction.Companion.onTopBarView
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.catrobat.paintroid.tools.Workspace
import org.junit.Before
Expand Down Expand Up @@ -137,32 +127,6 @@ class MainActivityIntegrationTest {
}
}

@Test
fun testMoreOptionsMenuAboutTextIsCorrect() {
onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.pocketpaint_menu_about))
.perform(click())
val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
val aboutTextExpected: String = context.getString(
R.string.pocketpaint_about_content,
context.getString(R.string.pocketpaint_about_license)
)
onView(withText(aboutTextExpected))
.check(matches(isDisplayed()))
}

@Test
fun testMoreOptionsMenuAboutClosesMoreOptions() {
onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.pocketpaint_menu_about))
.perform(click())
pressBack()
onView(withText(R.string.pocketpaint_menu_about))
.check(doesNotExist())
}

@Test
fun testHandleActivityResultWhenIntentIsNull() {
launchActivityRule.activity.onActivityResult(0, Activity.RESULT_OK, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand Down Expand Up @@ -71,7 +70,6 @@ import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.instanceOf
import org.hamcrest.core.AllOf.allOf
import org.hamcrest.core.IsNot
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
Expand Down Expand Up @@ -188,12 +186,6 @@ class MenuFileActivityIntegrationTest {
onDrawingSurfaceView().check(matches(isDisplayed()))
}

@Test
fun testOnHelpDisabled() {
onTopBarView().performOpenMoreOptions()
onView(withText(R.string.help_title)).check(matches(IsNot.not(isClickable())))
}

@Test
fun testWarningDialogOnNewImage() {
onDrawingSurfaceView().perform(touchAt(MIDDLE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@
*/
package org.catrobat.paintroid.test.espresso

import android.app.Activity
import android.app.Instrumentation.ActivityResult
import android.content.Context
import android.content.Intent
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand Down Expand Up @@ -98,29 +93,15 @@ class MoreOptionsIntegrationTest {
OptionsMenuViewInteraction.onOptionsMenu()
.checkItemExists(R.string.menu_load_image)
.checkItemExists(R.string.menu_hide_menu)
.checkItemExists(R.string.help_title)
.checkItemExists(R.string.pocketpaint_menu_about)
.checkItemExists(R.string.menu_rate_us)
.checkItemExists(R.string.menu_save_image)
.checkItemExists(R.string.menu_save_copy)
.checkItemExists(R.string.menu_new_image)
.checkItemExists(R.string.menu_feedback)
.checkItemExists(R.string.share_image_menu)
.checkItemExists(R.string.menu_advanced)
.checkItemDoesNotExist(R.string.menu_discard_image)
.checkItemDoesNotExist(R.string.menu_export)
}

@Test
fun testMoreOptionsItemHelpClick() {
Espresso.onView(withText(R.string.help_title)).perform(ViewActions.click())
}

@Test
fun testMoreOptionsItemAboutClick() {
Espresso.onView(withText(R.string.pocketpaint_about_title)).perform(ViewActions.click())
}

@Test
fun testMoreOptionsShareImageClicked() {
Espresso.onView(withText(R.string.share_image_menu)).perform(ViewActions.click())
Expand All @@ -145,17 +126,6 @@ class MoreOptionsIntegrationTest {
Espresso.onView(withText(R.string.menu_save_copy)).perform(ViewActions.click())
}

@Test
fun testMoreOptionsFeedbackClick() {
val intent = Intent()
Intents.init()
val intentResult = ActivityResult(Activity.RESULT_OK, intent)
Intents.intending(IntentMatchers.anyIntent()).respondWith(intentResult)
Espresso.onView(withText(R.string.menu_feedback)).perform(ViewActions.click())
Intents.intended(IntentMatchers.hasAction(Intent.ACTION_SENDTO))
Intents.release()
}

@Test
fun testShowLikeUsDialogOnFirstSave() {
Espresso.onView(withText(R.string.menu_save_image)).perform(ViewActions.click())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,10 @@ class MoreOptionsIntegrationTest {
OptionsMenuViewInteraction.onOptionsMenu()
.checkItemExists(R.string.menu_load_image)
.checkItemExists(R.string.menu_hide_menu)
.checkItemExists(R.string.help_title)
.checkItemExists(R.string.pocketpaint_menu_about)
.checkItemExists(R.string.share_image_menu)
.checkItemDoesNotExist(R.string.menu_save_image)
.checkItemDoesNotExist(R.string.menu_save_copy)
.checkItemDoesNotExist(R.string.menu_new_image)
.checkItemDoesNotExist(R.string.menu_rate_us)
.checkItemExists(R.string.menu_discard_image)
.checkItemExists(R.string.menu_export)
}
Expand Down
3 changes: 3 additions & 0 deletions Paintroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
android:resource="@xml/filepaths"/>
</provider>

<activity
android:name=".LandingPageActivity"
android:theme="@style/PocketPaintTheme"/>
<activity
android:exported="false"
android:name=".WelcomeActivity"
Expand Down
Loading