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

Org Screen Tested #1053

Open
wants to merge 7 commits into
base: master
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
10 changes: 10 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ android {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'


}
}
Expand Down Expand Up @@ -272,6 +275,13 @@ dependencies {
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"
testImplementation "org.robolectric:robolectric:4.8.1"

// dependency for Compose UI test
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"




}

configurations.all {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package org.greenstand.android.TreeTracker.orgpicker

import android.content.Context
import android.content.res.Resources
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.test.*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying to run this test locally I couldn't get it working. Were you able to run this test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.greenstand.android.TreeTracker.activities.TreeTrackerActivity
import org.greenstand.android.TreeTracker.models.organization.Destination
import org.greenstand.android.TreeTracker.models.organization.Org
import org.greenstand.android.TreeTracker.view.AppButtonColors
import org.greenstand.android.TreeTracker.view.DepthButtonColors
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.koin.androidx.compose.R
import org.koin.androidx.compose.viewModel

@RunWith(AndroidJUnit4::class)
class OrgPickerScreenKtTest {
precious3173 marked this conversation as resolved.
Show resolved Hide resolved

@get:Rule
val rule = createAndroidComposeRule<TreeTrackerActivity>()




//Test is working
@Test
fun OrgItemNameEqualsInputName() {

var isClicked:Boolean = false

rule.setContent {
OrgItem(
Org(
id = "123",
name = "BESTORG",
walletId = "abc",
logoPath = "path",
mutableListOf(
Destination(
"route",
mutableListOf("listofDestination")
)
),
mutableListOf(
Destination(
"route",
mutableListOf("listOfDestination")
)
)
), isSelected = true,

onClick ={ isClicked = true
})



}

rule.onNode(hasText("BESTORG"), useUnmergedTree = true).assertIsDisplayed()

}

//Test working

@Test
fun OrgisClickable() {

var clicked= false

rule.setContent {
OrgItem(
Org(
id = "123",
name = "BESTORG",
walletId = "ABC",
logoPath = "PATH",
mutableListOf(
Destination(
"route",
mutableListOf("listofDestination")
)
),
mutableListOf(
Destination(
"route",
mutableListOf("listOfDestination")
)
)
), isSelected = true,

onClick ={ clicked = true
})
}

rule.onNode(hasTestTag("TreeTrackerButton")).performClick()
assertTrue(clicked)

}


//Test is not working
@Test
fun TopBarTest(){

rule.setContent {
OrgPickerScreen()
}
rule.onNode(hasText("SELECT ORGANIZATION")).assertIsDisplayed()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import org.greenstand.android.TreeTracker.R
Expand Down Expand Up @@ -96,7 +98,7 @@ fun OrgItem(org: Org, isSelected: Boolean, onClick: () -> Unit) {
isSelected = isSelected,
modifier = Modifier
.padding(16.dp)
.size(height = 80.dp, width = 156.dp)
.size(height = 80.dp, width = 156.dp).testTag("TreeTrackerButton")
) {
Text(
modifier = Modifier.align(Alignment.Center),
Expand Down