|
| 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.transformTests |
| 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.assertTrue |
| 19 | +import org.junit.jupiter.api.BeforeEach |
| 20 | +import org.junit.jupiter.api.Test |
| 21 | +import org.kodein.di.DI |
| 22 | +import org.kodein.di.bindSingleton |
| 23 | +import software.aws.toolkits.jetbrains.uitests.TestCIServer |
| 24 | +import software.aws.toolkits.jetbrains.uitests.clearAwsXmlFile |
| 25 | +import software.aws.toolkits.jetbrains.uitests.executePuppeteerScript |
| 26 | +import software.aws.toolkits.jetbrains.uitests.setupTestEnvironment |
| 27 | +import software.aws.toolkits.jetbrains.uitests.useExistingConnectionForTest |
| 28 | +import java.io.File |
| 29 | +import java.nio.file.Path |
| 30 | +import java.nio.file.Paths |
| 31 | + |
| 32 | +// language=JS |
| 33 | +val transformHappyPathScript = """ |
| 34 | +const puppeteer = require('puppeteer'); |
| 35 | +async function testNavigation() { |
| 36 | + const browser = await puppeteer.connect({ |
| 37 | + browserURL: "http://localhost:9222" |
| 38 | + }) |
| 39 | + try { |
| 40 | + const pages = await browser.pages() |
| 41 | + for (const page of pages) { |
| 42 | + await page.type('.mynah-chat-prompt-input', '/transform') |
| 43 | + await page.keyboard.press('Enter') |
| 44 | + |
| 45 | + await page.waitForSelector('.mynah-chat-item-form-items-container', { |
| 46 | + timeout: 5000 |
| 47 | + }) |
| 48 | + const formInputs = await page.$$('.mynah-form-input-wrapper') |
| 49 | + |
| 50 | + const moduleLabel = await formInputs[0].evaluate( |
| 51 | + element => element.querySelector('.mynah-ui-form-item-mandatory-title').textContent |
| 52 | + ) |
| 53 | + console.log('Module selection label:', moduleLabel) |
| 54 | + |
| 55 | + const versionLabel = await formInputs[1].evaluate( |
| 56 | + element => element.querySelector('.mynah-ui-form-item-mandatory-title').textContent |
| 57 | + ) |
| 58 | + console.log('Version selection label:', versionLabel) |
| 59 | + |
| 60 | + await page.evaluate(() => { |
| 61 | + const button = document.querySelector('button[action-id="codetransform-input-confirm"]') |
| 62 | + button.click() |
| 63 | + }) |
| 64 | + |
| 65 | + const skipTestsForm = await page.waitForSelector('button[action-id="codetransform-input-confirm-skip-tests"]', { |
| 66 | + timeout: 5000 |
| 67 | + }) |
| 68 | + console.log('Skip tests form appeared:', skipTestsForm !== null) |
| 69 | + |
| 70 | + await page.evaluate(() => { |
| 71 | + const button = document.querySelector('button[action-id="codetransform-input-confirm-skip-tests"]') |
| 72 | + button.click() |
| 73 | + }) |
| 74 | + |
| 75 | + const oneOrMultipleDiffsForm = await page.waitForSelector('button[action-id="codetransform-input-confirm-one-or-multiple-diffs"]', { |
| 76 | + timeout: 5000 |
| 77 | + }) |
| 78 | + console.log('One or multiple diffs form appeared:', oneOrMultipleDiffsForm !== null) |
| 79 | + |
| 80 | + await page.evaluate(() => { |
| 81 | + const button = document.querySelector('button[action-id="codetransform-input-confirm-one-or-multiple-diffs"]') |
| 82 | + button.click() |
| 83 | + }) |
| 84 | + |
| 85 | + const errorMessage = await page.waitForSelector('text/Sorry, I couldn\'t run the Maven clean install command', { |
| 86 | + timeout: 5000 |
| 87 | + }) |
| 88 | + console.log('Error message:', await errorMessage.evaluate(el => el.textContent)) |
| 89 | + } |
| 90 | + } finally { |
| 91 | + await browser.close() |
| 92 | + } |
| 93 | +} |
| 94 | +testNavigation().catch(console.error) |
| 95 | +
|
| 96 | +""".trimIndent() |
| 97 | + |
| 98 | +class TransformChatTest { |
| 99 | + |
| 100 | + init { |
| 101 | + di = DI { |
| 102 | + extend(di) |
| 103 | + bindSingleton<CIServer>(overrides = true) { TestCIServer } |
| 104 | + val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply { |
| 105 | + put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString()) |
| 106 | + } |
| 107 | + |
| 108 | + bindSingleton<ConfigurationStorage>(overrides = true) { |
| 109 | + ConfigurationStorage(this, defaults) |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + @BeforeEach |
| 115 | + fun setUp() { |
| 116 | + setupTestEnvironment() |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + fun `can run a transformation from the chat`() { |
| 121 | + val testCase = TestCase( |
| 122 | + IdeProductProvider.IC, |
| 123 | + LocalProjectInfo( |
| 124 | + Paths.get("tstData", "Hello") |
| 125 | + ) |
| 126 | + ).useRelease(System.getProperty("org.gradle.project.ideProfileName")) |
| 127 | + |
| 128 | + // inject connection |
| 129 | + useExistingConnectionForTest() |
| 130 | + |
| 131 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 132 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 133 | + pluginConfigurator.installPluginFromPath( |
| 134 | + Path.of(path) |
| 135 | + ) |
| 136 | + } |
| 137 | + |
| 138 | + copyExistingConfig(Paths.get("tstData", "configAmazonQTests")) |
| 139 | + updateGeneralSettings() |
| 140 | + }.runIdeWithDriver() |
| 141 | + .useDriverAndCloseIde { |
| 142 | + waitForProjectOpen() |
| 143 | + // required wait time for the system to be fully ready |
| 144 | + Thread.sleep(30000) |
| 145 | + val result = executePuppeteerScript(transformHappyPathScript) |
| 146 | + assertTrue(result.contains("Choose a module to transform")) |
| 147 | + assertTrue(result.contains("Choose the target code version")) |
| 148 | + assertTrue(result.contains("Skip tests form appeared: true")) |
| 149 | + assertTrue(result.contains("One or multiple diffs form appeared: true")) |
| 150 | + assertTrue(result.contains("couldn't run the Maven clean install command")) |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + companion object { |
| 155 | + @JvmStatic |
| 156 | + @AfterAll |
| 157 | + fun clearAwsXml() { |
| 158 | + clearAwsXmlFile() |
| 159 | + } |
| 160 | + } |
| 161 | +} |
0 commit comments