-
Notifications
You must be signed in to change notification settings - Fork 1
Update QuickFixFinder UI and Refactor Filters for Reusability #228
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
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
677f084
Refactor: extract filtering component
Autek 2687c15
Fix/Feat: UI fix and added filtering tabs to SearchOnBoarding.kt
Autek 7fa722a
Merge remote-tracking branch 'origin' into feature/quickFixFinder-scr…
Autek 897ce03
Feat: all the UI implemented in the QuickFixFinder.kt screen
Autek 2272ac7
Style: package directives updated in search package and cleanup
Autek 0c57667
Fix: adapt tests to work with refactored SearchWorkerResult.kt
Autek 88546c7
Merge remote-tracking branch 'origin' into feature/quickFixFinder-scr…
Autek f437f78
Fix: update of tests to match refactoring of SearchWorkerResult.kt
Autek ab48b64
Test: add tests to reach 80% coverage
Autek 42e7825
Merge remote-tracking branch 'origin' into feature/quickFixFinder-scr…
Autek de5971d
Style: cleanup
Autek 513da1f
Test: add tests for coverage
Autek 9ac23d0
Merge remote-tracking branch 'origin' into feature/quickFixFinder-scr…
Autek 761f367
Merge: merge finished and tests compiling
Autek 1c03423
Fix: update tests for two files.
Autek 5e5ba70
Fix: all tests fixed and passing
Autek 4d07d58
Fix: most tests passing
Autek 27cbb35
Fix: all tests passing
Autek f6471d9
Merge remote-tracking branch 'origin' into feature/quickFixFinder-scr…
Autek f6ff04a
Fix: implemented requested changes in PR review
Autek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
136 changes: 52 additions & 84 deletions
136
app/src/androidTest/java/com/arygm/quickfix/ui/search/ProfileResultsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,148 +1,116 @@ | ||
| package com.arygm.quickfix.ui.search | ||
|
|
||
| import android.graphics.Bitmap | ||
| import androidx.compose.foundation.lazy.rememberLazyListState | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.unit.dp | ||
| import com.arygm.quickfix.model.account.Account | ||
| import com.arygm.quickfix.model.account.AccountRepositoryFirestore | ||
| import com.arygm.quickfix.model.account.AccountViewModel | ||
| import com.arygm.quickfix.model.category.CategoryRepositoryFirestore | ||
| import com.arygm.quickfix.model.category.CategoryViewModel | ||
| import com.arygm.quickfix.model.profile.ProfileRepository | ||
| import com.arygm.quickfix.model.profile.ProfileViewModel | ||
| import com.arygm.quickfix.model.locations.Location | ||
| import com.arygm.quickfix.model.profile.WorkerProfile | ||
| import com.arygm.quickfix.model.profile.WorkerProfileRepositoryFirestore | ||
| import com.arygm.quickfix.model.search.SearchViewModel | ||
| import com.arygm.quickfix.ui.navigation.NavigationActions | ||
| import com.arygm.quickfix.ui.uiMode.appContentUI.userModeUI.search.ProfileResults | ||
| import com.google.firebase.Timestamp | ||
| import io.mockk.every | ||
| import io.mockk.invoke | ||
| import io.mockk.mockk | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.mockito.Mockito.mock | ||
|
|
||
| class ProfileResultsTest { | ||
|
|
||
| private lateinit var navigationActions: NavigationActions | ||
| private lateinit var workerProfileRepo: WorkerProfileRepositoryFirestore | ||
| private lateinit var accountRepositoryFirestore: AccountRepositoryFirestore | ||
| private lateinit var categoryRepo: CategoryRepositoryFirestore | ||
| private lateinit var searchViewModel: SearchViewModel | ||
| private lateinit var accountViewModel: AccountViewModel | ||
| private lateinit var categoryViewModel: CategoryViewModel | ||
| private lateinit var navigationActionsRoot: NavigationActions | ||
| private lateinit var workerRepository: ProfileRepository | ||
| private lateinit var workerViewModel: ProfileViewModel | ||
|
|
||
| @get:Rule val composeTestRule = createComposeRule() | ||
|
|
||
| private lateinit var accountViewModel: AccountViewModel | ||
| private lateinit var searchViewModel: SearchViewModel | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| navigationActions = mock(NavigationActions::class.java) | ||
| navigationActionsRoot = mock(NavigationActions::class.java) | ||
| workerProfileRepo = mockk(relaxed = true) | ||
| categoryRepo = mockk(relaxed = true) | ||
| accountRepositoryFirestore = mock(AccountRepositoryFirestore::class.java) | ||
| searchViewModel = SearchViewModel(workerProfileRepo) | ||
| categoryViewModel = CategoryViewModel(categoryRepo) | ||
| accountViewModel = mockk(relaxed = true) | ||
| searchViewModel = mockk(relaxed = true) | ||
|
|
||
| workerViewModel = mockk(relaxed = true) | ||
|
|
||
| // Mock fetchProfileImageAsBitmap | ||
| every { workerViewModel.fetchProfileImageAsBitmap(any(), any(), any()) } answers | ||
| { | ||
| val onSuccess = arg<(Bitmap) -> Unit>(1) | ||
| // Provide a dummy bitmap here (e.g. a solid color bitmap or decode from resources) | ||
| val dummyBitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888) | ||
| onSuccess(dummyBitmap) // Simulate success callback | ||
| } | ||
|
|
||
| // Mock fetchBannerImageAsBitmap | ||
| every { workerViewModel.fetchBannerImageAsBitmap(any(), any(), any()) } answers | ||
| { | ||
| val onSuccess = arg<(Bitmap) -> Unit>(1) | ||
| // Provide another dummy bitmap | ||
| val dummyBitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_8888) | ||
| onSuccess(dummyBitmap) // Simulate success callback | ||
| } | ||
| } | ||
| // Mock calculateDistance to return a fixed distance | ||
| every { searchViewModel.calculateDistance(any(), any(), any(), any()) } returns 10.0 | ||
|
|
||
| @Test | ||
| fun profileContent_displaysWorkerProfiles() { | ||
| // Set up test data | ||
| val testProfiles = | ||
| listOf( | ||
| WorkerProfile( | ||
| uid = "worker0", | ||
| fieldOfWork = "Plumbing", | ||
| rating = 3.5, | ||
| reviews = ArrayDeque(), | ||
| location = null, // Simplify for the test | ||
| price = 49.0, | ||
| ), | ||
| WorkerProfile( | ||
| uid = "worker1", | ||
| fieldOfWork = "Electrical", | ||
| rating = 3.0, | ||
| reviews = ArrayDeque(), | ||
| location = null, | ||
| price = 59.0, | ||
| )) | ||
|
|
||
| // Mock the AccountViewModel to return sample account data | ||
| // Mock AccountViewModel fetchUserAccount | ||
| every { accountViewModel.fetchUserAccount(any(), captureLambda()) } answers | ||
| { | ||
| val uid = firstArg<String>() | ||
| val account = | ||
| val lambda = secondArg<(Account?) -> Unit>() | ||
| lambda( | ||
| when (uid) { | ||
| "worker0" -> | ||
| Account( | ||
| uid = "worker0", | ||
| firstName = "John", | ||
| lastName = "Doe", | ||
| email = "", | ||
| Timestamp.now()) | ||
| birthDate = Timestamp.now()) | ||
| "worker1" -> | ||
| Account( | ||
| uid = "worker1", | ||
| firstName = "Jane", | ||
| lastName = "Smith", | ||
| email = "", | ||
| Timestamp.now()) | ||
| birthDate = Timestamp.now()) | ||
| else -> null | ||
| } | ||
| lambda<(Account?) -> Unit>().invoke(account) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun profileResults_displaysWorkerProfiles_correctly() { | ||
| // Test data: profiles, images, and location | ||
| val testProfiles = | ||
| listOf( | ||
| WorkerProfile( | ||
| uid = "worker0", | ||
| displayName = "John Doe", | ||
| fieldOfWork = "Plumbing", | ||
| reviews = ArrayDeque(listOf()), | ||
| location = Location(40.0, 70.0), | ||
| price = 49.0), | ||
| WorkerProfile( | ||
| uid = "worker1", | ||
| displayName = "Jane Smith", | ||
| fieldOfWork = "Electrical", | ||
| reviews = ArrayDeque(listOf()), | ||
| location = Location(41.0, 71.0), | ||
| price = 59.0)) | ||
|
|
||
| val dummyBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888) | ||
| val profileImagesMap = mapOf("worker0" to dummyBitmap, "worker1" to dummyBitmap) | ||
| val bannerImagesMap = mapOf("worker0" to dummyBitmap, "worker1" to dummyBitmap) | ||
| val baseLocation = Location(0.0, 0.0) | ||
|
|
||
| // Set the content with ProfileContent composable | ||
| // Set the ProfileResults composable | ||
| composeTestRule.setContent { | ||
| ProfileResults( | ||
| profiles = testProfiles, | ||
| listState = rememberLazyListState(), | ||
| searchViewModel = searchViewModel, | ||
| accountViewModel = accountViewModel, | ||
| heightRatio = 1.0f, | ||
| workerViewModel = workerViewModel, | ||
| onBookClick = { _, _ -> }) | ||
| onBookClick = { _, _, _, _ -> }, | ||
| profileImagesMap = profileImagesMap, | ||
| bannerImagesMap = bannerImagesMap, | ||
| baseLocation = baseLocation, | ||
| screenHeight = 1000.dp) | ||
| } | ||
|
|
||
| // Allow coroutines to complete | ||
| composeTestRule.waitForIdle() | ||
|
|
||
| // Verify that the profile items are displayed correctly | ||
| composeTestRule.onNodeWithTag("worker_profile_result_0").assertIsDisplayed() | ||
| // Verify first profile | ||
| composeTestRule.onNodeWithTag("worker_profile_result0").assertIsDisplayed() | ||
| composeTestRule.onNodeWithText("John Doe").assertIsDisplayed() | ||
| composeTestRule.onNodeWithText("Plumbing").assertIsDisplayed() | ||
| composeTestRule.onNodeWithText("49.0").assertIsDisplayed() | ||
|
|
||
| composeTestRule.onNodeWithTag("worker_profile_result_1").assertIsDisplayed() | ||
| // Verify second profile | ||
| composeTestRule.onNodeWithTag("worker_profile_result1").assertIsDisplayed() | ||
| composeTestRule.onNodeWithText("Jane Smith").assertIsDisplayed() | ||
| composeTestRule.onNodeWithText("Electrical").assertIsDisplayed() | ||
| composeTestRule.onNodeWithText("59.0").assertIsDisplayed() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this test removed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test was not removed but updated to match the update of the
ProfileResultscomposable. It was replaced by a new test that is testing exactly the same thing