Skip to content

Commit

Permalink
Merge branch 'private-release/v1.2.2-223' into public-release/v1.2.2-223
Browse files Browse the repository at this point in the history
Signed-off-by: Uladzislau <leksilonchikk@gmail.com>
  • Loading branch information
KUGDev committed Aug 21, 2024
2 parents 0a47c10 + 598d871 commit 6da0537
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ All notable changes to the Zowe IntelliJ Plugin will be documented in this file.
* Bugfix: java.lang.RuntimeException: Cannot invoke (class=, method=onCacheUpdated, topic=cacheUpdated) ([2fedc7f5](https://github.com/zowe/zowe-explorer-intellij/commit/2fedc7f5))
* Bugfix: "Allocate like" action causes exception when refresh on mask is started ([d13a1c72](https://github.com/zowe/zowe-explorer-intellij/commit/d13a1c72))

## [1.2.0-223] (2024-04-15)
## [1.2.0-223] (2024-04-16)

### Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ExplorerWindowFactory : ToolWindowFactory, DumbAware {
val content = contentFactory
.createContent(it.buildExplorerContent(toolWindow.disposable, project), it.displayName, it.isLockable)
toolWindow.contentManager.addContent(content)
}
}
}

override fun init(toolWindow: ToolWindow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,51 @@
package eu.ibagroup.formainframe.utils.ui

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.EDT
import com.intellij.openapi.project.ProjectManager
import com.intellij.ui.UiInterceptors
import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.shouldBe
import io.mockk.*
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkAll
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.awt.EventQueue
import javax.swing.Action
import javax.swing.JButton
import javax.swing.JPanel

class WindowsLikeMessageDialogTestSpec : WithApplicationShouldSpec({

afterSpec {
clearAllMocks()
}

context("Windows dialog common spec") {
val application = ApplicationManager.getApplication()
val project = ProjectManager.getInstance().defaultProject
mockkStatic(EventQueue::class)
mockkObject(application)
every { EventQueue.isDispatchThread() } returns true
every { application.isDispatchThread } returns true

val actions = arrayOf(
"Skip the conflicting file(s)",
"Replace the file(s) in the destination",
"Decide for each file"
)

val customDialog = WindowsLikeMessageDialog(
project,
null,
"The destination already has file(s) with\nthe same name.\n" +
"Please, select an action.",
"Please, select an action.",
"Name conflicts in 1 file(s)",
actions,
0,
Expand All @@ -56,38 +65,38 @@ class WindowsLikeMessageDialogTestSpec : WithApplicationShouldSpec({
false,
"helpId"
)

val classUnderTest = spyk(customDialog, "testDialog")

should("create right side empty actions of the dialog") {
val expected = mutableListOf<Action>().toTypedArray()
val methodToTest = classUnderTest::class.java.declaredMethods.single { it.name == "createActions" }
val result = methodToTest.invoke(classUnderTest)

assertSoftly {
result as Array<*> shouldBe expected
}
}

should("create left side actions of the dialog") {
val methodToTest = classUnderTest::class.java.declaredMethods.single { it.name == "createLeftSideActions" }
val result = methodToTest.invoke(classUnderTest) as Array<*>
val actionToPerform = (result[0] as Action)

// Call default action to be able to cover lambda expression
actionToPerform.actionPerformed(null)

assertSoftly {
// Plus help action, because helpId is not null
result.size shouldBe 4
}
}

should("create buttons panel of the dialog with 3 buttons") {
val methodToTest = classUnderTest::class.java.declaredMethods.single { it.name == "createButtonsPanel" }
val arguments = mutableListOf(JButton(actions[0]), JButton(actions[1]), JButton(actions[2]))
val result = methodToTest.invoke(classUnderTest, arguments) as JPanel

assertSoftly {
((result.getComponent(0) as JPanel).getComponent(0) as JButton).text shouldBe "Skip the conflicting file(s)"
((result.getComponent(1) as JPanel).getComponent(0) as JButton).text shouldBe "Replace the file(s) in the destination"
Expand All @@ -96,39 +105,43 @@ class WindowsLikeMessageDialogTestSpec : WithApplicationShouldSpec({
}
unmockkAll()
}

context("test showWindowsLikeMessageDialog static function") {
val project = ProjectManager.getInstance().defaultProject
mockkStatic(EventQueue::class)
every { EventQueue.isDispatchThread() } returns true

val actions = arrayOf(
"Skip the conflicting file(s)",
"Replace the file(s) in the destination",
"Decide for each file"
)

should("call showWindowsLikeMessageDialog") {
mockkStatic(UiInterceptors::class)
every { UiInterceptors.tryIntercept(any()) } returns true
val exitCode = WindowsLikeMessageDialog.showWindowsLikeMessageDialog(
project,
null,
"The destination already has file(s) with\nthe same name.\n" +
"Please, select an action.",
"Name conflicts in 1 file(s)",
actions,
0,
0,
null,
null,
false,
null
)
val exitCode = runBlocking {
withContext(Dispatchers.EDT) {
WindowsLikeMessageDialog.showWindowsLikeMessageDialog(
project,
null,
"The destination already has file(s) with\nthe same name.\n" +
"Please, select an action.",
"Name conflicts in 1 file(s)",
actions,
0,
0,
null,
null,
false,
null
)
}
}
assertSoftly {
exitCode shouldBe 1
}
}
unmockkAll()
}
})
})

0 comments on commit 6da0537

Please sign in to comment.