Skip to content

Commit

Permalink
fix:quickfix test
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Apr 27, 2024
1 parent 112da54 commit 6b876f7
Showing 1 changed file with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import com.dsoftware.ghmanager.i18n.MessagesBundle.message
import com.dsoftware.ghmanager.toolwindow.executeSomeCoroutineTasksAndDispatchAllInvocationEvents
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInsight.navigation.activateFileWithPsiElement
import com.intellij.openapi.application.runWriteActionAndWait
import com.intellij.codeInspection.ex.QuickFixWrapper
import com.intellij.designer.model.QuickFix
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.components.service
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.testFramework.runInEdtAndWait
import com.intellij.testFramework.utils.vfs.getPsiFile
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down Expand Up @@ -94,42 +96,42 @@ class OutdatedVersionAnnotatorTest {
)
}
}
//
// @Test
// fun testQuickFix() {
// var actionLoaded = false
// val fixture = createTestFixture("testAnnotate")
// val psiFile = fixture.configureByText(".github/workflows/workflow1.yaml", ACTION_TEXT)
// val gitHubActionDataService = fixture.project.service<GitHubActionDataService>()
// gitHubActionDataService.requestExecutor = executorMock
// gitHubActionDataService.actionsToResolve.add("actions/checkout")
// gitHubActionDataService.whenActionsLoaded { actionLoaded = true }
// var action: IntentionAction? = null
// runInEdtAndWait {
// while (!actionLoaded) {
// executeSomeCoroutineTasksAndDispatchAllInvocationEvents(fixture.project)
// }
// fixture.doHighlighting()
// executeSomeCoroutineTasksAndDispatchAllInvocationEvents(fixture.project)
// val quickFixes = fixture.getAllQuickFixes(psiFile.name)
// Assertions.assertEquals(1, quickFixes.size)
// action = quickFixes.first()
// }
//
// action!!.invoke(fixture.project, fixture.editor, fixture.actionContext.file)
// fixture.checkResult(
// ".github/workflows/workflow1.yaml",
// """
// jobs:
// build:
// name: Build
// runs-on: ubuntu-latest
// steps:
// - name: Fetch Sources
// uses: actions/checkout@v4
// """.trimIndent(),
// false
// )
// }
//

@Test
fun testQuickFix() {
var actionLoaded = false
val fixture = createTestFixture("testQuickFix")
val psiFile = fixture.configureByText(".github/workflows/workflow1.yaml", ACTION_TEXT)
val virtualFile = fixture.tempDirFixture.createFile(".github/workflows/workflow1.yaml", ACTION_TEXT)
val gitHubActionDataService = fixture.project.service<GitHubActionDataService>()
gitHubActionDataService.requestExecutor = executorMock
gitHubActionDataService.actionsToResolve.add("actions/checkout")
gitHubActionDataService.whenActionsLoaded { actionLoaded = true }
var action: IntentionAction? = null
runInEdtAndWait {
while (!actionLoaded) {
executeSomeCoroutineTasksAndDispatchAllInvocationEvents(fixture.project)
}
fixture.doHighlighting()
executeSomeCoroutineTasksAndDispatchAllInvocationEvents(fixture.project)
val quickFixes = fixture.getAllQuickFixes(psiFile.name)
Assertions.assertEquals(1, quickFixes.size)
val quickFix = quickFixes.first() as QuickFixWrapper
WriteCommandAction.runWriteCommandAction(fixture.project) {
quickFix.invoke(fixture.project, fixture.editor, fixture.file)
}
Assertions.assertEquals(quickFix.file?.text,
"""
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Fetch Sources
uses: actions/checkout@v4
""".trimIndent()
)
}
}

}

0 comments on commit 6b876f7

Please sign in to comment.