Skip to content

Commit 4523267

Browse files
Gaurav Gandhigandhi-21
Gaurav Gandhi
authored andcommitted
test(qdoc): add more test cases for createReadme testing
1 parent 4eaa965 commit 4523267

File tree

5 files changed

+415
-0
lines changed

5 files changed

+415
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 45 additions & 0 deletions
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
@@ -28,6 +29,7 @@ import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData
2829
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript
2930
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmePromptedToConfirmFolderTestScript
3031
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.makeChangesFlowTestScript
32+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.newReadmeDiffViewerTestScript
3133
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.rejectReadmeTestScript
3234
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.validateFeatureAvailabilityTestScript
3335
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
@@ -256,6 +258,49 @@ class CreateReadmeTest {
256258
}
257259
}
258260

261+
@Test
262+
fun `New Readme opens in diff viewer`() {
263+
val testCase = TestCase(
264+
IdeProductProvider.IC,
265+
LocalProjectInfo(
266+
Paths.get("tstData", "qdoc", "createFlow")
267+
)
268+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
269+
270+
// inject connection
271+
useExistingConnectionForTest()
272+
273+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
274+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
275+
pluginConfigurator.installPluginFromPath(
276+
Path.of(path)
277+
)
278+
}
279+
280+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
281+
updateGeneralSettings()
282+
}.runIdeWithDriver()
283+
.useDriverAndCloseIde {
284+
waitForProjectOpen()
285+
// required wait time for the system to be fully ready
286+
Thread.sleep(30000)
287+
288+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
289+
val readme = File(readmePath.toUri())
290+
assertFalse(readme.exists())
291+
292+
val result = executePuppeteerScript(newReadmeDiffViewerTestScript)
293+
assertFalse(result.contains("Error: Test Failed"))
294+
295+
if (result.contains("Error: Test Failed")) {
296+
println("result: $result")
297+
}
298+
299+
val panel = this.ui.x("//div[contains(@class, 'SimpleDiffPanel')]")
300+
assertTrue(panel.present())
301+
}
302+
}
303+
259304
companion object {
260305
@JvmStatic
261306
@AfterAll
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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.junit.jupiter.api.AfterAll
19+
import org.junit.jupiter.api.Assertions.assertTrue
20+
import org.junit.jupiter.api.Assertions.assertFalse
21+
import org.junit.jupiter.api.BeforeAll
22+
import org.junit.jupiter.api.BeforeEach
23+
import org.junit.jupiter.api.Test
24+
import org.kodein.di.DI
25+
import org.kodein.di.bindSingleton
26+
import software.aws.toolkits.jetbrains.uitests.TestCIServer
27+
import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile
28+
import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData
29+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript
30+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPostFolderChangeTestScript
31+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPreFolderChangeTestScript
32+
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
33+
import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment
34+
import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest
35+
import java.awt.event.KeyEvent
36+
import java.io.File
37+
import java.nio.file.Path
38+
import java.nio.file.Paths
39+
40+
class CreateReadmeWorkspacesTest {
41+
init {
42+
di = DI {
43+
extend(di)
44+
bindSingleton<CIServer>(overrides = true) { TestCIServer }
45+
val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply {
46+
put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString())
47+
}
48+
49+
bindSingleton<ConfigurationStorage>(overrides = true) {
50+
ConfigurationStorage(this, defaults)
51+
}
52+
}
53+
}
54+
55+
@BeforeEach
56+
fun setUpTest() {
57+
// prep test data - remove readme if it exists
58+
prepTestData(true)
59+
}
60+
61+
@Test
62+
fun `Create readme with single-root workspace, root folder returns a readme` () {
63+
val testCase = TestCase(
64+
IdeProductProvider.IC,
65+
LocalProjectInfo(
66+
Paths.get("tstData", "qdoc", "createFlow")
67+
)
68+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
69+
70+
// inject connection
71+
useExistingConnectionForTest()
72+
73+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
74+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
75+
pluginConfigurator.installPluginFromPath(
76+
Path.of(path)
77+
)
78+
}
79+
80+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
81+
updateGeneralSettings()
82+
}.runIdeWithDriver()
83+
.useDriverAndCloseIde {
84+
waitForProjectOpen()
85+
// required wait time for the system to be fully ready
86+
Thread.sleep(30000)
87+
88+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
89+
val readme = File(readmePath.toUri())
90+
assertFalse(readme.exists())
91+
92+
val result = executePuppeteerScript(acceptReadmeTestScript)
93+
assertFalse(result.contains("Error: Test Failed"))
94+
if (result.contains("Error: Test Failed")) {
95+
println("result: $result")
96+
}
97+
98+
val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
99+
val newReadme = File(newReadmePath.toUri())
100+
assertTrue(newReadme.exists())
101+
assertTrue(newReadme.readText().contains("REST"))
102+
assertTrue(newReadme.readText().contains("API"))
103+
}
104+
}
105+
106+
@Test
107+
fun `Create readme with single-root workspace, in a subfolder returns a readme`() {
108+
val testCase = TestCase(
109+
IdeProductProvider.IC,
110+
LocalProjectInfo(
111+
Paths.get("tstData", "qdoc", "createFlow")
112+
)
113+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
114+
115+
// inject connection
116+
useExistingConnectionForTest()
117+
118+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
119+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
120+
pluginConfigurator.installPluginFromPath(
121+
Path.of(path)
122+
)
123+
}
124+
125+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
126+
updateGeneralSettings()
127+
}.runIdeWithDriver()
128+
.useDriverAndCloseIde {
129+
waitForProjectOpen()
130+
// required wait time for the system to be fully ready
131+
Thread.sleep(30000)
132+
133+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")
134+
val readme = File(readmePath.toUri())
135+
assertFalse(readme.exists())
136+
137+
val result = executePuppeteerScript(createReadmeSubFolderPreFolderChangeTestScript)
138+
this.ui.robot.pressAndReleaseKey(KeyEvent.VK_RIGHT)
139+
this.ui.robot.pressAndReleaseKey(KeyEvent.VK_DOWN)
140+
this.ui.robot.pressAndReleaseKey(KeyEvent.VK_ENTER)
141+
val result2 = executePuppeteerScript(createReadmeSubFolderPostFolderChangeTestScript)
142+
143+
assertFalse(result.contains("Error: Test Failed"))
144+
assertFalse(result2.contains("Error: Test Failed"))
145+
146+
if (result.contains("Error: Test Failed") || result2.contains("Error: Test Failed")) {
147+
println("result: $result")
148+
println("result2: $result2")
149+
}
150+
151+
val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md")
152+
val newReadme = File(newReadmePath.toUri())
153+
assertTrue(newReadme.exists())
154+
}
155+
}
156+
157+
@Test
158+
fun `Create readme with multi-root workspace returns a readme`() {
159+
val testCase = TestCase(
160+
IdeProductProvider.IC,
161+
LocalProjectInfo(
162+
Paths.get("tstData", "qdoc")
163+
)
164+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
165+
166+
// inject connection
167+
useExistingConnectionForTest()
168+
169+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
170+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
171+
pluginConfigurator.installPluginFromPath(
172+
Path.of(path)
173+
)
174+
}
175+
176+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
177+
updateGeneralSettings()
178+
}.runIdeWithDriver()
179+
.useDriverAndCloseIde {
180+
waitForProjectOpen()
181+
// required wait time for the system to be fully ready
182+
Thread.sleep(30000)
183+
184+
val readmePath = Paths.get("tstData", "qdoc", "README.md")
185+
val readme = File(readmePath.toUri())
186+
assertFalse(readme.exists())
187+
188+
val result = executePuppeteerScript(acceptReadmeTestScript)
189+
assertFalse(result.contains("Error: Test Failed"))
190+
if (result.contains("Error: Test Failed")) {
191+
println("result: $result")
192+
}
193+
194+
val newReadmePath = Paths.get("tstData", "qdoc", "README.md")
195+
val newReadme = File(newReadmePath.toUri())
196+
assertTrue(newReadme.exists())
197+
val readmeContents = newReadme.readText()
198+
assertTrue(readmeContents.contains("REST"))
199+
assertTrue(readmeContents.contains("API"))
200+
}
201+
}
202+
203+
companion object {
204+
@JvmStatic
205+
@AfterAll
206+
fun clearAwsXml() {
207+
clearAwsXmlFile()
208+
}
209+
210+
@JvmStatic
211+
@BeforeAll
212+
fun setUp() {
213+
// Setup test environment
214+
setupTestEnvironment()
215+
}
216+
}
217+
}
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)