|
| 1 | +// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package software.aws.toolkits.jetbrains.uitests.testTests |
| 5 | + |
| 6 | +import com.intellij.driver.sdk.openFile |
| 7 | +import com.intellij.driver.sdk.waitForProjectOpen |
| 8 | +import com.intellij.ide.starter.ci.CIServer |
| 9 | +import com.intellij.ide.starter.config.ConfigurationStorage |
| 10 | +import com.intellij.ide.starter.di.di |
| 11 | +import com.intellij.ide.starter.driver.engine.runIdeWithDriver |
| 12 | +import com.intellij.ide.starter.ide.IdeProductProvider |
| 13 | +import com.intellij.ide.starter.junit5.hyphenateWithClass |
| 14 | +import com.intellij.ide.starter.models.TestCase |
| 15 | +import com.intellij.ide.starter.project.LocalProjectInfo |
| 16 | +import com.intellij.ide.starter.runner.CurrentTestMethod |
| 17 | +import com.intellij.ide.starter.runner.Starter |
| 18 | +import org.junit.jupiter.api.AfterAll |
| 19 | +import org.junit.jupiter.api.Assertions.assertTrue |
| 20 | +import org.junit.jupiter.api.BeforeEach |
| 21 | +import org.junit.jupiter.api.Test |
| 22 | +import org.kodein.di.DI |
| 23 | +import org.kodein.di.bindSingleton |
| 24 | +import software.aws.toolkits.jetbrains.uitests.TestCIServer |
| 25 | +import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile |
| 26 | +import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript |
| 27 | +import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment |
| 28 | +import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest |
| 29 | +import java.io.File |
| 30 | +import java.nio.file.Path |
| 31 | +import java.nio.file.Paths |
| 32 | + |
| 33 | +class QTestGenerationChatTest { |
| 34 | + init { |
| 35 | + di = DI { |
| 36 | + extend(di) |
| 37 | + bindSingleton<CIServer>(overrides = true) { TestCIServer } |
| 38 | + val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply { |
| 39 | + put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString()) |
| 40 | + } |
| 41 | + |
| 42 | + bindSingleton<ConfigurationStorage>(overrides = true) { |
| 43 | + ConfigurationStorage(this, defaults) |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @BeforeEach |
| 49 | + fun setUp() { |
| 50 | + setupTestEnvironment() |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + fun `can run a test from the chat`() { |
| 55 | + val testCase = TestCase( |
| 56 | + IdeProductProvider.IC, |
| 57 | + LocalProjectInfo( |
| 58 | + Paths.get("tstData", "qTestGenerationTestProject") |
| 59 | + ) |
| 60 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 61 | + |
| 62 | + // inject connection |
| 63 | + useExistingConnectionForTest() |
| 64 | + |
| 65 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 66 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 67 | + pluginConfigurator.installPluginFromPath( |
| 68 | + Path.of(path) |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 73 | + updateGeneralSettings() |
| 74 | + }.runIdeWithDriver() |
| 75 | + .useDriverAndCloseIde { |
| 76 | + waitForProjectOpen() |
| 77 | + // required wait time for the system to be fully ready |
| 78 | + Thread.sleep(30000) |
| 79 | + val result = executePuppeteerScript(testNoFilePathScript) |
| 80 | + assertTrue(result.contains("new tab opened")) |
| 81 | + assertTrue(result.contains("a source file open right now that I can generate a test for")) |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + fun `test happy path from the chat`() { |
| 87 | + val testCase = TestCase( |
| 88 | + IdeProductProvider.IC, |
| 89 | + LocalProjectInfo( |
| 90 | + Paths.get("tstData", "qTestGenerationTestProject/") |
| 91 | + ) |
| 92 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 93 | + |
| 94 | + // inject connection |
| 95 | + useExistingConnectionForTest() |
| 96 | + |
| 97 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 98 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 99 | + pluginConfigurator.installPluginFromPath( |
| 100 | + Path.of(path) |
| 101 | + ) |
| 102 | + } |
| 103 | + |
| 104 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 105 | + updateGeneralSettings() |
| 106 | + }.runIdeWithDriver() |
| 107 | + .useDriverAndCloseIde { |
| 108 | + waitForProjectOpen() |
| 109 | + openFile(Paths.get("testModule1", "HappyPath.java").toString()) |
| 110 | + Thread.sleep(30000) |
| 111 | + val result = executePuppeteerScript(testHappyPathScript) |
| 112 | + assertTrue(result.contains("new tab opened")) |
| 113 | + assertTrue(result.contains("View Diff opened")) |
| 114 | + assertTrue(result.contains("Result Accepted")) |
| 115 | + assertTrue(result.contains("Unit test generation completed.")) |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + fun `test expected error path from the chat`() { |
| 121 | + val testCase = TestCase( |
| 122 | + IdeProductProvider.IC, |
| 123 | + LocalProjectInfo( |
| 124 | + Paths.get("tstData", "qTestGenerationTestProject/") |
| 125 | + ) |
| 126 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 127 | + |
| 128 | + // inject connection |
| 129 | + useExistingConnectionForTest() |
| 130 | + |
| 131 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 132 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 133 | + pluginConfigurator.installPluginFromPath( |
| 134 | + Path.of(path) |
| 135 | + ) |
| 136 | + } |
| 137 | + |
| 138 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 139 | + updateGeneralSettings() |
| 140 | + }.runIdeWithDriver() |
| 141 | + .useDriverAndCloseIde { |
| 142 | + waitForProjectOpen() |
| 143 | + openFile(Paths.get("testModule1", "ErrorPath.java").toString()) |
| 144 | + Thread.sleep(30000) |
| 145 | + val result = executePuppeteerScript(expectedErrorPath) |
| 146 | + assertTrue(result.contains("new tab opened")) |
| 147 | + assertTrue(result.contains("Test generation complete with expected error")) |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + fun `test unsupported language error path from the chat`() { |
| 153 | + val testCase = TestCase( |
| 154 | + IdeProductProvider.IC, |
| 155 | + LocalProjectInfo( |
| 156 | + Paths.get("tstData", "qTestGenerationTestProject/") |
| 157 | + ) |
| 158 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 159 | + |
| 160 | + // inject connection |
| 161 | + useExistingConnectionForTest() |
| 162 | + |
| 163 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 164 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 165 | + pluginConfigurator.installPluginFromPath( |
| 166 | + Path.of(path) |
| 167 | + ) |
| 168 | + } |
| 169 | + |
| 170 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 171 | + updateGeneralSettings() |
| 172 | + }.runIdeWithDriver() |
| 173 | + .useDriverAndCloseIde { |
| 174 | + waitForProjectOpen() |
| 175 | + openFile(Paths.get("testModule2", "UnSupportedLanguage.kt").toString()) |
| 176 | + Thread.sleep(30000) |
| 177 | + val result = executePuppeteerScript(unsupportedLanguagePath) |
| 178 | + assertTrue(result.contains("new tab opened")) |
| 179 | + assertTrue(result.contains("Test generation complete with expected error")) |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + companion object { |
| 184 | + @JvmStatic |
| 185 | + @AfterAll |
| 186 | + fun clearAwsXml() { |
| 187 | + clearAwsXmlFile() |
| 188 | + } |
| 189 | + } |
| 190 | +} |
0 commit comments