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

Added AboutFragment test cases #2587

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -72,7 +73,8 @@ class AboutFragment : AbstractFragment() {
Image(
bitmap = R.drawable.ground_logo.toImageBitmap(),
contentDescription = "Logo",
modifier = Modifier.padding(0.dp, 8.dp, 0.dp, 22.dp).width(122.dp).height(122.dp),
modifier =
Modifier.testTag("logo").padding(0.dp, 8.dp, 0.dp, 22.dp).width(122.dp).height(122.dp),
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
)

val uriHandler = LocalUriHandler.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open class BaseHiltTest {
/* Allows creating mocks using @Mock annotation. */
@get:Rule(order = 2) var rule: MockitoRule = MockitoJUnit.rule()

@get:Rule(order = 3) val composeTestRule = createComposeRule()
@get:Rule(order = 3) open val composeTestRule = createComposeRule()

@Inject lateinit var database: LocalDatabase
@Inject lateinit var testDispatcher: TestDispatcher
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.ground.ui.home

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import com.google.android.ground.BaseHiltTest
import com.google.android.ground.R
import com.google.android.ground.launchFragmentWithNavController
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
class AboutFragmentTest : BaseHiltTest() {
shobhitagarwal1612 marked this conversation as resolved.
Show resolved Hide resolved

private lateinit var fragment: AboutFragment

/**
* composeTestRule has to be created in the specific test file in order to access the required
* activity. [composeTestRule.activity]
*/
@get:Rule override val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@Before
override fun setUp() {
super.setUp()
launchFragmentWithNavController<AboutFragment>(destId = R.id.aboutFragment) {
fragment = this as AboutFragment
}
}

@Test
fun `Toolbar is displayed`() {
composeTestRule.onNodeWithText("About").assertIsDisplayed()
}

@Test
fun `Back Icon click closes the screen`() {
composeTestRule.onNodeWithTag("logo").assertIsDisplayed()

composeTestRule
.onNodeWithText(composeTestRule.activity.getString(R.string.about_ground))
.assertIsDisplayed()
}
}