Skip to content

Commit

Permalink
IJMP-1378: disable actions if connection is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzianis Lisiankou committed Jan 31, 2024
1 parent e4d267a commit 3df02fd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ package eu.ibagroup.formainframe.explorer.actions
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.util.IconUtil
import eu.ibagroup.formainframe.explorer.ui.DSMaskNode
import eu.ibagroup.formainframe.explorer.ui.FileExplorerView
import eu.ibagroup.formainframe.explorer.ui.FileLikeDatasetNode
import eu.ibagroup.formainframe.explorer.ui.FilesWorkingSetNode
import eu.ibagroup.formainframe.explorer.ui.LibraryNode
import eu.ibagroup.formainframe.explorer.ui.getExplorerView
import eu.ibagroup.formainframe.explorer.ui.*
import eu.ibagroup.formainframe.utils.castOrNull

/**
* Class that represents dataset allocation action with parameters, defined by a user
Expand All @@ -40,18 +36,20 @@ class AllocateDatasetAction : AllocateActionBase() {
* 2. The first selected node is [FilesWorkingSetNode], [DSMaskNode], [LibraryNode] or [FileLikeDatasetNode]
*/
override fun update(e: AnActionEvent) {
e.presentation.icon = IconUtil.addText(AllIcons.FileTypes.Any_type, "DS")

val view = e.getExplorerView<FileExplorerView>() ?: let {
e.presentation.isEnabledAndVisible = false
return
}
val selectedNodesData = view.mySelectedNodesData
val node = selectedNodesData.getOrNull(0)?.node
if (node !is FilesWorkingSetNode && node !is DSMaskNode && node !is LibraryNode && node !is FileLikeDatasetNode) {
e.presentation.isEnabledAndVisible = false
return
e.presentation.isEnabledAndVisible =
node is FilesWorkingSetNode || node is DSMaskNode || node is LibraryNode || node is FileLikeDatasetNode

if (node.castOrNull<ExplorerUnitTreeNodeBase<*, *, *>>()?.unit?.connectionConfig == null) {
e.presentation.isEnabled = false
}
e.presentation.isEnabledAndVisible = true
e.presentation.icon = IconUtil.addText(AllIcons.FileTypes.Any_type, "DS")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ abstract class CreateUssEntityAction : AnAction() {
e.presentation.isEnabledAndVisible = false
return
}
val selected = view.mySelectedNodesData
e.presentation.isEnabledAndVisible =
selected.size == 1 && (selected[0].node is UssDirNode || selected[0].node is UssFileNode)
val selectedNodes = view.mySelectedNodesData
val node = selectedNodes.getOrNull(0)?.node
e.presentation.isEnabledAndVisible = node is UssDirNode || node is UssFileNode

if (node.castOrNull<ExplorerUnitTreeNodeBase<*, *, *>>()?.unit?.connectionConfig == null) {
e.presentation.isEnabled = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@ import eu.ibagroup.formainframe.dataops.Operation
import eu.ibagroup.formainframe.dataops.operations.DatasetAllocationParams
import eu.ibagroup.formainframe.explorer.Explorer
import eu.ibagroup.formainframe.explorer.FilesWorkingSet
import eu.ibagroup.formainframe.explorer.ui.DSMaskNode
import eu.ibagroup.formainframe.explorer.ui.ExplorerTreeNode
import eu.ibagroup.formainframe.explorer.ui.ExplorerTreeView
import eu.ibagroup.formainframe.explorer.ui.FileExplorerView
import eu.ibagroup.formainframe.explorer.ui.FileLikeDatasetNode
import eu.ibagroup.formainframe.explorer.ui.FilesWorkingSetNode
import eu.ibagroup.formainframe.explorer.ui.JobNode
import eu.ibagroup.formainframe.explorer.ui.LibraryNode
import eu.ibagroup.formainframe.explorer.ui.NodeData
import eu.ibagroup.formainframe.explorer.ui.getExplorerView
import eu.ibagroup.formainframe.explorer.ui.*
import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec
import eu.ibagroup.formainframe.testutils.testServiceImpl.TestAnalyticsServiceImpl
import eu.ibagroup.formainframe.utils.service
Expand Down Expand Up @@ -733,13 +724,19 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({
context("update") {
val presentationMock = mockk<Presentation>()
var isPresentationEnabledAndVisible = false
var isPresentationEnabled = false

beforeEach {
every {
presentationMock.isEnabledAndVisible = any<Boolean>()
} answers {
isPresentationEnabledAndVisible = firstArg<Boolean>()
}
every {
presentationMock.isEnabled = any<Boolean>()
} answers {
isPresentationEnabled = firstArg<Boolean>()
}
every { presentationMock.icon = any<Icon>() } just Runs
every { anActionEventMock.presentation } returns presentationMock
}
Expand All @@ -755,6 +752,7 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({

every { viewMock.mySelectedNodesData } returns selectedNodesData
every { anActionEventMock.getExplorerView<FileExplorerView>() } returns viewMock
every { nodeMock.unit.connectionConfig } returns mockk()

allocateDsActionInst.update(anActionEventMock)

Expand All @@ -767,6 +765,7 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({

every { viewMock.mySelectedNodesData } returns selectedNodesData
every { anActionEventMock.getExplorerView<FileExplorerView>() } returns viewMock
every { nodeMock.unit.connectionConfig } returns mockk()

allocateDsActionInst.update(anActionEventMock)

Expand All @@ -779,6 +778,7 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({

every { viewMock.mySelectedNodesData } returns selectedNodesData
every { anActionEventMock.getExplorerView<FileExplorerView>() } returns viewMock
every { nodeMock.unit.connectionConfig } returns mockk()

allocateDsActionInst.update(anActionEventMock)

Expand All @@ -791,6 +791,7 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({

every { viewMock.mySelectedNodesData } returns selectedNodesData
every { anActionEventMock.getExplorerView<FileExplorerView>() } returns viewMock
every { nodeMock.unit.connectionConfig } returns mockk()

allocateDsActionInst.update(anActionEventMock)

Expand All @@ -803,6 +804,7 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({

every { viewMock.mySelectedNodesData } returns selectedNodesData
every { anActionEventMock.getExplorerView<FileExplorerView>() } returns viewMock
every { nodeMock.unit.connectionConfig } returns mockk()

allocateDsActionInst.update(anActionEventMock)

Expand All @@ -816,7 +818,10 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({

allocateDsActionInst.update(anActionEventMock)

assertSoftly { isPresentationEnabledAndVisible shouldBe false }
assertSoftly {
isPresentationEnabledAndVisible shouldBe false
isPresentationEnabled shouldBe false
}
}
should("not show the action on update function is triggered outside the file explorer view") {
every { anActionEventMock.getExplorerView<FileExplorerView>() } returns null
Expand All @@ -825,6 +830,19 @@ class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({

assertSoftly { isPresentationEnabledAndVisible shouldBe false }
}
should("not enable the action on update function is triggered without connection config") {
val nodeMock = mockk<FilesWorkingSetNode>()
val nodeDataMock = NodeData(nodeMock, null, null)
val selectedNodesData = listOf(nodeDataMock)

every { viewMock.mySelectedNodesData } returns selectedNodesData
every { anActionEventMock.getExplorerView<FileExplorerView>() } returns viewMock
every { nodeMock.unit.connectionConfig } returns null

allocateDsActionInst.update(anActionEventMock)

assertSoftly { isPresentationEnabled shouldBe false }
}
}
}
})

0 comments on commit 3df02fd

Please sign in to comment.