Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ fun prepTestData(isCreate: Boolean) {
if (File(path).exists()) {
File(path).delete()
}
// check multi-root workspace readme as well
val path2 = Paths.get("tstData", "qdoc", "README.md").toUri()
if (File(path2).exists()) {
File(path2).delete()
}
} else {
val path = Paths.get("tstData", "qdoc", "updateFlow", "README.md").toUri()
process = ProcessBuilder("git", "restore", path.path).start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package software.aws.toolkits.jetbrains.uitests.docTests.createReadmeTests

import com.intellij.driver.sdk.ui.ui
import com.intellij.driver.sdk.waitForProjectOpen
import com.intellij.ide.starter.ci.CIServer
import com.intellij.ide.starter.config.ConfigurationStorage
Expand All @@ -27,6 +28,7 @@ import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmePromptedToConfirmFolderTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.makeChangesFlowTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.newReadmeDiffViewerTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.rejectReadmeTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.validateFeatureAvailabilityTestScript
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
Expand Down Expand Up @@ -246,6 +248,46 @@ class CreateReadmeTest {
}
}

@Test
fun `New Readme opens in diff viewer`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "qdoc", "createFlow")
)
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))

// inject connection
useExistingConnectionForTest()

Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
pluginConfigurator.installPluginFromPath(
Path.of(path)
)
}

copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
waitForProjectOpen()
// required wait time for the system to be fully ready
Thread.sleep(30000)

val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
val readme = File(readmePath.toUri())
assertThat(readme).doesNotExist()

val result = executePuppeteerScript(newReadmeDiffViewerTestScript)
assertThat(result)
.doesNotContain("Error: Test Failed")

val panel = this.ui.x("//div[contains(@class, 'SimpleDiffPanel')]")
assertThat(panel.present()).isTrue()
}
}

companion object {
@JvmStatic
@AfterAll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.uitests.docTests.createReadmeTests

import com.intellij.driver.sdk.ui.ui
import com.intellij.driver.sdk.waitForProjectOpen
import com.intellij.ide.starter.ci.CIServer
import com.intellij.ide.starter.config.ConfigurationStorage
import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.junit5.hyphenateWithClass
import com.intellij.ide.starter.models.TestCase
import com.intellij.ide.starter.project.LocalProjectInfo
import com.intellij.ide.starter.runner.CurrentTestMethod
import com.intellij.ide.starter.runner.Starter
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.kodein.di.DI
import org.kodein.di.bindSingleton
import software.aws.toolkits.jetbrains.uitests.TestCIServer
import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile
import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPostFolderChangeTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPreFolderChangeTestScript
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment
import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest
import java.awt.event.KeyEvent
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths

class CreateReadmeWorkspacesTest {
init {
di = DI {
extend(di)
bindSingleton<CIServer>(overrides = true) { TestCIServer }
val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply {
put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString())
}

bindSingleton<ConfigurationStorage>(overrides = true) {
ConfigurationStorage(this, defaults)
}
}
}

@BeforeEach
fun setUpTest() {
// prep test data - remove readme if it exists
prepTestData(true)
}

@Test
fun `Create readme with single-root workspace, root folder returns a readme`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "qdoc", "createFlow")
)
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))

// inject connection
useExistingConnectionForTest()

Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
pluginConfigurator.installPluginFromPath(
Path.of(path)
)
}

copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
waitForProjectOpen()
// required wait time for the system to be fully ready
Thread.sleep(30000)

val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
val readme = File(readmePath.toUri())
assertThat(readme).doesNotExist()

val result = executePuppeteerScript(acceptReadmeTestScript)
assertThat(result)
.doesNotContain("Error: Test Failed")

val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
val newReadme = File(newReadmePath.toUri())
assertThat(newReadme)
.exists()
.content()
.contains("REST", "API")
}
}

@Test
fun `Create readme with single-root workspace, in a subfolder returns a readme`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "qdoc", "createFlow")
)
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))

// inject connection
useExistingConnectionForTest()

Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
pluginConfigurator.installPluginFromPath(
Path.of(path)
)
}

copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
waitForProjectOpen()
// required wait time for the system to be fully ready
Thread.sleep(30000)

val readmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")
val readme = File(readmePath.toUri())
assertThat(readme)
.doesNotExist()

val result = executePuppeteerScript(createReadmeSubFolderPreFolderChangeTestScript)
// Using keyboard press to select a subfolder based on a windows/linux folder selector
// right to move active cursor to the end
// enter src as the subfolder name (subfolder name tstData/qdoc/createFlow/src)
// enter to confirm selected subfolder
this.ui.robot.pressAndReleaseKey(KeyEvent.VK_RIGHT)
this.ui.robot.enterText("\\/src")
this.ui.robot.pressAndReleaseKey(KeyEvent.VK_ENTER)
val result2 = executePuppeteerScript(createReadmeSubFolderPostFolderChangeTestScript)

assertThat(result)
.doesNotContain("Error: Test Failed")
assertThat(result2)
.doesNotContain("Error: Test Failed")

val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")
val newReadme = File(newReadmePath.toUri())
assertThat(newReadme)
.exists()
}
}

@Test
fun `Create readme with multi-root workspace returns a readme`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "qdoc")
)
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))

// inject connection
useExistingConnectionForTest()

Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
pluginConfigurator.installPluginFromPath(
Path.of(path)
)
}

copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
waitForProjectOpen()
// required wait time for the system to be fully ready
Thread.sleep(30000)

val readmePath = Paths.get("tstData", "qdoc", "README.md")
val readme = File(readmePath.toUri())
assertThat(readme).doesNotExist()

val result = executePuppeteerScript(acceptReadmeTestScript)
assertThat(result)
.doesNotContain("Error: Test Failed")

val newReadmePath = Paths.get("tstData", "qdoc", "README.md")
val newReadme = File(newReadmePath.toUri())
assertThat(newReadme)
.exists()
.content()
.contains(
"REST",
"API"
)
}
}

companion object {
@JvmStatic
@AfterAll
fun clearAwsXml() {
clearAwsXmlFile()
}

@JvmStatic
@BeforeAll
fun setUp() {
// Setup test environment
setupTestEnvironment()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts

import software.aws.toolkits.jetbrains.uitests.findAndClickButtonScript

// language=JS
val createReadmeSubFolderPreFolderChangeScript = """
const puppeteer = require('puppeteer');

async function testNavigation() {
const browser = await puppeteer.connect({
browserURL: 'http://localhost:9222'
})

try {

const pages = await browser.pages()

for(const page of pages) {
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));

const element = await page.${'$'}('.mynah-chat-prompt-input')
if(element) {

console.log('Typing /doc in the chat window')

await page.type('.mynah-chat-prompt-input', '/doc')
await page.keyboard.press('Enter')

console.log('Attempting to find and click Create a README button')
await findAndClickButton(page, 'Create a README', true, 10000)
console.log('Attempting to find and click Change folder button to select subfolder')
await findAndClickButton(page, 'Change folder', true, 10000)
}
}

} finally {
await browser.close();
}
}

testNavigation().catch((error) => {
console.log('Error: Test Failed');
console.error(error);
});
""".trimIndent()

// language=JS
val createReadmeSubFolderPostFolderChangeScript = """
const puppeteer = require('puppeteer');

async function testNavigation() {
const browser = await puppeteer.connect({
browserURL: 'http://localhost:9222'
})

try {

const pages = await browser.pages()

for(const page of pages) {
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));

const element = await page.${'$'}('.mynah-chat-prompt-input')
if(element) {
console.log('Attempting to find and click Yes button to confirm option')
await findAndClickButton(page, 'Yes', true, 10000)

console.log('Waiting for README to be generated')
await new Promise(resolve => setTimeout(resolve, 90000))

console.log('Attempting to find and click Accept button');
await findAndClickButton(page, 'Accept', true, 10000)
}
}

} finally {
await browser.close();
}
}

testNavigation().catch((error) => {
console.log('Error: Test Failed');
console.error(error);
});
""".trimIndent()

val createReadmeSubFolderPreFolderChangeTestScript = createReadmeSubFolderPreFolderChangeScript.plus(findAndClickButtonScript)
val createReadmeSubFolderPostFolderChangeTestScript = createReadmeSubFolderPostFolderChangeScript.plus(findAndClickButtonScript)
Loading
Loading