-
Notifications
You must be signed in to change notification settings - Fork 273
test(qdoc): add more test cases for createReadme testing #5500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b90803
test(qdoc): add more test cases for createReadme testing
0449dfe
fix detekt issues
ed1cb7b
update subfolder selection for create readme in subfolder test
5ab963b
update assertions for tests
cfea556
fix assertions for tests
3defdb5
update assertions for tests: remove explicitly logging failed results
e765b34
update assertions for tests: remove explicitly logging failed results
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
219 changes: 219 additions & 0 deletions
219
...e/aws/toolkits/jetbrains/uitests/docTests/createReadmeTests/CreateReadmeWorkspacesTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.uitests.docTests.createReadmeTests | ||
|
|
||
| import com.intellij.driver.sdk.ui.ui | ||
| import com.intellij.driver.sdk.waitForProjectOpen | ||
| import com.intellij.ide.starter.ci.CIServer | ||
| import com.intellij.ide.starter.config.ConfigurationStorage | ||
| import com.intellij.ide.starter.di.di | ||
| import com.intellij.ide.starter.driver.engine.runIdeWithDriver | ||
| import com.intellij.ide.starter.ide.IdeProductProvider | ||
| import com.intellij.ide.starter.junit5.hyphenateWithClass | ||
| import com.intellij.ide.starter.models.TestCase | ||
| import com.intellij.ide.starter.project.LocalProjectInfo | ||
| import com.intellij.ide.starter.runner.CurrentTestMethod | ||
| import com.intellij.ide.starter.runner.Starter | ||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.junit.jupiter.api.AfterAll | ||
| import org.junit.jupiter.api.BeforeAll | ||
| import org.junit.jupiter.api.BeforeEach | ||
| import org.junit.jupiter.api.Test | ||
| import org.kodein.di.DI | ||
| import org.kodein.di.bindSingleton | ||
| import software.aws.toolkits.jetbrains.uitests.TestCIServer | ||
| import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile | ||
| import software.aws.toolkits.jetbrains.uitests.docTests.prepTestData | ||
| import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.acceptReadmeTestScript | ||
| import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPostFolderChangeTestScript | ||
| import software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts.createReadmeSubFolderPreFolderChangeTestScript | ||
| import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript | ||
| import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment | ||
| import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest | ||
| import java.awt.event.KeyEvent | ||
| import java.io.File | ||
| import java.nio.file.Path | ||
| import java.nio.file.Paths | ||
|
|
||
| class CreateReadmeWorkspacesTest { | ||
| init { | ||
| di = DI { | ||
| extend(di) | ||
| bindSingleton<CIServer>(overrides = true) { TestCIServer } | ||
| val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply { | ||
| put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString()) | ||
| } | ||
|
|
||
| bindSingleton<ConfigurationStorage>(overrides = true) { | ||
| ConfigurationStorage(this, defaults) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @BeforeEach | ||
| fun setUpTest() { | ||
| // prep test data - remove readme if it exists | ||
| prepTestData(true) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Create readme with single-root workspace, root folder returns a readme`() { | ||
| val testCase = TestCase( | ||
| IdeProductProvider.IC, | ||
| LocalProjectInfo( | ||
| Paths.get("tstData", "qdoc", "createFlow") | ||
| ) | ||
| ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) | ||
|
|
||
| // inject connection | ||
| useExistingConnectionForTest() | ||
|
|
||
| Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { | ||
| System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> | ||
| pluginConfigurator.installPluginFromPath( | ||
| Path.of(path) | ||
| ) | ||
| } | ||
|
|
||
| copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) | ||
| updateGeneralSettings() | ||
| }.runIdeWithDriver() | ||
| .useDriverAndCloseIde { | ||
| waitForProjectOpen() | ||
| // required wait time for the system to be fully ready | ||
| Thread.sleep(30000) | ||
|
|
||
| val readmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") | ||
| val readme = File(readmePath.toUri()) | ||
| assertThat(readme).doesNotExist() | ||
|
|
||
| val result = executePuppeteerScript(acceptReadmeTestScript) | ||
| assertThat(result) | ||
| .doesNotContain("Error: Test Failed") | ||
|
|
||
| val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "README.md") | ||
| val newReadme = File(newReadmePath.toUri()) | ||
| assertThat(newReadme) | ||
| .exists() | ||
| .content() | ||
| .contains("REST", "API") | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `Create readme with single-root workspace, in a subfolder returns a readme`() { | ||
| val testCase = TestCase( | ||
| IdeProductProvider.IC, | ||
| LocalProjectInfo( | ||
| Paths.get("tstData", "qdoc", "createFlow") | ||
| ) | ||
| ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) | ||
|
|
||
| // inject connection | ||
| useExistingConnectionForTest() | ||
|
|
||
| Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { | ||
| System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> | ||
| pluginConfigurator.installPluginFromPath( | ||
| Path.of(path) | ||
| ) | ||
| } | ||
|
|
||
| copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) | ||
| updateGeneralSettings() | ||
| }.runIdeWithDriver() | ||
| .useDriverAndCloseIde { | ||
| waitForProjectOpen() | ||
| // required wait time for the system to be fully ready | ||
| Thread.sleep(30000) | ||
|
|
||
| val readmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md") | ||
| val readme = File(readmePath.toUri()) | ||
| assertThat(readme) | ||
| .doesNotExist() | ||
|
|
||
| val result = executePuppeteerScript(createReadmeSubFolderPreFolderChangeTestScript) | ||
| // Using keyboard press to select a subfolder based on a windows/linux folder selector | ||
| // right to move active cursor to the end | ||
| // enter src as the subfolder name (subfolder name tstData/qdoc/createFlow/src) | ||
| // enter to confirm selected subfolder | ||
| this.ui.robot.pressAndReleaseKey(KeyEvent.VK_RIGHT) | ||
| this.ui.robot.enterText("\\/src") | ||
| this.ui.robot.pressAndReleaseKey(KeyEvent.VK_ENTER) | ||
| val result2 = executePuppeteerScript(createReadmeSubFolderPostFolderChangeTestScript) | ||
|
|
||
| assertThat(result) | ||
| .doesNotContain("Error: Test Failed") | ||
| assertThat(result2) | ||
| .doesNotContain("Error: Test Failed") | ||
|
|
||
| val newReadmePath = Paths.get("tstData", "qdoc", "createFlow", "src", "README.md") | ||
| val newReadme = File(newReadmePath.toUri()) | ||
| assertThat(newReadme) | ||
| .exists() | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `Create readme with multi-root workspace returns a readme`() { | ||
| val testCase = TestCase( | ||
| IdeProductProvider.IC, | ||
| LocalProjectInfo( | ||
| Paths.get("tstData", "qdoc") | ||
| ) | ||
| ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) | ||
|
|
||
| // inject connection | ||
| useExistingConnectionForTest() | ||
|
|
||
| Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { | ||
| System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> | ||
| pluginConfigurator.installPluginFromPath( | ||
| Path.of(path) | ||
| ) | ||
| } | ||
|
|
||
| copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) | ||
| updateGeneralSettings() | ||
| }.runIdeWithDriver() | ||
| .useDriverAndCloseIde { | ||
| waitForProjectOpen() | ||
| // required wait time for the system to be fully ready | ||
| Thread.sleep(30000) | ||
|
|
||
| val readmePath = Paths.get("tstData", "qdoc", "README.md") | ||
| val readme = File(readmePath.toUri()) | ||
| assertThat(readme).doesNotExist() | ||
|
|
||
| val result = executePuppeteerScript(acceptReadmeTestScript) | ||
| assertThat(result) | ||
| .doesNotContain("Error: Test Failed") | ||
|
|
||
| val newReadmePath = Paths.get("tstData", "qdoc", "README.md") | ||
| val newReadme = File(newReadmePath.toUri()) | ||
| assertThat(newReadme) | ||
| .exists() | ||
| .content() | ||
| .contains( | ||
| "REST", | ||
| "API" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| @AfterAll | ||
| fun clearAwsXml() { | ||
| clearAwsXmlFile() | ||
| } | ||
|
|
||
| @JvmStatic | ||
| @BeforeAll | ||
| fun setUp() { | ||
| // Setup test environment | ||
| setupTestEnvironment() | ||
| } | ||
| } | ||
| } | ||
91 changes: 91 additions & 0 deletions
91
...lkits/jetbrains/uitests/docTests/scripts/createReadmeScripts/CreateReadmeSubFolderTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.uitests.docTests.scripts.createReadmeScripts | ||
|
|
||
| import software.aws.toolkits.jetbrains.uitests.findAndClickButtonScript | ||
|
|
||
| // language=JS | ||
| val createReadmeSubFolderPreFolderChangeScript = """ | ||
| const puppeteer = require('puppeteer'); | ||
|
|
||
| async function testNavigation() { | ||
| const browser = await puppeteer.connect({ | ||
| browserURL: 'http://localhost:9222' | ||
| }) | ||
|
|
||
| try { | ||
|
|
||
| const pages = await browser.pages() | ||
|
|
||
| for(const page of pages) { | ||
| const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root')); | ||
|
|
||
| const element = await page.${'$'}('.mynah-chat-prompt-input') | ||
| if(element) { | ||
|
|
||
| console.log('Typing /doc in the chat window') | ||
|
|
||
| await page.type('.mynah-chat-prompt-input', '/doc') | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| console.log('Attempting to find and click Create a README button') | ||
| await findAndClickButton(page, 'Create a README', true, 10000) | ||
| console.log('Attempting to find and click Change folder button to select subfolder') | ||
| await findAndClickButton(page, 'Change folder', true, 10000) | ||
| } | ||
| } | ||
|
|
||
| } finally { | ||
| await browser.close(); | ||
| } | ||
| } | ||
|
|
||
| testNavigation().catch((error) => { | ||
| console.log('Error: Test Failed'); | ||
| console.error(error); | ||
| }); | ||
| """.trimIndent() | ||
|
|
||
| // language=JS | ||
| val createReadmeSubFolderPostFolderChangeScript = """ | ||
| const puppeteer = require('puppeteer'); | ||
|
|
||
| async function testNavigation() { | ||
| const browser = await puppeteer.connect({ | ||
| browserURL: 'http://localhost:9222' | ||
| }) | ||
|
|
||
| try { | ||
|
|
||
| const pages = await browser.pages() | ||
|
|
||
| for(const page of pages) { | ||
| const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root')); | ||
|
|
||
| const element = await page.${'$'}('.mynah-chat-prompt-input') | ||
| if(element) { | ||
| console.log('Attempting to find and click Yes button to confirm option') | ||
| await findAndClickButton(page, 'Yes', true, 10000) | ||
|
|
||
| console.log('Waiting for README to be generated') | ||
| await new Promise(resolve => setTimeout(resolve, 90000)) | ||
|
|
||
| console.log('Attempting to find and click Accept button'); | ||
| await findAndClickButton(page, 'Accept', true, 10000) | ||
| } | ||
| } | ||
|
|
||
| } finally { | ||
| await browser.close(); | ||
| } | ||
| } | ||
|
|
||
| testNavigation().catch((error) => { | ||
| console.log('Error: Test Failed'); | ||
| console.error(error); | ||
| }); | ||
| """.trimIndent() | ||
|
|
||
| val createReadmeSubFolderPreFolderChangeTestScript = createReadmeSubFolderPreFolderChangeScript.plus(findAndClickButtonScript) | ||
| val createReadmeSubFolderPostFolderChangeTestScript = createReadmeSubFolderPostFolderChangeScript.plus(findAndClickButtonScript) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.