Skip to content

Commit

Permalink
Add search screen test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexymumo committed Apr 1, 2024
1 parent 16fe9ee commit a3f851e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -70,7 +71,7 @@ fun SearchContent(
searchState: SearchState
) {
Column(
modifier = Modifier.fillMaxSize()
modifier = Modifier.fillMaxSize().testTag("search_screen_test_tag")
) {
CustomSearchBar(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -102,6 +103,7 @@ fun CustomSearchBar(
placeholder = { Text(text = "Search News..") },
modifier = modifier
.fillMaxWidth()
.testTag("search_text_tag")
.shadow(4.dp, CircleShape),
maxLines = 1,
trailingIcon = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 News-App
*
* 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
*
* http://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.alexmumo.presentation.search

import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.navigation.compose.rememberNavController
import com.alexmumo.domain.repository.SearchRepository
import io.mockk.mockk
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.shadows.ShadowLog

@RunWith(RobolectricTestRunner::class)
class SearchScreenTest {

@get:Rule
val composeRule = createComposeRule()

private val searchRepository = mockk<SearchRepository>(relaxed = true)
private val viewModel = SearchViewModel(searchRepository)

@Before
@Throws(Exception::class)
fun setUp() {
ShadowLog.stream = System.out
}

@Test
fun `test search screen`() {
composeRule.setContent {
SearchScreen(navController = rememberNavController(), viewModel = viewModel)
}
composeRule.onNodeWithTag("search_screen_test_tag")
composeRule.onNodeWithTag("search_text_tag")
}
}

0 comments on commit a3f851e

Please sign in to comment.