Skip to content
Closed
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
@@ -0,0 +1,178 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

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

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.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
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.scripts.updateReadmeAcceptChangesTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.updateReadmeConfirmOptionsTestScript
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.updateReadmeMakeChangesTestScript
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment
import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest
import java.io.File
import java.net.URI
import java.nio.file.Path
import java.nio.file.Paths

class UpdateCodeChangesFlowTest {

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 setUp() {
// Setup test environment
setupTestEnvironment()
}

@Test
fun `User is prompted to Confirm Selected Folder`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "Hello")
)
).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 result = executePuppeteerScript(updateReadmeConfirmOptionsTestScript)

assertTrue(result.contains("found buttons looks for in the text"))
assertFalse(result.contains("buttons not found"))
}
}

@Test
fun `Make changes button brings you to UPDATE w specific changes flow`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "Hello")
)
).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()
waitForProjectOpen()
// required wait time for the system to be fully ready
Thread.sleep(30000)

val result = executePuppeteerScript(updateReadmeMakeChangesTestScript)
assertFalse(result.contains("Could not find the placeholder text"))
assertTrue(result.contains("Found documentation change input text"))
}
}

@Test
fun `Update README with latest changes flow`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "Hello")
)
).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 result = executePuppeteerScript(updateReadmeAcceptChangesTestScript)

val readmePath = getReadmePath(delete = true)
val readmeFile = File(readmePath)
val content = readmeFile.readText()
assertTrue(content.contains("tancode"))
}
}

private fun getReadmePath(delete: Boolean = false): URI {
val readmePath = Paths.get("tstData", "Hello", "README.md").toUri()
if (delete) {
File(readmePath).takeIf { it.exists() }?.delete()
}
return readmePath
}

companion object {
@JvmStatic
@AfterAll
fun clearAwsXml() {
clearAwsXmlFile()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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

// language=TS
val updateReadmeAcceptChangesScript = """

const puppeteer = require('puppeteer');

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

try {

const pages = await browser.pages()
//console.log(pages)
for(const page of pages) {
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
//console.log(contents)
const element = await page.${'$'}('.mynah-chat-prompt-input')
if(element) {
console.log('found')

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

console.log('entered /doc')
console.log('found commands')

await findAndClickButton(page, 'Update an existing README', true, 10000)
console.log('clicked update readme')
await findAndClickButton(page, 'Update README to reflect code', true, 10000)
console.log('clicked update readme to reflect code')
await findAndClickButton(page, 'Yes', true, 10000)
console.log('clicked yes')

await new Promise(resolve => setTimeout(resolve, 90000));

await findAndClickButton(page, 'Accept', true, 10000)
console.log('clicked Accept')

}
}


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

testNavigation().catch(console.error);

""".trimIndent()

val updateReadmeAcceptChangesTestScript = updateReadmeAcceptChangesScript.plus(findAndClickButton)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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

// language=TS
val updateReadmeConfirmOptionsScript = """

const puppeteer = require('puppeteer');

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

try {

const pages = await browser.pages()
//console.log(pages)
for(const page of pages) {
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
//console.log(contents)
const element = await page.${'$'}('.mynah-chat-prompt-input')
if(element) {
console.log('found')

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

console.log('entered /doc')
console.log('found commands')

await findAndClickButton(page, 'Update an existing README', true, 10000)
console.log('clicked update readme')
await findAndClickButton(page, 'Update README to reflect code', true, 10000)

const yesButton = await findAndClickButton(page, 'Yes', false, 10000)
const changeFolderButton = await findAndClickButton(page, 'Change folder', false, 10000)
const cancelButton = await findAndClickButton(page, 'Cancel', false, 10000)

if (!yesButton || !changeFolderButton || !cancelButton) {
console.log('buttons not found')
} else {
console.log('found buttons looks for in the text')
}
}
}

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

testNavigation().catch(console.error);

""".trimIndent()

val updateReadmeConfirmOptionsTestScript = updateReadmeConfirmOptionsScript.plus(findAndClickButton)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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

// language=TS
val updateReadmeMakeChangesScript = """

const puppeteer = require('puppeteer');

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

try {

const pages = await browser.pages()
//console.log(pages)
for(const page of pages) {
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
//console.log(contents)
const element = await page.${'$'}('.mynah-chat-prompt-input')
if(element) {
console.log('found')

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

console.log('entered /doc')
console.log('found commands')

await findAndClickButton(page, 'Update an existing README', true, 10000)
console.log('clicked update readme')
await findAndClickButton(page, 'Update README to reflect code', true, 10000)
console.log('clicked update readme to reflect code')
await findAndClickButton(page, 'Yes', true, 10000)
console.log('clicked yes')

await new Promise(resolve => setTimeout(resolve, 90000));

await findAndClickButton(page, 'Make changes', true, 10000)
console.log('clicked make changes')

const makeChangeText = await page.${'$'}('[placeholder="Describe documentation changes"]')
if (!makeChangeText) {
throw new Error('Could not find the placeholder text');
} else {
console.log("Found documentation change input text")
}
}
}


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

testNavigation().catch(console.error);
""".trimIndent()

val updateReadmeMakeChangesTestScript = updateReadmeMakeChangesScript.plus(findAndClickButton)
Loading
Loading