Skip to content
Merged
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
113 changes: 54 additions & 59 deletions app/src/androidTest/kotlin/com/itsaky/androidide/ProjectBuildTest.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.itsaky.androidide

import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.uiautomator.UiSelector
import com.itsaky.androidide.activities.SplashActivity
import com.itsaky.androidide.screens.EditorScreen
import com.itsaky.androidide.scenarios.InitializationProjectAndCancelingBuildScenario
import com.itsaky.androidide.scenarios.NavigateToMainScreenScenario
import com.itsaky.androidide.screens.HomeScreen
import com.itsaky.androidide.screens.ProjectSettingsScreen
import com.itsaky.androidide.screens.TemplateScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import io.github.kakaocup.kakao.common.views.KView
import io.github.kakaocup.kakao.toolbar.KToolbar
import io.github.kakaocup.kakao.spinner.KSpinnerItem
import org.junit.Rule
import org.junit.Test

Expand All @@ -19,7 +18,7 @@ class ProjectBuildTest : TestCase() {
val activityRule = activityScenarioRule<SplashActivity>()

@Test
fun test_projectBuild_withJava_withBasicProject() {
fun test_projectBuild_baseProject_java() {
run {
step("Initialize the app") {
scenario(NavigateToMainScreenScenario())
Expand Down Expand Up @@ -48,85 +47,81 @@ class ProjectBuildTest : TestCase() {
}
step("Select the java language") {
ProjectSettingsScreen {
languageField {
spinner {
isVisible()
click()
}
open()

KView { withText("Java") }.click()
childAt<KSpinnerItem>(0) {
isVisible()
hasText("Java")
click()
}
}

createProjectButton {
isVisible()
click()
}
}
}
step("Close the first build dialog") {
flakySafely(120000) {
EditorScreen {
firstBuildDialog {
isDisplayed()
title {
hasText(R.string.title_first_build)
}
message {
hasText(R.string.msg_first_build)
}
positiveButton {
step("Initialization the project and cancelling the build") {
scenario(InitializationProjectAndCancelingBuildScenario())
}
}
}

@Test
fun test_projectBuild_baseProject_kotlin() {
run {
step("Initialize the app") {
scenario(NavigateToMainScreenScenario())
}
step("Click create project") {
flakySafely(60000) {
HomeScreen {
rvActions {
childAt<HomeScreen.ActionItem>(0) {
click()
}
}
}
}
}
step("Wait for the green button") {
flakySafely(180000) {
KView {
withText(R.string.msg_project_initialized)
}.isVisible()
flakySafely {
KView {
withParent {
KToolbar {
withId(R.id.editor_appBarLayout)
}
}
withId("ide.editor.build.quickRun".hashCode())
}.click()
}
}
}
step("Confirm that the install dialog appears and click cancel") {
flakySafely(120000) {
val installDialog =
device.uiDevice.findObject(UiSelector().text("Do you want to install this app?"))
val cancelButton = device.uiDevice.findObject(UiSelector().text("Cancel"))
if (installDialog.waitForExists(120000)) {
installDialog.exists()
cancelButton.click()
} else {
throw AssertionError("Install dialog not found!")
step("Select the basic project") {
flakySafely(10000) {
TemplateScreen {
rvTemplates {
childWith<TemplateScreen.TemplateItem> {
withDescendant { withText(R.string.template_basic) }
} perform { click() }
}
}
}
}
step("Click back and confirm that the Close Project dialog appears") {
device.uiDevice.pressBack()
step("Select the kotlin language") {
flakySafely {
EditorScreen {
closeProjectDialog {
title {
hasText(R.string.title_confirm_project_close)
}
message {
hasText(R.string.msg_confirm_project_close)
}
positiveButton {
ProjectSettingsScreen {
spinner {
isVisible()
open()

childAt<KSpinnerItem>(1) {
isVisible()
hasText("Kotlin")
click()
}
}

createProjectButton {
isVisible()
click()
}
}
}
}
step("Initialization the project and cancelling the build") {
scenario(InitializationProjectAndCancelingBuildScenario())
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.itsaky.androidide.scenarios

import androidx.test.uiautomator.UiSelector
import com.itsaky.androidide.R
import com.itsaky.androidide.screens.EditorScreen
import com.kaspersky.kaspresso.testcases.api.scenario.Scenario
import com.kaspersky.kaspresso.testcases.core.testcontext.TestContext
import io.github.kakaocup.kakao.common.views.KView
import io.github.kakaocup.kakao.toolbar.KToolbar

class InitializationProjectAndCancelingBuildScenario : Scenario() {

override val steps: TestContext<Unit>.() -> Unit = {
step("Close the first build dialog") {
flakySafely(120000) {
EditorScreen {
firstBuildDialog {
isDisplayed()
title {
hasText(R.string.title_first_build)
}
message {
hasText(R.string.msg_first_build)
}
positiveButton {
click()
}
}
}
}
}
step("Wait for the green button") {
flakySafely(180000) {
KView {
withText(R.string.msg_project_initialized)
}.isVisible()
flakySafely {
KView {
withParent {
KToolbar {
withId(R.id.editor_appBarLayout)
}
}
withId("ide.editor.build.quickRun".hashCode())
}.click()
}
}
}
step("Confirm that the install dialog appears and click cancel") {
flakySafely(120000) {
val installDialog =
device.uiDevice.findObject(UiSelector().text("Do you want to install this app?"))
val cancelButton = device.uiDevice.findObject(UiSelector().text("Cancel"))
if (installDialog.waitForExists(120000)) {
installDialog.exists()
cancelButton.click()
} else {
throw AssertionError("Install dialog not found!")
}
}
}
step("Click back and confirm that the Close Project dialog appears") {
device.uiDevice.pressBack()
flakySafely {
EditorScreen {
closeProjectDialog {
title {
hasText(R.string.title_confirm_project_close)
}
message {
hasText(R.string.msg_confirm_project_close)
}
positiveButton {
click()
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.itsaky.androidide
package com.itsaky.androidide.scenarios

import com.itsaky.androidide.screens.InstallToolsScreen
import com.itsaky.androidide.screens.OnboardingScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.itsaky.androidide.screens

import com.itsaky.androidide.R
import com.kaspersky.kaspresso.screens.KScreen
import io.github.kakaocup.kakao.common.views.KView
import io.github.kakaocup.kakao.spinner.KSpinner
import io.github.kakaocup.kakao.spinner.KSpinnerItem
import io.github.kakaocup.kakao.text.KButton

object ProjectSettingsScreen : KScreen<ProjectSettingsScreen>() {
Expand All @@ -11,12 +12,13 @@ object ProjectSettingsScreen : KScreen<ProjectSettingsScreen>() {

override val viewClass: Class<*>? = null

val languageField = KView {
withHint("Project Language")
}

val createProjectButton = KButton {
withText(R.string.create_project)
withId(R.id.finish)
}

val spinner = KSpinner(
builder = { withHint("Project Language") },
itemTypeBuilder = { itemType(::KSpinnerItem) }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,11 @@ inline fun projectLanguageParameter(
default = Java
displayName = Language::lang
startIcon = {
if (it.value == Kotlin) R.drawable.ic_language_kotlin
else R.drawable.ic_language_java
if (it.value == Kotlin) {
R.drawable.ic_language_kotlin
} else {
R.drawable.ic_language_java
}
}

configure()
Expand Down