|
| 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.docTests.createReadmeTests |
| 5 | + |
| 6 | +import com.intellij.driver.sdk.waitForProjectOpen |
| 7 | +import com.intellij.ide.starter.ci.CIServer |
| 8 | +import com.intellij.ide.starter.config.ConfigurationStorage |
| 9 | +import com.intellij.ide.starter.di.di |
| 10 | +import com.intellij.ide.starter.driver.engine.runIdeWithDriver |
| 11 | +import com.intellij.ide.starter.ide.IdeProductProvider |
| 12 | +import com.intellij.ide.starter.junit5.hyphenateWithClass |
| 13 | +import com.intellij.ide.starter.models.TestCase |
| 14 | +import com.intellij.ide.starter.project.LocalProjectInfo |
| 15 | +import com.intellij.ide.starter.runner.CurrentTestMethod |
| 16 | +import com.intellij.ide.starter.runner.Starter |
| 17 | +import org.junit.jupiter.api.AfterAll |
| 18 | +import org.junit.jupiter.api.Assertions.assertFalse |
| 19 | +import org.junit.jupiter.api.Assertions.assertTrue |
| 20 | +import org.junit.jupiter.api.BeforeAll |
| 21 | +import org.junit.jupiter.api.BeforeEach |
| 22 | +import org.junit.jupiter.api.Test |
| 23 | +import org.kodein.di.DI |
| 24 | +import org.kodein.di.bindSingleton |
| 25 | +import software.aws.toolkits.jetbrains.uitests.TestCIServer |
| 26 | +import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile |
| 27 | +import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData |
| 28 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript |
| 29 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmePromptedToConfirmFolderTestScript |
| 30 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.makeChangesFlowTestScript |
| 31 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.rejectReadmeTestScript |
| 32 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.validateFeatureAvailabilityTestScript |
| 33 | +import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript |
| 34 | +import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment |
| 35 | +import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest |
| 36 | +import java.io.File |
| 37 | +import java.nio.file.Path |
| 38 | +import java.nio.file.Paths |
| 39 | + |
| 40 | +class CreateReadmeTest { |
| 41 | + init { |
| 42 | + di = DI { |
| 43 | + extend(di) |
| 44 | + bindSingleton<CIServer>(overrides = true) { TestCIServer } |
| 45 | + val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply { |
| 46 | + put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString()) |
| 47 | + } |
| 48 | + |
| 49 | + bindSingleton<ConfigurationStorage>(overrides = true) { |
| 50 | + ConfigurationStorage(this, defaults) |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @BeforeEach |
| 56 | + fun setUpTest() { |
| 57 | + // prep test data - remove readme if it exists |
| 58 | + prepTestData(true) |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + fun `Validate that the qdoc feature can be invoked`() { |
| 63 | + val testCase = TestCase( |
| 64 | + IdeProductProvider.IC, |
| 65 | + LocalProjectInfo( |
| 66 | + Paths.get("tstData", "qdoc", "createFlow") |
| 67 | + ) |
| 68 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 69 | + |
| 70 | + // inject connection |
| 71 | + useExistingConnectionForTest() |
| 72 | + |
| 73 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 74 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 75 | + pluginConfigurator.installPluginFromPath( |
| 76 | + Path.of(path) |
| 77 | + ) |
| 78 | + } |
| 79 | + |
| 80 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 81 | + updateGeneralSettings() |
| 82 | + }.runIdeWithDriver() |
| 83 | + .useDriverAndCloseIde { |
| 84 | + waitForProjectOpen() |
| 85 | + // required wait time for the system to be fully ready |
| 86 | + Thread.sleep(30000) |
| 87 | + |
| 88 | + val result = executePuppeteerScript(validateFeatureAvailabilityTestScript) |
| 89 | + assertTrue(result.contains("Test Successful")) |
| 90 | + assertFalse(result.contains("Error: Test Failed")) |
| 91 | + if (result.contains("Error: Test Failed")) { |
| 92 | + println("result: $result") |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + fun `You are prompted to confirm selected folder, change folder, or cancel back to choosing CREATE or UPDATE`() { |
| 99 | + val testCase = TestCase( |
| 100 | + IdeProductProvider.IC, |
| 101 | + LocalProjectInfo( |
| 102 | + Paths.get("tstData", "qdoc", "createFlow") |
| 103 | + ) |
| 104 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 105 | + |
| 106 | + // inject connection |
| 107 | + useExistingConnectionForTest() |
| 108 | + |
| 109 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 110 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 111 | + pluginConfigurator.installPluginFromPath( |
| 112 | + Path.of(path) |
| 113 | + ) |
| 114 | + } |
| 115 | + |
| 116 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 117 | + updateGeneralSettings() |
| 118 | + }.runIdeWithDriver() |
| 119 | + .useDriverAndCloseIde { |
| 120 | + waitForProjectOpen() |
| 121 | + // required wait time for the system to be fully ready |
| 122 | + Thread.sleep(30000) |
| 123 | + |
| 124 | + val result = executePuppeteerScript(createReadmePromptedToConfirmFolderTestScript) |
| 125 | + assertTrue(result.contains("Test Successful")) |
| 126 | + assertFalse(result.contains("Error: Test Failed")) |
| 127 | + if (result.contains("Error: Test Failed")) { |
| 128 | + println("result: $result") |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + fun `Make changes button brings you to UPDATE with specific changes flow`() { |
| 135 | + val testCase = TestCase( |
| 136 | + IdeProductProvider.IC, |
| 137 | + LocalProjectInfo( |
| 138 | + Paths.get("tstData", "qdoc", "createFlow") |
| 139 | + ) |
| 140 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 141 | + |
| 142 | + // inject connection |
| 143 | + useExistingConnectionForTest() |
| 144 | + |
| 145 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 146 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 147 | + pluginConfigurator.installPluginFromPath( |
| 148 | + Path.of(path) |
| 149 | + ) |
| 150 | + } |
| 151 | + |
| 152 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 153 | + updateGeneralSettings() |
| 154 | + }.runIdeWithDriver() |
| 155 | + .useDriverAndCloseIde { |
| 156 | + waitForProjectOpen() |
| 157 | + // required wait time for the system to be fully ready |
| 158 | + Thread.sleep(30000) |
| 159 | + |
| 160 | + val result = executePuppeteerScript(makeChangesFlowTestScript) |
| 161 | + assertTrue(result.contains("Test Successful")) |
| 162 | + assertFalse(result.contains("Error: Test Failed")) |
| 163 | + if (result.contains("Error: Test Failed")) { |
| 164 | + println("result: $result") |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + fun `Accept button saves the ReadMe in the appropriate folder`() { |
| 171 | + val testCase = TestCase( |
| 172 | + IdeProductProvider.IC, |
| 173 | + LocalProjectInfo( |
| 174 | + Paths.get("tstData", "qdoc", "createFlow") |
| 175 | + ) |
| 176 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 177 | + |
| 178 | + // inject connection |
| 179 | + useExistingConnectionForTest() |
| 180 | + |
| 181 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 182 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 183 | + pluginConfigurator.installPluginFromPath( |
| 184 | + Path.of(path) |
| 185 | + ) |
| 186 | + } |
| 187 | + |
| 188 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 189 | + updateGeneralSettings() |
| 190 | + }.runIdeWithDriver() |
| 191 | + .useDriverAndCloseIde { |
| 192 | + waitForProjectOpen() |
| 193 | + // required wait time for the system to be fully ready |
| 194 | + Thread.sleep(30000) |
| 195 | + |
| 196 | + val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") |
| 197 | + val readme = File(readmePath.toUri()) |
| 198 | + assertFalse(readme.exists()) |
| 199 | + |
| 200 | + val result = executePuppeteerScript(acceptReadmeTestScript) |
| 201 | + assertFalse(result.contains("Error: Test Failed")) |
| 202 | + if (result.contains("Error: Test Failed")) { |
| 203 | + println("result: $result") |
| 204 | + } |
| 205 | + |
| 206 | + val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") |
| 207 | + val newReadme = File(newReadmePath.toUri()) |
| 208 | + assertTrue(newReadme.exists()) |
| 209 | + assertTrue(newReadme.readText().contains("REST")) |
| 210 | + assertTrue(newReadme.readText().contains("API")) |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + @Test |
| 215 | + fun `Reject button discards the changes`() { |
| 216 | + val testCase = TestCase( |
| 217 | + IdeProductProvider.IC, |
| 218 | + LocalProjectInfo( |
| 219 | + Paths.get("tstData", "qdoc", "createFlow") |
| 220 | + ) |
| 221 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 222 | + |
| 223 | + // inject connection |
| 224 | + useExistingConnectionForTest() |
| 225 | + |
| 226 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 227 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 228 | + pluginConfigurator.installPluginFromPath( |
| 229 | + Path.of(path) |
| 230 | + ) |
| 231 | + } |
| 232 | + |
| 233 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 234 | + updateGeneralSettings() |
| 235 | + }.runIdeWithDriver() |
| 236 | + .useDriverAndCloseIde { |
| 237 | + waitForProjectOpen() |
| 238 | + // required wait time for the system to be fully ready |
| 239 | + Thread.sleep(30000) |
| 240 | + |
| 241 | + val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") |
| 242 | + val readme = File(readmePath.toUri()) |
| 243 | + assertFalse(readme.exists()) |
| 244 | + |
| 245 | + val result = executePuppeteerScript(rejectReadmeTestScript) |
| 246 | + assertTrue(result.contains("Test Successful")) |
| 247 | + assertFalse(result.contains("Error: Test Failed")) |
| 248 | + |
| 249 | + if (result.contains("Error: Test Failed")) { |
| 250 | + println("result: $result") |
| 251 | + } |
| 252 | + |
| 253 | + val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") |
| 254 | + val newReadme = File(newReadmePath.toUri()) |
| 255 | + assertFalse(newReadme.exists()) |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + companion object { |
| 260 | + @JvmStatic |
| 261 | + @AfterAll |
| 262 | + fun clearAwsXml() { |
| 263 | + clearAwsXmlFile() |
| 264 | + } |
| 265 | + |
| 266 | + @JvmStatic |
| 267 | + @BeforeAll |
| 268 | + fun setUp() { |
| 269 | + // Setup test environment |
| 270 | + setupTestEnvironment() |
| 271 | + } |
| 272 | + } |
| 273 | +} |
0 commit comments