Skip to content

Commit 76b42b8

Browse files
author
Gaurav Gandhi
committed
test(qdoc): initial tests for latest code changes flow
1 parent f9f19d5 commit 76b42b8

File tree

11 files changed

+679
-0
lines changed

11 files changed

+679
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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
5+
6+
import com.intellij.driver.sdk.waitForProjectOpen
7+
import com.intellij.ide.starter.ci.CIServer
8+
import com.intellij.ide.starter.config.ConfigurationStorage
9+
import com.intellij.ide.starter.di.di
10+
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
11+
import com.intellij.ide.starter.ide.IdeProductProvider
12+
import com.intellij.ide.starter.junit5.hyphenateWithClass
13+
import com.intellij.ide.starter.models.TestCase
14+
import com.intellij.ide.starter.project.LocalProjectInfo
15+
import com.intellij.ide.starter.runner.CurrentTestMethod
16+
import com.intellij.ide.starter.runner.Starter
17+
import org.junit.jupiter.api.AfterAll
18+
import org.junit.jupiter.api.Assertions.assertFalse
19+
import org.junit.jupiter.api.Assertions.assertTrue
20+
import org.junit.jupiter.api.BeforeEach
21+
import org.junit.jupiter.api.Test
22+
import org.kodein.di.DI
23+
import org.kodein.di.bindSingleton
24+
import software.aws.toolkits.jetbrains.uitests.TestCIServer
25+
import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile
26+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.updateReadmeLatestChangesConfirmOptionsTestScript
27+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.updateReadmeLatestChangesMakeChangesFlowTestScript
28+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.updateReadmeLatestChangesTestScript
29+
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
30+
import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment
31+
import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest
32+
import java.io.File
33+
import java.nio.file.Path
34+
import java.nio.file.Paths
35+
36+
class UpdateReadmeWithLatestChangesFlowTest {
37+
38+
init {
39+
di = DI {
40+
extend(di)
41+
bindSingleton<CIServer>(overrides = true) { TestCIServer }
42+
val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply {
43+
put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString())
44+
}
45+
46+
bindSingleton<ConfigurationStorage>(overrides = true) {
47+
ConfigurationStorage(this, defaults)
48+
}
49+
}
50+
}
51+
52+
@BeforeEach
53+
fun setUp() {
54+
// Setup test environment
55+
setupTestEnvironment()
56+
}
57+
58+
@Test
59+
fun `Prompted to confirm selected folder`() {
60+
val testCase = TestCase(
61+
IdeProductProvider.IC,
62+
LocalProjectInfo(
63+
Paths.get("tstData", "qdoc", "updateFlow")
64+
)
65+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
66+
67+
// inject connection
68+
useExistingConnectionForTest()
69+
70+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
71+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
72+
pluginConfigurator.installPluginFromPath(
73+
Path.of(path)
74+
)
75+
}
76+
77+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
78+
updateGeneralSettings()
79+
}.runIdeWithDriver()
80+
.useDriverAndCloseIde {
81+
waitForProjectOpen()
82+
// required wait time for the system to be fully ready
83+
Thread.sleep(30000)
84+
85+
val result = executePuppeteerScript(updateReadmeLatestChangesConfirmOptionsTestScript)
86+
assertTrue(result.contains("Test Successful"))
87+
assertFalse(result.contains("Error: Test Failed"))
88+
}
89+
}
90+
91+
@Test
92+
fun `Make Changes button leads to UPDATE with specific changes flow`() {
93+
val testCase = TestCase(
94+
IdeProductProvider.IC,
95+
LocalProjectInfo(
96+
Paths.get("tstData", "qdoc", "updateFlow")
97+
)
98+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
99+
100+
// inject connection
101+
useExistingConnectionForTest()
102+
103+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
104+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
105+
pluginConfigurator.installPluginFromPath(
106+
Path.of(path)
107+
)
108+
}
109+
110+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
111+
updateGeneralSettings()
112+
}.runIdeWithDriver()
113+
.useDriverAndCloseIde {
114+
waitForProjectOpen()
115+
// required wait time for the system to be fully ready
116+
Thread.sleep(30000)
117+
118+
val result = executePuppeteerScript(updateReadmeLatestChangesMakeChangesFlowTestScript)
119+
assertTrue(result.contains("Test Successful"))
120+
assertFalse(result.contains("Error: Test Failed"))
121+
}
122+
}
123+
124+
@Test
125+
fun `UpdateReadme with latest changes returns an updated Readme`() {
126+
val testCase = TestCase(
127+
IdeProductProvider.IC,
128+
LocalProjectInfo(
129+
Paths.get("tstData", "qdoc", "updateFlow")
130+
)
131+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
132+
133+
// inject connection
134+
useExistingConnectionForTest()
135+
136+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
137+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
138+
pluginConfigurator.installPluginFromPath(
139+
Path.of(path)
140+
)
141+
}
142+
143+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
144+
updateGeneralSettings()
145+
}.runIdeWithDriver()
146+
.useDriverAndCloseIde {
147+
waitForProjectOpen()
148+
// required wait time for the system to be fully ready
149+
Thread.sleep(30000)
150+
151+
val result = executePuppeteerScript(updateReadmeLatestChangesTestScript)
152+
assertTrue(result.contains("Test Successful"))
153+
assertFalse(result.contains("Error: Test Failed"))
154+
155+
val readmePath = Paths.get("tstData", "qdoc", "updateFlow", "README.md")
156+
val readme = File(readmePath.toUri())
157+
assertTrue(readme.exists())
158+
assertTrue(readme.readText().contains("tancode"))
159+
assertTrue(readme.readText().contains("HealthController"))
160+
}
161+
}
162+
163+
companion object {
164+
@JvmStatic
165+
@AfterAll
166+
fun clearAwsXml() {
167+
clearAwsXmlFile()
168+
}
169+
}
170+
}
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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.scripts
5+
6+
// language=TS
7+
val updateReadmeLatestChangesConfirmOptionsScript = """
8+
const puppeteer = require('puppeteer');
9+
10+
async function testNavigation() {
11+
const browser = await puppeteer.connect({
12+
browserURL: 'http://localhost:9222'
13+
})
14+
15+
try {
16+
17+
const pages = await browser.pages()
18+
19+
for(const page of pages) {
20+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
21+
22+
const element = await page.${'$'}('.mynah-chat-prompt-input')
23+
if(element) {
24+
25+
console.log('Typing /doc in the chat window')
26+
27+
await page.type('.mynah-chat-prompt-input', '/doc')
28+
await page.keyboard.press('Enter')
29+
30+
console.log('Attempting to find and click Update an existing README button')
31+
await findAndClickButton(page, 'Update an existing README', true, 10000)
32+
console.log('Attempting to find and click Update README to reflect code button')
33+
await findAndClickButton(page, 'Update README to reflect code', true, 10000)
34+
console.log('Attempting to find all available buttons')
35+
const yesButton = await findAndClickButton(page, 'Yes', false, 10000)
36+
const changeFolderButton = await findAndClickButton(page, 'Change folder', false, 10000)
37+
const cancelButton = await findAndClickButton(page, 'Cancel', false, 10000)
38+
39+
if (!yesButton || !changeFolderButton || !cancelButton) {
40+
console.log('Error: Test Failed')
41+
console.log('Unable to find buttons for Yes/ChangeFolder/Cancel')
42+
} else {
43+
console.log('Found all expected buttons')
44+
console.log('Test Successful')
45+
}
46+
}
47+
}
48+
49+
} finally {
50+
await browser.close();
51+
}
52+
}
53+
54+
testNavigation().catch((error) => {
55+
console.log('Error: Test Failed');
56+
console.error(error);
57+
});
58+
""".trimIndent()
59+
60+
// language=TS
61+
val updateReadmeLatestChangesScript = """
62+
63+
const puppeteer = require('puppeteer');
64+
65+
async function testNavigation() {
66+
const browser = await puppeteer.connect({
67+
browserURL: 'http://localhost:9222'
68+
})
69+
70+
try {
71+
72+
const pages = await browser.pages()
73+
74+
for(const page of pages) {
75+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
76+
77+
const element = await page.${'$'}('.mynah-chat-prompt-input')
78+
79+
if(element) {
80+
81+
console.log('Typing /doc in the chat window')
82+
83+
await page.type('.mynah-chat-prompt-input', '/doc')
84+
await page.keyboard.press('Enter')
85+
86+
console.log('Attempting to find and click Update an existing README button')
87+
await findAndClickButton(page, 'Update an existing README', true, 10000)
88+
console.log('Attempting to find and click Update README to reflect code button')
89+
await findAndClickButton(page, 'Update README to reflect code', true, 10000)
90+
console.log('Attempting to find and click Yes button to confirm option')
91+
await findAndClickButton(page, 'Yes', true, 10000)
92+
console.log('Waiting for updated README to be generated')
93+
await new Promise(resolve => setTimeout(resolve, 90000));
94+
console.log('Attempting to find and click Accept button')
95+
await findAndClickButton(page, 'Accept', true, 10000)
96+
97+
// find and confirm the readme was generated successfully
98+
99+
100+
}
101+
}
102+
103+
} finally {
104+
await browser.close();
105+
}
106+
}
107+
108+
testNavigation().catch((error) => {
109+
console.log('Error: Test Failed');
110+
console.error(error);
111+
});
112+
113+
""".trimIndent()
114+
115+
// language=TS
116+
val updateReadmeLatestChangesMakeChangesFlowScript = """
117+
118+
const puppeteer = require('puppeteer');
119+
120+
async function testNavigation() {
121+
const browser = await puppeteer.connect({
122+
browserURL: 'http://localhost:9222'
123+
});
124+
125+
try {
126+
127+
const pages = await browser.pages();
128+
129+
for(const page of pages) {
130+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
131+
132+
const element = await page.${'$'}('.mynah-chat-prompt-input');
133+
if(element) {
134+
135+
console.log('Typing /doc in the chat window');
136+
137+
await page.type('.mynah-chat-prompt-input', '/doc');
138+
await page.keyboard.press('Enter');
139+
140+
console.log('Attempting to find and click Update an existing README button');
141+
await findAndClickButton(page, 'Update an existing README', true, 10000);
142+
console.log('Attempting to find and click Update README to reflect code button');
143+
await findAndClickButton(page, 'Update README to reflect code', true, 10000);
144+
console.log('Attempting to find and click Yes button to confirm option');
145+
await findAndClickButton(page, 'Yes', true, 10000);
146+
console.log('Waiting for updated README to be generated');
147+
await new Promise(resolve => setTimeout(resolve, 90000));
148+
console.log('Attempting to find and click Make changes button');
149+
await findAndClickButton(page, 'Make changes', true, 10000);
150+
const makeChangeText = await page.${'$'}('[placeholder="Describe documentation changes"]');
151+
if (!makeChangeText) {
152+
console.log('Error: Test Failed');
153+
console.log('Unable to find placeholder description test in Make Changes flow');
154+
} else {
155+
console.log('Found expected placeholder text for Make Changes flow');
156+
console.log('Test Successful');
157+
}
158+
159+
}
160+
}
161+
162+
} finally {
163+
await browser.close();
164+
}
165+
}
166+
167+
testNavigation().catch((error) => {
168+
console.log('Error: Test Failed');
169+
console.error(error);
170+
});
171+
172+
""".trimIndent()
173+
174+
val updateReadmeLatestChangesConfirmOptionsTestScript = updateReadmeLatestChangesConfirmOptionsScript.plus(findAndClickButtonScript)
175+
val updateReadmeLatestChangesTestScript = updateReadmeLatestChangesScript.plus(findAndClickButtonScript)
176+
val updateReadmeLatestChangesMakeChangesFlowTestScript = updateReadmeLatestChangesMakeChangesFlowScript.plus(findAndClickButtonScript)

0 commit comments

Comments
 (0)