diff --git a/src/test/kotlin/com/dsoftware/ghmanager/psi/OutdatedVersionAnnotatorTest.kt b/src/test/kotlin/com/dsoftware/ghmanager/psi/OutdatedVersionAnnotatorTest.kt index 8e67ab8..f389eec 100644 --- a/src/test/kotlin/com/dsoftware/ghmanager/psi/OutdatedVersionAnnotatorTest.kt +++ b/src/test/kotlin/com/dsoftware/ghmanager/psi/OutdatedVersionAnnotatorTest.kt @@ -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 @@ -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.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.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() + ) + } + } + } \ No newline at end of file