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

Complete test in OfflineAreSelectorFragmentTest #3032

Open
github-actions bot opened this issue Feb 4, 2025 · 0 comments
Open

Complete test in OfflineAreSelectorFragmentTest #3032

github-actions bot opened this issue Feb 4, 2025 · 0 comments
Assignees
Labels
type: code health Improvements to readability or robustness of codebase

Comments

@github-actions
Copy link

github-actions bot commented Feb 4, 2025

// TODO: Complete below test
// Issue URL: https://github.com/google/ground-android/issues/3032


        matches(hasDescendant(withText(fragment.getString(R.string.offline_area_selector_title))))
      )
  }

  // TODO: Complete below test
  // Issue URL: https://github.com/google/ground-android/issues/3032
  @Test
  fun `stopDownloading cancels active download and updates UI state`() = runWithTestDispatcher {
    composeTestRule.setContent { DownloadProgressDialog(viewModel.downloadProgress.value!!, {}) }

    val progressFlow = MutableSharedFlow<Pair<Int, Int>>()
    whenever(offlineAreaRepository.downloadTiles(any())).thenReturn(progressFlow)

    val downloadProgressValues = mutableListOf<Float>()
    val observer = Observer<Float> { downloadProgressValues.add(it) }

    viewModel.downloadProgress.observeForever(observer)

    viewModel.onDownloadClick()
    advanceUntilIdle()

    progressFlow.emit(Pair(50, 100))
    advanceUntilIdle()

    composeTestRule
      .onNodeWithText(composeTestRule.activity.getString(R.string.cancel))
      .isDisplayed()

    composeTestRule
      .onNodeWithText(composeTestRule.activity.getString(R.string.cancel))
      .performClick()
    progressFlow.emit(Pair(75, 100))

    composeTestRule
      .onNodeWithText(composeTestRule.activity.getString(R.string.cancel))
      .isNotDisplayed()

    assertFalse(viewModel.isDownloadProgressVisible.value!!)
    assertNull(viewModel.downloadJob)

    viewModel.downloadProgress.removeObserver(observer)
  }
}

@gino-m gino-m changed the title Complete below test Complete test in OfflineAreSelectorFragmentTest Feb 5, 2025
@gino-m gino-m added the type: code health Improvements to readability or robustness of codebase label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code health Improvements to readability or robustness of codebase
Projects
Status: No status
Development

No branches or pull requests

2 participants