Skip to content

Commit

Permalink
fix:tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Apr 3, 2024
1 parent 5283684 commit ef9ebfa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class WorkflowRunListLoader(
val repoBranches = ArrayList<String>()
val workflowTypes = ArrayList<WorkflowType>()
private val progressManager = ProgressManager.getInstance()
private var lastFuture = CompletableFuture.completedFuture(emptyList<WorkflowRun>())
private val loadingStateChangeEventDispatcher = EventDispatcher.create(SimpleEventListener::class.java)
private val errorChangeEventDispatcher = EventDispatcher.create(SimpleEventListener::class.java)
val url: String = GithubApi.getWorkflowRuns(repositoryCoordinates, filter).url
Expand Down Expand Up @@ -93,8 +92,7 @@ class WorkflowRunListLoader(
}.applyIf(workflowTypes.isEmpty()) {
progressManager.submitIOTask(indicatorsProvider) { updateWorkflowTypes(it) }
}
lastFuture = progressManager.submitIOTask(indicatorsProvider) { doLoadMore(it, update) }
return lastFuture
return progressManager.submitIOTask(indicatorsProvider) { doLoadMore(it, update) }
}

private fun updateCollaborators(indicator: ProgressIndicator) {
Expand Down Expand Up @@ -168,9 +166,6 @@ class WorkflowRunListLoader(

fun reset() {
LOG.debug("Removing all from the list model")
lastFuture = lastFuture.handle { _, _ ->
listOf()
}
error = null
loading = false
workflowRunsListModel.removeAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class WorkflowRunsListPanel(
private val context: WorkflowRunSelectionContext,
) : BorderLayoutPanel(), Disposable {
private val scope = MainScope().also { Disposer.register(parentDisposable) { it.cancel() } }

private val workflowRunsLoader: WorkflowRunListLoader
get() = context.runsListLoader
@VisibleForTesting
val runListComponent: WorkflowRunsListComponent = WorkflowRunsListComponent(context.runsListModel).apply {
val runListComponent = WorkflowRunsListComponent(workflowRunsLoader.workflowRunsListModel).apply {
emptyText.clear()
installPopup(this)
ToolbarUtil.installSelectionHolder(this, context.runSelectionHolder)
Expand All @@ -63,8 +64,7 @@ class WorkflowRunsListPanel(
}
private val progressStripe: ProgressStripe
private val infoPanel = HtmlInfoPanel()
private val workflowRunsLoader: WorkflowRunListLoader
get() = context.runsListLoader


private val errorHandler = LoadingErrorHandler { workflowRunsLoader.reset() }

Expand All @@ -80,7 +80,7 @@ class WorkflowRunsListPanel(
val searchPanel = WfRunsFiltersFactory(searchVm).createWfRunsFiltersPanel(scope)
context.toolWindow.project.messageBus
.connect(this)
.subscribe(GitRepository.GIT_REPO_CHANGE, GitRepositoryChangeListener {repo->
.subscribe(GitRepository.GIT_REPO_CHANGE, GitRepositoryChangeListener { repo ->
val currentFilter = searchVm.searchState.value
val currentBranchName = repo.currentBranchName
if (currentFilter.currentBranchFilter && currentBranchName != currentFilter.branch) {
Expand All @@ -103,7 +103,11 @@ class WorkflowRunsListPanel(
}, this, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS
)
addToCenter(progressStripe)

workflowRunsLoader.workflowRunsListModel.addListDataListener(object : ListDataListener {
override fun intervalAdded(e: ListDataEvent) = updateInfoPanelAndEmptyText()
override fun contentsChanged(e: ListDataEvent) {}
override fun intervalRemoved(e: ListDataEvent) = updateInfoPanelAndEmptyText()
})
workflowRunsLoader.addLoadingStateChangeListener(this) {
setLoading(workflowRunsLoader.loading)
updateInfoPanelAndEmptyText()
Expand All @@ -118,17 +122,6 @@ class WorkflowRunsListPanel(
actionToolbar.targetComponent = this

add(actionToolbar.component, BorderLayout.WEST)

runListComponent.model.addListDataListener(object : ListDataListener {
override fun intervalAdded(e: ListDataEvent) {
if (e.type == ListDataEvent.INTERVAL_ADDED) updateInfoPanelAndEmptyText()
}

override fun contentsChanged(e: ListDataEvent) {}
override fun intervalRemoved(e: ListDataEvent) {
if (e.type == ListDataEvent.INTERVAL_REMOVED) updateInfoPanelAndEmptyText()
}
})
}

private fun updateInfoPanelAndEmptyText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.TestApplicationManager
import com.intellij.testFramework.common.initTestApplication
import com.intellij.testFramework.junit5.RunInEdt
import com.intellij.testFramework.junit5.TestApplication
import com.intellij.testFramework.registerServiceInstance
import com.intellij.testFramework.rules.ProjectModelExtension
import com.intellij.testFramework.waitUntil
import com.intellij.toolWindow.ToolWindowHeadlessManagerImpl
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.util.ui.UIUtil
Expand All @@ -26,7 +24,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
import org.jetbrains.plugins.github.api.GithubServerPath
import org.jetbrains.plugins.github.authentication.accounts.GHAccountManager
Expand Down Expand Up @@ -75,8 +72,15 @@ abstract class GitHubActionsManagerBaseTest {
val accounts = accountNames.map { GHAccountManager.createAccount(it, host) }.toSet()
val repos: Set<GHGitRepositoryMapping> = repoUrls.map {
mockk<GHGitRepositoryMapping>().apply {
every { remote.url } returns it
every { repository.serverPath } returns host
every { remote } returns mockk {
every { url } returns it
}
every { repository } returns mockk {
every { serverPath } returns host
}
every { gitRepository } returns mockk {
every { currentBranchName } returns "main"
}
every { repositoryPath } returns it.replace("http://github.com/", "")
}
}.toSet()
Expand Down

0 comments on commit ef9ebfa

Please sign in to comment.