Skip to content

Commit 5347314

Browse files
gandhi-21Gaurav Gandhi
and
Gaurav Gandhi
authored
test(qdoc): add more test cases for createReadme testing (#5500)
* test(qdoc): add more test cases for createReadme testing * fix detekt issues * update subfolder selection for create readme in subfolder test * update assertions for tests * fix assertions for tests * update assertions for tests: remove explicitly logging failed results * update assertions for tests: remove explicitly logging failed results --------- Co-authored-by: Gaurav Gandhi <[email protected]>
1 parent 98254a2 commit 5347314

File tree

5 files changed

+414
-0
lines changed

5 files changed

+414
-0
lines changed

ui-tests-starter/tst-243+/software/aws/toolkits/jetbrains/uitests/docTests/Utils.kt

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ fun prepTestData(isCreate: Boolean) {
1313
if (File(path).exists()) {
1414
File(path).delete()
1515
}
16+
// check multi-root workspace readme as well
17+
val path2 = Paths.get("tstData", "qdoc", "README.md").toUri()
18+
if (File(path2).exists()) {
19+
File(path2).delete()
20+
}
1621
} else {
1722
val path = Paths.get("tstData", "qdoc", "updateFlow", "README.md").toUri()
1823
process = ProcessBuilder("git", "restore", path.path).start()

ui-tests-starter/tst-243+/software/aws/toolkits/jetbrains/uitests/docTests/createReadmeTests/CreateReadmeTest.kt

+42
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

6+
import com.intellij.driver.sdk.ui.ui
67
import com.intellij.driver.sdk.waitForProjectOpen
78
import com.intellij.ide.starter.ci.CIServer
89
import com.intellij.ide.starter.config.ConfigurationStorage
@@ -27,6 +28,7 @@ import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData
2728
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript
2829
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmePromptedToConfirmFolderTestScript
2930
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.makeChangesFlowTestScript
31+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.newReadmeDiffViewerTestScript
3032
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.rejectReadmeTestScript
3133
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.validateFeatureAvailabilityTestScript
3234
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
@@ -246,6 +248,46 @@ class CreateReadmeTest {
246248
}
247249
}
248250

251+
@Test
252+
fun `New Readme opens in diff viewer`() {
253+
val testCase = TestCase(
254+
IdeProductProvider.IC,
255+
LocalProjectInfo(
256+
Paths.get("tstData", "qdoc", "createFlow")
257+
)
258+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
259+
260+
// inject connection
261+
useExistingConnectionForTest()
262+
263+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
264+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
265+
pluginConfigurator.installPluginFromPath(
266+
Path.of(path)
267+
)
268+
}
269+
270+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
271+
updateGeneralSettings()
272+
}.runIdeWithDriver()
273+
.useDriverAndCloseIde {
274+
waitForProjectOpen()
275+
// required wait time for the system to be fully ready
276+
Thread.sleep(30000)
277+
278+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
279+
val readme = File(readmePath.toUri())
280+
assertThat(readme).doesNotExist()
281+
282+
val result = executePuppeteerScript(newReadmeDiffViewerTestScript)
283+
assertThat(result)
284+
.doesNotContain("Error: Test Failed")
285+
286+
val panel = this.ui.x("//div[contains(@class, 'SimpleDiffPanel')]")
287+
assertThat(panel.present()).isTrue()
288+
}
289+
}
290+
249291
companion object {
250292
@JvmStatic
251293
@AfterAll
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
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.assertj.core.api.Assertions.assertThat
19+
import org.junit.jupiter.api.AfterAll
20+
import org.junit.jupiter.api.BeforeAll
21+
import org.junit.jupiter.api.BeforeEach
22+
import org.junit.jupiter.api.Test
23+
import org.kodein.di.DI
24+
import org.kodein.di.bindSingleton
25+
import software.aws.toolkits.jetbrains.uitests.TestCIServer
26+
import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile
27+
import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData
28+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript
29+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPostFolderChangeTestScript
30+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPreFolderChangeTestScript
31+
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
32+
import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment
33+
import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest
34+
import java.awt.event.KeyEvent
35+
import java.io.File
36+
import java.nio.file.Path
37+
import java.nio.file.Paths
38+
39+
class CreateReadmeWorkspacesTest {
40+
init {
41+
di = DI {
42+
extend(di)
43+
bindSingleton<CIServer>(overrides = true) { TestCIServer }
44+
val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply {
45+
put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString())
46+
}
47+
48+
bindSingleton<ConfigurationStorage>(overrides = true) {
49+
ConfigurationStorage(this, defaults)
50+
}
51+
}
52+
}
53+
54+
@BeforeEach
55+
fun setUpTest() {
56+
// prep test data - remove readme if it exists
57+
prepTestData(true)
58+
}
59+
60+
@Test
61+
fun `Create readme with single-root workspace, root folder returns a readme`() {
62+
val testCase = TestCase(
63+
IdeProductProvider.IC,
64+
LocalProjectInfo(
65+
Paths.get("tstData", "qdoc", "createFlow")
66+
)
67+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
68+
69+
// inject connection
70+
useExistingConnectionForTest()
71+
72+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
73+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
74+
pluginConfigurator.installPluginFromPath(
75+
Path.of(path)
76+
)
77+
}
78+
79+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
80+
updateGeneralSettings()
81+
}.runIdeWithDriver()
82+
.useDriverAndCloseIde {
83+
waitForProjectOpen()
84+
// required wait time for the system to be fully ready
85+
Thread.sleep(30000)
86+
87+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
88+
val readme = File(readmePath.toUri())
89+
assertThat(readme).doesNotExist()
90+
91+
val result = executePuppeteerScript(acceptReadmeTestScript)
92+
assertThat(result)
93+
.doesNotContain("Error: Test Failed")
94+
95+
val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
96+
val newReadme = File(newReadmePath.toUri())
97+
assertThat(newReadme)
98+
.exists()
99+
.content()
100+
.contains("REST", "API")
101+
}
102+
}
103+
104+
@Test
105+
fun `Create readme with single-root workspace, in a subfolder returns a readme`() {
106+
val testCase = TestCase(
107+
IdeProductProvider.IC,
108+
LocalProjectInfo(
109+
Paths.get("tstData", "qdoc", "createFlow")
110+
)
111+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
112+
113+
// inject connection
114+
useExistingConnectionForTest()
115+
116+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
117+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
118+
pluginConfigurator.installPluginFromPath(
119+
Path.of(path)
120+
)
121+
}
122+
123+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
124+
updateGeneralSettings()
125+
}.runIdeWithDriver()
126+
.useDriverAndCloseIde {
127+
waitForProjectOpen()
128+
// required wait time for the system to be fully ready
129+
Thread.sleep(30000)
130+
131+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")
132+
val readme = File(readmePath.toUri())
133+
assertThat(readme)
134+
.doesNotExist()
135+
136+
val result = executePuppeteerScript(createReadmeSubFolderPreFolderChangeTestScript)
137+
// Using keyboard press to select a subfolder based on a windows/linux folder selector
138+
// right to move active cursor to the end
139+
// enter src as the subfolder name (subfolder name tstData/qdoc/createFlow/src)
140+
// enter to confirm selected subfolder
141+
this.ui.robot.pressAndReleaseKey(KeyEvent.VK_RIGHT)
142+
this.ui.robot.enterText("\\/src")
143+
this.ui.robot.pressAndReleaseKey(KeyEvent.VK_ENTER)
144+
val result2 = executePuppeteerScript(createReadmeSubFolderPostFolderChangeTestScript)
145+
146+
assertThat(result)
147+
.doesNotContain("Error: Test Failed")
148+
assertThat(result2)
149+
.doesNotContain("Error: Test Failed")
150+
151+
val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")
152+
val newReadme = File(newReadmePath.toUri())
153+
assertThat(newReadme)
154+
.exists()
155+
}
156+
}
157+
158+
@Test
159+
fun `Create readme with multi-root workspace returns a readme`() {
160+
val testCase = TestCase(
161+
IdeProductProvider.IC,
162+
LocalProjectInfo(
163+
Paths.get("tstData", "qdoc")
164+
)
165+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
166+
167+
// inject connection
168+
useExistingConnectionForTest()
169+
170+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
171+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
172+
pluginConfigurator.installPluginFromPath(
173+
Path.of(path)
174+
)
175+
}
176+
177+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
178+
updateGeneralSettings()
179+
}.runIdeWithDriver()
180+
.useDriverAndCloseIde {
181+
waitForProjectOpen()
182+
// required wait time for the system to be fully ready
183+
Thread.sleep(30000)
184+
185+
val readmePath = Paths.get("tstData", "qdoc", "README.md")
186+
val readme = File(readmePath.toUri())
187+
assertThat(readme).doesNotExist()
188+
189+
val result = executePuppeteerScript(acceptReadmeTestScript)
190+
assertThat(result)
191+
.doesNotContain("Error: Test Failed")
192+
193+
val newReadmePath = Paths.get("tstData", "qdoc", "README.md")
194+
val newReadme = File(newReadmePath.toUri())
195+
assertThat(newReadme)
196+
.exists()
197+
.content()
198+
.contains(
199+
"REST",
200+
"API"
201+
)
202+
}
203+
}
204+
205+
companion object {
206+
@JvmStatic
207+
@AfterAll
208+
fun clearAwsXml() {
209+
clearAwsXmlFile()
210+
}
211+
212+
@JvmStatic
213+
@BeforeAll
214+
fun setUp() {
215+
// Setup test environment
216+
setupTestEnvironment()
217+
}
218+
}
219+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.createReadmeScripts
5+
6+
import software.aws.toolkits.jetbrains.uitests.findAndClickButtonScript
7+
8+
// language=JS
9+
val createReadmeSubFolderPreFolderChangeScript = """
10+
const puppeteer = require('puppeteer');
11+
12+
async function testNavigation() {
13+
const browser = await puppeteer.connect({
14+
browserURL: 'http://localhost:9222'
15+
})
16+
17+
try {
18+
19+
const pages = await browser.pages()
20+
21+
for(const page of pages) {
22+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
23+
24+
const element = await page.${'$'}('.mynah-chat-prompt-input')
25+
if(element) {
26+
27+
console.log('Typing /doc in the chat window')
28+
29+
await page.type('.mynah-chat-prompt-input', '/doc')
30+
await page.keyboard.press('Enter')
31+
32+
console.log('Attempting to find and click Create a README button')
33+
await findAndClickButton(page, 'Create a README', true, 10000)
34+
console.log('Attempting to find and click Change folder button to select subfolder')
35+
await findAndClickButton(page, 'Change folder', true, 10000)
36+
}
37+
}
38+
39+
} finally {
40+
await browser.close();
41+
}
42+
}
43+
44+
testNavigation().catch((error) => {
45+
console.log('Error: Test Failed');
46+
console.error(error);
47+
});
48+
""".trimIndent()
49+
50+
// language=JS
51+
val createReadmeSubFolderPostFolderChangeScript = """
52+
const puppeteer = require('puppeteer');
53+
54+
async function testNavigation() {
55+
const browser = await puppeteer.connect({
56+
browserURL: 'http://localhost:9222'
57+
})
58+
59+
try {
60+
61+
const pages = await browser.pages()
62+
63+
for(const page of pages) {
64+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
65+
66+
const element = await page.${'$'}('.mynah-chat-prompt-input')
67+
if(element) {
68+
console.log('Attempting to find and click Yes button to confirm option')
69+
await findAndClickButton(page, 'Yes', true, 10000)
70+
71+
console.log('Waiting for README to be generated')
72+
await new Promise(resolve => setTimeout(resolve, 90000))
73+
74+
console.log('Attempting to find and click Accept button');
75+
await findAndClickButton(page, 'Accept', true, 10000)
76+
}
77+
}
78+
79+
} finally {
80+
await browser.close();
81+
}
82+
}
83+
84+
testNavigation().catch((error) => {
85+
console.log('Error: Test Failed');
86+
console.error(error);
87+
});
88+
""".trimIndent()
89+
90+
val createReadmeSubFolderPreFolderChangeTestScript = createReadmeSubFolderPreFolderChangeScript.plus(findAndClickButtonScript)
91+
val createReadmeSubFolderPostFolderChangeTestScript = createReadmeSubFolderPostFolderChangeScript.plus(findAndClickButtonScript)

0 commit comments

Comments
 (0)