|
| 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.ui.ui |
| 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.assertj.core.api.Assertions.assertThat |
| 19 | +import org.junit.jupiter.api.AfterAll |
| 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.createReadmeSubFolderPostFolderChangeTestScript |
| 30 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPreFolderChangeTestScript |
| 31 | +import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript |
| 32 | +import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment |
| 33 | +import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest |
| 34 | +import java.awt.event.KeyEvent |
| 35 | +import java.io.File |
| 36 | +import java.nio.file.Path |
| 37 | +import java.nio.file.Paths |
| 38 | + |
| 39 | +class CreateReadmeWorkspacesTest { |
| 40 | + init { |
| 41 | + di = DI { |
| 42 | + extend(di) |
| 43 | + bindSingleton<CIServer>(overrides = true) { TestCIServer } |
| 44 | + val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply { |
| 45 | + put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString()) |
| 46 | + } |
| 47 | + |
| 48 | + bindSingleton<ConfigurationStorage>(overrides = true) { |
| 49 | + ConfigurationStorage(this, defaults) |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @BeforeEach |
| 55 | + fun setUpTest() { |
| 56 | + // prep test data - remove readme if it exists |
| 57 | + prepTestData(true) |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + fun `Create readme with single-root workspace, root folder returns a readme`() { |
| 62 | + val testCase = TestCase( |
| 63 | + IdeProductProvider.IC, |
| 64 | + LocalProjectInfo( |
| 65 | + Paths.get("tstData", "qdoc", "createFlow") |
| 66 | + ) |
| 67 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 68 | + |
| 69 | + // inject connection |
| 70 | + useExistingConnectionForTest() |
| 71 | + |
| 72 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 73 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 74 | + pluginConfigurator.installPluginFromPath( |
| 75 | + Path.of(path) |
| 76 | + ) |
| 77 | + } |
| 78 | + |
| 79 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 80 | + updateGeneralSettings() |
| 81 | + }.runIdeWithDriver() |
| 82 | + .useDriverAndCloseIde { |
| 83 | + waitForProjectOpen() |
| 84 | + // required wait time for the system to be fully ready |
| 85 | + Thread.sleep(30000) |
| 86 | + |
| 87 | + val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") |
| 88 | + val readme = File(readmePath.toUri()) |
| 89 | + assertThat(readme).doesNotExist() |
| 90 | + |
| 91 | + val result = executePuppeteerScript(acceptReadmeTestScript) |
| 92 | + assertThat(result) |
| 93 | + .doesNotContain("Error: Test Failed") |
| 94 | + |
| 95 | + val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") |
| 96 | + val newReadme = File(newReadmePath.toUri()) |
| 97 | + assertThat(newReadme) |
| 98 | + .exists() |
| 99 | + .content() |
| 100 | + .contains("REST", "API") |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + fun `Create readme with single-root workspace, in a subfolder returns a readme`() { |
| 106 | + val testCase = TestCase( |
| 107 | + IdeProductProvider.IC, |
| 108 | + LocalProjectInfo( |
| 109 | + Paths.get("tstData", "qdoc", "createFlow") |
| 110 | + ) |
| 111 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 112 | + |
| 113 | + // inject connection |
| 114 | + useExistingConnectionForTest() |
| 115 | + |
| 116 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 117 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 118 | + pluginConfigurator.installPluginFromPath( |
| 119 | + Path.of(path) |
| 120 | + ) |
| 121 | + } |
| 122 | + |
| 123 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 124 | + updateGeneralSettings() |
| 125 | + }.runIdeWithDriver() |
| 126 | + .useDriverAndCloseIde { |
| 127 | + waitForProjectOpen() |
| 128 | + // required wait time for the system to be fully ready |
| 129 | + Thread.sleep(30000) |
| 130 | + |
| 131 | + val readmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md") |
| 132 | + val readme = File(readmePath.toUri()) |
| 133 | + assertThat(readme) |
| 134 | + .doesNotExist() |
| 135 | + |
| 136 | + val result = executePuppeteerScript(createReadmeSubFolderPreFolderChangeTestScript) |
| 137 | + // Using keyboard press to select a subfolder based on a windows/linux folder selector |
| 138 | + // right to move active cursor to the end |
| 139 | + // enter src as the subfolder name (subfolder name tstData/qdoc/createFlow/src) |
| 140 | + // enter to confirm selected subfolder |
| 141 | + this.ui.robot.pressAndReleaseKey(KeyEvent.VK_RIGHT) |
| 142 | + this.ui.robot.enterText("\\/src") |
| 143 | + this.ui.robot.pressAndReleaseKey(KeyEvent.VK_ENTER) |
| 144 | + val result2 = executePuppeteerScript(createReadmeSubFolderPostFolderChangeTestScript) |
| 145 | + |
| 146 | + assertThat(result) |
| 147 | + .doesNotContain("Error: Test Failed") |
| 148 | + assertThat(result2) |
| 149 | + .doesNotContain("Error: Test Failed") |
| 150 | + |
| 151 | + val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md") |
| 152 | + val newReadme = File(newReadmePath.toUri()) |
| 153 | + assertThat(newReadme) |
| 154 | + .exists() |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + @Test |
| 159 | + fun `Create readme with multi-root workspace returns a readme`() { |
| 160 | + val testCase = TestCase( |
| 161 | + IdeProductProvider.IC, |
| 162 | + LocalProjectInfo( |
| 163 | + Paths.get("tstData", "qdoc") |
| 164 | + ) |
| 165 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 166 | + |
| 167 | + // inject connection |
| 168 | + useExistingConnectionForTest() |
| 169 | + |
| 170 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 171 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 172 | + pluginConfigurator.installPluginFromPath( |
| 173 | + Path.of(path) |
| 174 | + ) |
| 175 | + } |
| 176 | + |
| 177 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 178 | + updateGeneralSettings() |
| 179 | + }.runIdeWithDriver() |
| 180 | + .useDriverAndCloseIde { |
| 181 | + waitForProjectOpen() |
| 182 | + // required wait time for the system to be fully ready |
| 183 | + Thread.sleep(30000) |
| 184 | + |
| 185 | + val readmePath = Paths.get("tstData", "qdoc", "README.md") |
| 186 | + val readme = File(readmePath.toUri()) |
| 187 | + assertThat(readme).doesNotExist() |
| 188 | + |
| 189 | + val result = executePuppeteerScript(acceptReadmeTestScript) |
| 190 | + assertThat(result) |
| 191 | + .doesNotContain("Error: Test Failed") |
| 192 | + |
| 193 | + val newReadmePath = Paths.get("tstData", "qdoc", "README.md") |
| 194 | + val newReadme = File(newReadmePath.toUri()) |
| 195 | + assertThat(newReadme) |
| 196 | + .exists() |
| 197 | + .content() |
| 198 | + .contains( |
| 199 | + "REST", |
| 200 | + "API" |
| 201 | + ) |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + companion object { |
| 206 | + @JvmStatic |
| 207 | + @AfterAll |
| 208 | + fun clearAwsXml() { |
| 209 | + clearAwsXmlFile() |
| 210 | + } |
| 211 | + |
| 212 | + @JvmStatic |
| 213 | + @BeforeAll |
| 214 | + fun setUp() { |
| 215 | + // Setup test environment |
| 216 | + setupTestEnvironment() |
| 217 | + } |
| 218 | + } |
| 219 | +} |
0 commit comments