diff --git a/.github/workflows/runUiTests.yml b/.github/workflows/runUiTests.yml index 01a5af9..e9f305a 100644 --- a/.github/workflows/runUiTests.yml +++ b/.github/workflows/runUiTests.yml @@ -9,12 +9,11 @@ jobs: matrix: include: - os: ubuntu-latest - runIde: | + prepareUI: | export DISPLAY=:99.0 Xvfb -ac :99 -screen 0 1920x1080x24 & sleep 10 mkdir -p build/reports - ./gradlew :runIdeForUiTests > build/reports/idea.log & runTests: | export DISPLAY=:99.0 ./gradlew :test @@ -41,15 +40,8 @@ jobs: - name: Clean run: ./gradlew :clean - - name: Run Idea - run: ${{ matrix.runIde }} - - - name: Wait for Idea started - uses: jtalk/url-health-check-action@v3 - with: - url: ${{ matrix.url }} - max-attempts: 15 - retry-delay: 30s + - name: Prepare UI + run: ${{ matrix.prepareUI }} - name: Run tests run: ${{ matrix.runTests }} @@ -57,10 +49,12 @@ jobs: - name: Move video if: ${{ failure() }} run: mv video build/reports + - name: Wait for reports uses: jakejarvis/wait-action@master with: time: '10s' + - name: Save reports uses: actions/upload-artifact@v3 with: diff --git a/.idea/misc.xml b/.idea/misc.xml index 775445d..9f230de 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/main/kotlin/com/github/nizienko/propertiesSwitcher/PropertySwitcherService.kt b/src/main/kotlin/com/github/nizienko/propertiesSwitcher/PropertySwitcherService.kt index 62ca493..732d82f 100644 --- a/src/main/kotlin/com/github/nizienko/propertiesSwitcher/PropertySwitcherService.kt +++ b/src/main/kotlin/com/github/nizienko/propertiesSwitcher/PropertySwitcherService.kt @@ -23,7 +23,6 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent import com.intellij.openapi.wm.WindowManager import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager import java.io.InputStreamReader -import java.nio.charset.StandardCharsets import java.util.* import java.util.concurrent.CountDownLatch import kotlin.text.Regex.Companion.escapeReplacement diff --git a/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/ReloadPropertyTemplatesAction.kt b/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/ReloadPropertyTemplatesAction.kt index 5e5b858..c402d74 100644 --- a/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/ReloadPropertyTemplatesAction.kt +++ b/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/ReloadPropertyTemplatesAction.kt @@ -2,10 +2,7 @@ package com.github.nizienko.propertiesSwitcher.actions import com.github.nizienko.propertiesSwitcher.PropertySwitcherService import com.github.nizienko.propertiesSwitcher.fileType.PropertiesTemplateFileType -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.actionSystem.LangDataKeys +import com.intellij.openapi.actionSystem.* import com.intellij.openapi.components.service import com.intellij.openapi.fileEditor.FileDocumentManager @@ -20,6 +17,10 @@ internal class ReloadPropertyTemplatesAction : AnAction() { service.reload() } + override fun getActionUpdateThread(): ActionUpdateThread { + return ActionUpdateThread.BGT + } + override fun update(event: AnActionEvent) { val virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE) val presentation = event.presentation diff --git a/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/SwitchPropertiesAction.kt b/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/SwitchPropertiesAction.kt index 55a810b..4074285 100644 --- a/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/SwitchPropertiesAction.kt +++ b/src/main/kotlin/com/github/nizienko/propertiesSwitcher/actions/SwitchPropertiesAction.kt @@ -3,13 +3,13 @@ package com.github.nizienko.propertiesSwitcher.actions import com.github.nizienko.propertiesSwitcher.Prop import com.github.nizienko.propertiesSwitcher.SwitchablePropertyFile import com.github.nizienko.propertiesSwitcher.switcher +import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.openapi.ui.popup.PopupStep import com.intellij.openapi.ui.popup.util.BaseListPopupStep import com.intellij.vcs.commit.NonModalCommitPanel.Companion.showAbove -import java.awt.Component import javax.swing.JComponent internal class SwitchPropertiesAction : AnAction() { @@ -26,6 +26,10 @@ internal class SwitchPropertiesAction : AnAction() { } } + override fun getActionUpdateThread(): ActionUpdateThread { + return ActionUpdateThread.BGT + } + override fun update(e: AnActionEvent) { super.update(e) } diff --git a/src/test/kotlin/CreateSwitchPropertiesTest.kt b/src/test/kotlin/CreateSwitchPropertiesTest.kt index ddc7838..62726ed 100644 --- a/src/test/kotlin/CreateSwitchPropertiesTest.kt +++ b/src/test/kotlin/CreateSwitchPropertiesTest.kt @@ -5,18 +5,29 @@ import com.intellij.remoterobot.steps.CommonSteps import com.intellij.remoterobot.stepsProcessing.step import com.intellij.remoterobot.utils.keyboard import com.intellij.remoterobot.utils.waitFor +import com.intellij.remoterobot.utils.waitForIgnoringError import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test +import java.io.BufferedReader +import java.io.InputStreamReader import java.time.Duration +import kotlin.concurrent.thread class CreateSwitchPropertiesTest { companion object { private val robot = RemoteRobot("http://127.0.0.1:8082") private val steps = CommonSteps(robot) + @JvmStatic + @BeforeAll + fun beforeAll() { + robot.runIde() + } + @JvmStatic @AfterAll - fun afterAll(): Unit { + fun afterAll() { steps.invokeAction("Exit") robot.idea { find(byXpath("//div[@class='MyDialog']")) @@ -78,6 +89,16 @@ class CreateSwitchPropertiesTest { """.trimIndent() ) + step("Add third parameter") { + textEditor().editor.clickOnOffset(textEditor().editor.text.length) + keyboard { + backspace() + enterText(" # comment") + enter() + enterText("property_3=value_1") + enter() + } + } step("Switch properties") { widget().click() @@ -90,7 +111,8 @@ class CreateSwitchPropertiesTest { assert( textEditor().editor.text == """ property_1=value_1 - property_2=value_3 + property_2=value_3 # comment + property_3=value_1 """.trimIndent() ) @@ -106,7 +128,8 @@ class CreateSwitchPropertiesTest { assert( textEditor().editor.text == """ property_1=value_1 - property_2=value_2 + property_2=value_2 # comment + property_3=value_1 """.trimIndent() ) @@ -133,4 +156,19 @@ private fun ContainerFixture.popup(): ContainerFixture { } private fun CommonContainerFixture.widget(): ComponentFixture = - component(byXpath("//div[@class='IdeStatusBarImpl']//div[@class='TextPresentationComponent']")) \ No newline at end of file + component(byXpath("//div[@class='IdeStatusBarImpl']//div[@class='TextPresentationComponent']")) + +private fun RemoteRobot.runIde() { + thread { + val process = Runtime.getRuntime().exec("./gradlew :runIdeForUiTests") + val reader = BufferedReader(InputStreamReader(process.inputStream)) + var line: String? + while (reader.readLine().also { line = it } != null) { + println(line) + } + } + waitForIgnoringError(Duration.ofSeconds(120)) { + findAll(CommonContainerFixture::class.java, byXpath("//div[@class='FlatWelcomeFrame']")) + .size == 1 + } +} \ No newline at end of file