| 
 | 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.junit.jupiter.api.AfterAll  | 
 | 19 | +import org.junit.jupiter.api.Assertions.assertTrue  | 
 | 20 | +import org.junit.jupiter.api.Assertions.assertFalse  | 
 | 21 | +import org.junit.jupiter.api.BeforeAll  | 
 | 22 | +import org.junit.jupiter.api.BeforeEach  | 
 | 23 | +import org.junit.jupiter.api.Test  | 
 | 24 | +import org.kodein.di.DI  | 
 | 25 | +import org.kodein.di.bindSingleton  | 
 | 26 | +import software.aws.toolkits.jetbrains.uitests.TestCIServer  | 
 | 27 | +import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile  | 
 | 28 | +import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData  | 
 | 29 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript  | 
 | 30 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPostFolderChangeTestScript  | 
 | 31 | +import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPreFolderChangeTestScript  | 
 | 32 | +import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript  | 
 | 33 | +import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment  | 
 | 34 | +import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest  | 
 | 35 | +import java.awt.event.KeyEvent  | 
 | 36 | +import java.io.File  | 
 | 37 | +import java.nio.file.Path  | 
 | 38 | +import java.nio.file.Paths  | 
 | 39 | + | 
 | 40 | +class CreateReadmeWorkspacesTest {  | 
 | 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 `Create readme with single-root workspace, root folder returns a readme` () {  | 
 | 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 readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")  | 
 | 89 | +                val readme = File(readmePath.toUri())  | 
 | 90 | +                assertFalse(readme.exists())  | 
 | 91 | + | 
 | 92 | +                val result = executePuppeteerScript(acceptReadmeTestScript)  | 
 | 93 | +                assertFalse(result.contains("Error: Test Failed"))  | 
 | 94 | +                if (result.contains("Error: Test Failed")) {  | 
 | 95 | +                    println("result: $result")  | 
 | 96 | +                }  | 
 | 97 | + | 
 | 98 | +                val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")  | 
 | 99 | +                val newReadme = File(newReadmePath.toUri())  | 
 | 100 | +                assertTrue(newReadme.exists())  | 
 | 101 | +                assertTrue(newReadme.readText().contains("REST"))  | 
 | 102 | +                assertTrue(newReadme.readText().contains("API"))  | 
 | 103 | +            }  | 
 | 104 | +    }  | 
 | 105 | + | 
 | 106 | +    @Test  | 
 | 107 | +    fun `Create readme with single-root workspace, in a subfolder returns a readme`() {  | 
 | 108 | +        val testCase = TestCase(  | 
 | 109 | +            IdeProductProvider.IC,  | 
 | 110 | +            LocalProjectInfo(  | 
 | 111 | +                Paths.get("tstData", "qdoc", "createFlow")  | 
 | 112 | +            )  | 
 | 113 | +        ).useRelease(System.getProperty("org.gradle.project.ideProfileName"))  | 
 | 114 | + | 
 | 115 | +        // inject connection  | 
 | 116 | +        useExistingConnectionForTest()  | 
 | 117 | + | 
 | 118 | +        Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {  | 
 | 119 | +            System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->  | 
 | 120 | +                pluginConfigurator.installPluginFromPath(  | 
 | 121 | +                    Path.of(path)  | 
 | 122 | +                )  | 
 | 123 | +            }  | 
 | 124 | + | 
 | 125 | +            copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))  | 
 | 126 | +            updateGeneralSettings()  | 
 | 127 | +        }.runIdeWithDriver()  | 
 | 128 | +            .useDriverAndCloseIde {  | 
 | 129 | +                waitForProjectOpen()  | 
 | 130 | +                // required wait time for the system to be fully ready  | 
 | 131 | +                Thread.sleep(30000)  | 
 | 132 | + | 
 | 133 | +                val readmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")  | 
 | 134 | +                val readme = File(readmePath.toUri())  | 
 | 135 | +                assertFalse(readme.exists())  | 
 | 136 | + | 
 | 137 | +                val result = executePuppeteerScript(createReadmeSubFolderPreFolderChangeTestScript)  | 
 | 138 | +                this.ui.robot.pressAndReleaseKey(KeyEvent.VK_RIGHT)  | 
 | 139 | +                this.ui.robot.pressAndReleaseKey(KeyEvent.VK_DOWN)  | 
 | 140 | +                this.ui.robot.pressAndReleaseKey(KeyEvent.VK_ENTER)  | 
 | 141 | +                val result2 = executePuppeteerScript(createReadmeSubFolderPostFolderChangeTestScript)  | 
 | 142 | + | 
 | 143 | +                assertFalse(result.contains("Error: Test Failed"))  | 
 | 144 | +                assertFalse(result2.contains("Error: Test Failed"))  | 
 | 145 | + | 
 | 146 | +                if (result.contains("Error: Test Failed") || result2.contains("Error: Test Failed")) {  | 
 | 147 | +                    println("result: $result")  | 
 | 148 | +                    println("result2: $result2")  | 
 | 149 | +                }  | 
 | 150 | + | 
 | 151 | +                val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")  | 
 | 152 | +                val newReadme = File(newReadmePath.toUri())  | 
 | 153 | +                assertTrue(newReadme.exists())  | 
 | 154 | +            }  | 
 | 155 | +    }  | 
 | 156 | + | 
 | 157 | +    @Test  | 
 | 158 | +    fun `Create readme with multi-root workspace returns a readme`() {  | 
 | 159 | +        val testCase = TestCase(  | 
 | 160 | +            IdeProductProvider.IC,  | 
 | 161 | +            LocalProjectInfo(  | 
 | 162 | +                Paths.get("tstData", "qdoc")  | 
 | 163 | +            )  | 
 | 164 | +        ).useRelease(System.getProperty("org.gradle.project.ideProfileName"))  | 
 | 165 | + | 
 | 166 | +        // inject connection  | 
 | 167 | +        useExistingConnectionForTest()  | 
 | 168 | + | 
 | 169 | +        Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {  | 
 | 170 | +            System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->  | 
 | 171 | +                pluginConfigurator.installPluginFromPath(  | 
 | 172 | +                    Path.of(path)  | 
 | 173 | +                )  | 
 | 174 | +            }  | 
 | 175 | + | 
 | 176 | +            copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))  | 
 | 177 | +            updateGeneralSettings()  | 
 | 178 | +        }.runIdeWithDriver()  | 
 | 179 | +            .useDriverAndCloseIde {  | 
 | 180 | +                waitForProjectOpen()  | 
 | 181 | +                // required wait time for the system to be fully ready  | 
 | 182 | +                Thread.sleep(30000)  | 
 | 183 | + | 
 | 184 | +                val readmePath = Paths.get("tstData", "qdoc", "README.md")  | 
 | 185 | +                val readme = File(readmePath.toUri())  | 
 | 186 | +                assertFalse(readme.exists())  | 
 | 187 | + | 
 | 188 | +                val result = executePuppeteerScript(acceptReadmeTestScript)  | 
 | 189 | +                assertFalse(result.contains("Error: Test Failed"))  | 
 | 190 | +                if (result.contains("Error: Test Failed")) {  | 
 | 191 | +                    println("result: $result")  | 
 | 192 | +                }  | 
 | 193 | + | 
 | 194 | +                val newReadmePath = Paths.get("tstData", "qdoc", "README.md")  | 
 | 195 | +                val newReadme = File(newReadmePath.toUri())  | 
 | 196 | +                assertTrue(newReadme.exists())  | 
 | 197 | +                val readmeContents = newReadme.readText()  | 
 | 198 | +                assertTrue(readmeContents.contains("REST"))  | 
 | 199 | +                assertTrue(readmeContents.contains("API"))  | 
 | 200 | +            }  | 
 | 201 | +    }  | 
 | 202 | + | 
 | 203 | +    companion object {  | 
 | 204 | +        @JvmStatic  | 
 | 205 | +        @AfterAll  | 
 | 206 | +        fun clearAwsXml() {  | 
 | 207 | +            clearAwsXmlFile()  | 
 | 208 | +        }  | 
 | 209 | + | 
 | 210 | +        @JvmStatic  | 
 | 211 | +        @BeforeAll  | 
 | 212 | +        fun setUp() {  | 
 | 213 | +            // Setup test environment  | 
 | 214 | +            setupTestEnvironment()  | 
 | 215 | +        }  | 
 | 216 | +    }  | 
 | 217 | +}  | 
0 commit comments