Skip to content

Commit 85d480e

Browse files
author
David Hasani
committed
test(amazonq): add e2e test for /transform
1 parent b7e9b73 commit 85d480e

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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
5+
6+
import com.intellij.driver.sdk.waitForProjectOpen
7+
import com.intellij.ide.starter.ci.CIServer
8+
import com.intellij.ide.starter.di.di
9+
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
10+
import com.intellij.ide.starter.ide.IdeProductProvider
11+
import com.intellij.ide.starter.junit5.hyphenateWithClass
12+
import com.intellij.ide.starter.models.TestCase
13+
import com.intellij.ide.starter.project.LocalProjectInfo
14+
import com.intellij.ide.starter.runner.CurrentTestMethod
15+
import com.intellij.ide.starter.runner.Starter
16+
import org.junit.jupiter.api.Assertions.assertEquals
17+
import org.junit.jupiter.api.Assertions.assertTrue
18+
import org.junit.jupiter.api.BeforeEach
19+
import org.junit.jupiter.api.Test
20+
import org.kodein.di.DI
21+
import org.kodein.di.bindSingleton
22+
import java.io.File
23+
import java.nio.file.Path
24+
import java.nio.file.Paths
25+
import kotlin.io.path.createParentDirectories
26+
import kotlin.io.path.writeText
27+
28+
class TransformChatTest {
29+
30+
init {
31+
di = DI {
32+
extend(di)
33+
bindSingleton<CIServer>(overrides = true) { TestCIServer }
34+
}
35+
}
36+
37+
private val testResourcesPath = "src/test/tstData"
38+
39+
@BeforeEach
40+
fun setUp() {
41+
// Setup test environment
42+
setupTestEnvironment()
43+
}
44+
private fun setupTestEnvironment() {
45+
// Ensure Puppeteer is installed
46+
val npmInstall = ProcessBuilder()
47+
.command("npm", "install", "puppeteer")
48+
.inheritIO()
49+
.start()
50+
.waitFor()
51+
52+
assertEquals(0, npmInstall, "Failed to install Puppeteer")
53+
54+
}
55+
56+
@Test
57+
fun `can open up IDE`() {
58+
val testCase = TestCase(
59+
IdeProductProvider.IC,
60+
LocalProjectInfo(
61+
Paths.get("tstData", "Hello")
62+
)
63+
).useRelease("2024.3")
64+
65+
66+
Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "ee1d2538cb8d358377d7661466c866af747a8a3f.json")
67+
.createParentDirectories()
68+
.writeText(
69+
"""
70+
auth goes here
71+
""".trimIndent()
72+
)
73+
74+
Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "d3b447f809607422aac1470dd17fbb32e358cdb3.json")
75+
.writeText(
76+
"""
77+
auth goes here
78+
""".trimIndent()
79+
)
80+
81+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
82+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
83+
pluginConfigurator.installPluginFromPath(
84+
Path.of(path)
85+
)
86+
}
87+
88+
copyExistingConfig(Paths.get("tstData", "config"))
89+
updateGeneralSettings()
90+
}.runIdeWithDriver()
91+
.useDriverAndCloseIde {
92+
waitForProjectOpen()
93+
Thread.sleep(20000)
94+
95+
96+
val result = executeScript(scr)
97+
assertTrue(result.contains("Choose a module to transform"))
98+
assertTrue(result.contains("Choose the target code version"))
99+
assertTrue(result.contains("Skip tests form appeared: true"))
100+
assertTrue(result.contains("One or multiple diffs form appeared: true"))
101+
assertTrue(result.contains("couldn't run the Maven clean install command"))
102+
}
103+
}
104+
105+
private fun executeScript(scriptContent: String): String {
106+
val scriptFile = File("$testResourcesPath/temp-script.js")
107+
scriptFile.parentFile.mkdirs()
108+
scriptFile.writeText(scriptContent)
109+
110+
val process = ProcessBuilder()
111+
.command("node", scriptFile.absolutePath)
112+
.redirectErrorStream(true)
113+
.start()
114+
115+
val output = process.inputStream.bufferedReader().use { it.readText() }
116+
val exitCode = process.waitFor()
117+
118+
scriptFile.delete()
119+
120+
assertEquals(0, exitCode, "Script execution failed with output: $output")
121+
return output
122+
}
123+
124+
}
125+
126+
private val scr = """
127+
const puppeteer = require('puppeteer');
128+
async function testNavigation() {
129+
const browser = await puppeteer.connect({
130+
browserURL: "http://localhost:9222"
131+
})
132+
try {
133+
const pages = await browser.pages()
134+
for (const page of pages) {
135+
const contents = await page.evaluate(el => el.innerHTML, await page.$(':root'))
136+
const element = await page.$('.mynah-chat-prompt-input')
137+
await page.type('.mynah-chat-prompt-input', '/transform')
138+
await page.keyboard.press('Enter')
139+
140+
await page.waitForSelector('.mynah-chat-item-form-items-container', {
141+
timeout: 5000
142+
})
143+
const formInputs = await page.$$('.mynah-form-input-wrapper')
144+
145+
const moduleLabel = await formInputs[0].evaluate(
146+
element => element.querySelector('.mynah-ui-form-item-mandatory-title').textContent
147+
)
148+
console.log('Module selection label:', moduleLabel)
149+
150+
const versionLabel = await formInputs[1].evaluate(
151+
element => element.querySelector('.mynah-ui-form-item-mandatory-title').textContent
152+
)
153+
console.log('Version selection label:', versionLabel)
154+
155+
await page.evaluate(() => {
156+
const button = document.querySelector('button[action-id="codetransform-input-confirm"]')
157+
button.click()
158+
})
159+
160+
const skipTestsForm = await page.waitForSelector('button[action-id="codetransform-input-confirm-skip-tests"]', {
161+
timeout: 5000
162+
})
163+
console.log('Skip tests form appeared:', skipTestsForm !== null)
164+
165+
await page.evaluate(() => {
166+
const button = document.querySelector('button[action-id="codetransform-input-confirm-skip-tests"]')
167+
button.click()
168+
})
169+
170+
const oneOrMultipleDiffsForm = await page.waitForSelector('button[action-id="codetransform-input-confirm-one-or-multiple-diffs"]', {
171+
timeout: 5000
172+
})
173+
console.log('One or multiple diffs form appeared:', oneOrMultipleDiffsForm !== null)
174+
175+
await page.evaluate(() => {
176+
const button = document.querySelector('button[action-id="codetransform-input-confirm-one-or-multiple-diffs"]')
177+
button.click()
178+
})
179+
180+
const errorMessage = await page.waitForSelector('text/Sorry, I couldn\'t run the Maven clean install command', {
181+
timeout: 5000
182+
})
183+
console.log('Error message:', await errorMessage.evaluate(el => el.textContent))
184+
}
185+
} finally {
186+
await browser.close()
187+
}
188+
}
189+
testNavigation().catch(console.error)
190+
""".trimIndent()
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. -->
2+
<!-- SPDX-License-Identifier: Apache-2.0 -->
3+
<root>
4+
<!-- Empty pom.xml used for testing /transform; see TransformChatTest.kt -->
5+
</root>

0 commit comments

Comments
 (0)