Skip to content

Commit a75f49f

Browse files
gandhi-21Gaurav Gandhi
and
Gaurav Gandhi
authored
test(qdoc): Add ui tests for qdoc create readme flow (#5479)
* move findAndClickButton to common ScriptUtils & update script syntax to JS (followups from #5435) * initial commit: add qdoc create readme tests --------- Co-authored-by: Gaurav Gandhi <gangaur@amazon.com>
1 parent 48b30c0 commit a75f49f

File tree

15 files changed

+714
-15
lines changed

15 files changed

+714
-15
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package software.aws.toolkits.jetbrains.uitests.docTests.scripts
4+
package software.aws.toolkits.jetbrains.uitests
55

6-
// language=TS
6+
// language=JS
77
val findAndClickButtonScript = """
88
const findAndClickButton = async (
99
page,

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33

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

6+
import java.io.File
67
import java.nio.file.Paths
78

89
fun prepTestData(isCreate: Boolean) {
910
val process: Process
1011
if (isCreate) {
1112
val path = Paths.get("tstData", "qdoc", "createFlow", "README.md").toUri()
12-
process = ProcessBuilder("rm", path.path).start()
13+
if (File(path).exists()) {
14+
File(path).delete()
15+
}
1316
} else {
1417
val path = Paths.get("tstData", "qdoc", "updateFlow", "README.md").toUri()
1518
process = ProcessBuilder("git", "restore", path.path).start()
16-
}
17-
18-
val exitCode = process.waitFor()
19-
if (exitCode != 0) {
20-
println("Warning: git stash command failed with exit code $exitCode")
21-
process.errorStream.bufferedReader().use { reader ->
22-
println("Error: ${reader.readText()}")
19+
val exitCode = process.waitFor()
20+
if (exitCode != 0) {
21+
println("Warning: git stash command failed with exit code $exitCode")
22+
process.errorStream.bufferedReader().use { reader ->
23+
println("Error: ${reader.readText()}")
24+
}
2325
}
2426
}
2527
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
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.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.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.createReadmePromptedToConfirmFolderTestScript
30+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.makeChangesFlowTestScript
31+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.rejectReadmeTestScript
32+
import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.validateFeatureAvailabilityTestScript
33+
import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript
34+
import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment
35+
import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest
36+
import java.io.File
37+
import java.nio.file.Path
38+
import java.nio.file.Paths
39+
40+
class CreateReadmeTest {
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 `Validate that the qdoc feature can be invoked`() {
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 result = executePuppeteerScript(validateFeatureAvailabilityTestScript)
89+
assertTrue(result.contains("Test Successful"))
90+
assertFalse(result.contains("Error: Test Failed"))
91+
if (result.contains("Error: Test Failed")) {
92+
println("result: $result")
93+
}
94+
}
95+
}
96+
97+
@Test
98+
fun `You are prompted to confirm selected folder, change folder, or cancel back to choosing CREATE or UPDATE`() {
99+
val testCase = TestCase(
100+
IdeProductProvider.IC,
101+
LocalProjectInfo(
102+
Paths.get("tstData", "qdoc", "createFlow")
103+
)
104+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
105+
106+
// inject connection
107+
useExistingConnectionForTest()
108+
109+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
110+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
111+
pluginConfigurator.installPluginFromPath(
112+
Path.of(path)
113+
)
114+
}
115+
116+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
117+
updateGeneralSettings()
118+
}.runIdeWithDriver()
119+
.useDriverAndCloseIde {
120+
waitForProjectOpen()
121+
// required wait time for the system to be fully ready
122+
Thread.sleep(30000)
123+
124+
val result = executePuppeteerScript(createReadmePromptedToConfirmFolderTestScript)
125+
assertTrue(result.contains("Test Successful"))
126+
assertFalse(result.contains("Error: Test Failed"))
127+
if (result.contains("Error: Test Failed")) {
128+
println("result: $result")
129+
}
130+
}
131+
}
132+
133+
@Test
134+
fun `Make changes button brings you to UPDATE with specific changes flow`() {
135+
val testCase = TestCase(
136+
IdeProductProvider.IC,
137+
LocalProjectInfo(
138+
Paths.get("tstData", "qdoc", "createFlow")
139+
)
140+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
141+
142+
// inject connection
143+
useExistingConnectionForTest()
144+
145+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
146+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
147+
pluginConfigurator.installPluginFromPath(
148+
Path.of(path)
149+
)
150+
}
151+
152+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
153+
updateGeneralSettings()
154+
}.runIdeWithDriver()
155+
.useDriverAndCloseIde {
156+
waitForProjectOpen()
157+
// required wait time for the system to be fully ready
158+
Thread.sleep(30000)
159+
160+
val result = executePuppeteerScript(makeChangesFlowTestScript)
161+
assertTrue(result.contains("Test Successful"))
162+
assertFalse(result.contains("Error: Test Failed"))
163+
if (result.contains("Error: Test Failed")) {
164+
println("result: $result")
165+
}
166+
}
167+
}
168+
169+
@Test
170+
fun `Accept button saves the ReadMe in the appropriate folder`() {
171+
val testCase = TestCase(
172+
IdeProductProvider.IC,
173+
LocalProjectInfo(
174+
Paths.get("tstData", "qdoc", "createFlow")
175+
)
176+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
177+
178+
// inject connection
179+
useExistingConnectionForTest()
180+
181+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
182+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
183+
pluginConfigurator.installPluginFromPath(
184+
Path.of(path)
185+
)
186+
}
187+
188+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
189+
updateGeneralSettings()
190+
}.runIdeWithDriver()
191+
.useDriverAndCloseIde {
192+
waitForProjectOpen()
193+
// required wait time for the system to be fully ready
194+
Thread.sleep(30000)
195+
196+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
197+
val readme = File(readmePath.toUri())
198+
assertFalse(readme.exists())
199+
200+
val result = executePuppeteerScript(acceptReadmeTestScript)
201+
assertFalse(result.contains("Error: Test Failed"))
202+
if (result.contains("Error: Test Failed")) {
203+
println("result: $result")
204+
}
205+
206+
val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
207+
val newReadme = File(newReadmePath.toUri())
208+
assertTrue(newReadme.exists())
209+
assertTrue(newReadme.readText().contains("REST"))
210+
assertTrue(newReadme.readText().contains("API"))
211+
}
212+
}
213+
214+
@Test
215+
fun `Reject button discards the changes`() {
216+
val testCase = TestCase(
217+
IdeProductProvider.IC,
218+
LocalProjectInfo(
219+
Paths.get("tstData", "qdoc", "createFlow")
220+
)
221+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
222+
223+
// inject connection
224+
useExistingConnectionForTest()
225+
226+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
227+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
228+
pluginConfigurator.installPluginFromPath(
229+
Path.of(path)
230+
)
231+
}
232+
233+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
234+
updateGeneralSettings()
235+
}.runIdeWithDriver()
236+
.useDriverAndCloseIde {
237+
waitForProjectOpen()
238+
// required wait time for the system to be fully ready
239+
Thread.sleep(30000)
240+
241+
val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
242+
val readme = File(readmePath.toUri())
243+
assertFalse(readme.exists())
244+
245+
val result = executePuppeteerScript(rejectReadmeTestScript)
246+
assertTrue(result.contains("Test Successful"))
247+
assertFalse(result.contains("Error: Test Failed"))
248+
249+
if (result.contains("Error: Test Failed")) {
250+
println("result: $result")
251+
}
252+
253+
val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md")
254+
val newReadme = File(newReadmePath.toUri())
255+
assertFalse(newReadme.exists())
256+
}
257+
}
258+
259+
companion object {
260+
@JvmStatic
261+
@AfterAll
262+
fun clearAwsXml() {
263+
clearAwsXmlFile()
264+
}
265+
266+
@JvmStatic
267+
@BeforeAll
268+
fun setUp() {
269+
// Setup test environment
270+
setupTestEnvironment()
271+
}
272+
}
273+
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

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

6-
// language=TS
6+
import software.aws.toolkits.jetbrains.uitests.findAndClickButtonScript
7+
8+
// language=JS
79
val updateReadmeLatestChangesConfirmOptionsScript = """
810
const puppeteer = require('puppeteer');
911
@@ -57,7 +59,7 @@ val updateReadmeLatestChangesConfirmOptionsScript = """
5759
});
5860
""".trimIndent()
5961

60-
// language=TS
62+
// language=JS
6163
val updateReadmeLatestChangesScript = """
6264
6365
const puppeteer = require('puppeteer');
@@ -108,7 +110,7 @@ val updateReadmeLatestChangesScript = """
108110
109111
""".trimIndent()
110112

111-
// language=TS
113+
// language=JS
112114
val updateReadmeLatestChangesMakeChangesFlowScript = """
113115
114116
const puppeteer = require('puppeteer');

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

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

6-
// language=TS
6+
import software.aws.toolkits.jetbrains.uitests.findAndClickButtonScript
7+
8+
// language=JS
79
val updateReadmeSpecificChangesMakeChangesFlowScript = """
810
911
const puppeteer = require('puppeteer');
@@ -67,7 +69,7 @@ val updateReadmeSpecificChangesMakeChangesFlowScript = """
6769
6870
""".trimIndent()
6971

70-
// language=TS
72+
// language=JS
7173
val updateReadmeSpecificChangesScript = """
7274
7375
const puppeteer = require('puppeteer');

0 commit comments

Comments
 (0)