From ef9ebfa2c2535c7a2fd7067ed6826ee7abe680c0 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Wed, 3 Apr 2024 16:17:48 -0400 Subject: [PATCH] fix:tests --- .../ghmanager/data/WorkflowRunListLoader.kt | 7 +---- .../ui/panels/wfruns/WorkflowRunListPanel.kt | 27 +++++++------------ .../ghmanager/GitHubActionsManagerBaseTest.kt | 14 ++++++---- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt index 049e397..b7bcacb 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt @@ -43,7 +43,6 @@ class WorkflowRunListLoader( val repoBranches = ArrayList() val workflowTypes = ArrayList() private val progressManager = ProgressManager.getInstance() - private var lastFuture = CompletableFuture.completedFuture(emptyList()) private val loadingStateChangeEventDispatcher = EventDispatcher.create(SimpleEventListener::class.java) private val errorChangeEventDispatcher = EventDispatcher.create(SimpleEventListener::class.java) val url: String = GithubApi.getWorkflowRuns(repositoryCoordinates, filter).url @@ -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) { @@ -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() diff --git a/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/wfruns/WorkflowRunListPanel.kt b/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/wfruns/WorkflowRunListPanel.kt index b837d9a..56257d2 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/wfruns/WorkflowRunListPanel.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/wfruns/WorkflowRunListPanel.kt @@ -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) @@ -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() } @@ -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) { @@ -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() @@ -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() { diff --git a/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt b/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt index 1c0e1b3..f246069 100644 --- a/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt +++ b/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt @@ -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 @@ -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 @@ -75,8 +72,15 @@ abstract class GitHubActionsManagerBaseTest { val accounts = accountNames.map { GHAccountManager.createAccount(it, host) }.toSet() val repos: Set = repoUrls.map { mockk().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()