if there's a way to create or get an instance of CommitWorkflowHandler in the test code.
Hello,
I am currently developing a plugin that automatically generates commit messages using ChatGPT for the Changes checked in the commit tab.
During the implementation process, I've added a feature that displays a warning notification if the plugin's icon is clicked without any Changes being checked.
To create an integration test for this feature, I wanted to set up a DataContext in the test, referring to this post
However, I couldn't find a way to insert an instance of AbstractCommitWorkflowHandler into the DataContext.
Is there any way to use an actual implementation of VcsDataKeys.COMMIT_WORKFLOW_HANDLER in the DataContext?
I've already written all the unit tests, but I'd like to create test code that integrates with the actual commit workflow.
Thank you for your assistance.
here's my test code
class NotificationTest : BasePlatformTestCase() {
private lateinit var action: GenerateCommitMessageAction
private val notifiedMessages = mutableListOf<Triple<String, String, NotificationType>>()
override fun setUp() {
super.setUp()
action = GenerateCommitMessageAction()
project.messageBus.connect().subscribe(Notifications.TOPIC, object : Notifications {
override fun notify(notification: Notification) {
println("Notification received: ${notification.title}, ${notification.content}")
notifiedMessages.add(Triple(notification.title, notification.content, notification.type))
}
})
}
fun testNoChangesDetected() {
//how can i get instance of CommitWorkflowHandler?
val context = SimpleDataContext.getProjectContext(project)
val event = AnActionEvent.createFromAnAction(
action,
null,
ActionPlaces.VCS_HISTORY_TOOLBAR_PLACE,
context
)
WriteCommandAction.runWriteCommandAction(project) {
println("Action performed")
action.actionPerformed(event)
}
println("After action performed")
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
println("Captured notifications: ${notifiedMessages.size}")
assertTruenotifiedMessages.isNotEmpty())
notifiedMessages.forEach { (title, content, type) ->
println("Received notification: $title, $content, $type")
}
val (title, content, type) = notifiedMessages.last()
assertEquals("MessageMaker: No Changes Detected", title)
assertEquals("There are no changes to generate a commit message for.", content)
assertEquals(NotificationType.WARNING, type)
}
override fun tearDown() {
notifiedMessages.clear()
super.tearDown()
}
}
Please sign in to leave a comment.
Hi,
There are a couple of
CommitWorkflowHandler
implementations. I also don't understand your test scenario: what implementation is expected, how you use it (if you use it explicitly), in which place it is called, etc. Please clarify in more detail.Oh, I understand. Let me explain in detail. Here's my test scenario:
For these reasons, I'm curious about how to configure a DataContext containing AbstractCommitWorkflowHandler in the test environment.
thanks for help.
Hi,
The simplest approach would be to use a mock. Testing a “real” implementation is complex here, because, to get data from “real” implementation, a lot of UI classes would need to be initialized, which requires a lot of non-trivial code required for waiting for the UI to load.