Skip to content

Commit 30f9b7e

Browse files
committed
add e2e test for reject case
1 parent 4eaa965 commit 30f9b7e

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

ui-tests-starter/tst-243+/software/aws/toolkits/jetbrains/uitests/testTests/QTestGenerationChatTest.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,40 @@ class QTestGenerationChatTest {
180180
}
181181
}
182182

183+
@Test
184+
fun `test reject path from the chat`() {
185+
val testCase = TestCase(
186+
IdeProductProvider.IC,
187+
LocalProjectInfo(
188+
Paths.get("tstData", "qTestGenerationTestProject/")
189+
)
190+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
191+
192+
// inject connection
193+
useExistingConnectionForTest()
194+
195+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
196+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
197+
pluginConfigurator.installPluginFromPath(
198+
Path.of(path)
199+
)
200+
}
201+
202+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
203+
updateGeneralSettings()
204+
}.runIdeWithDriver()
205+
.useDriverAndCloseIde {
206+
waitForProjectOpen()
207+
openFile(Paths.get("testModule2", "UnSupportedLanguage.kt").toString())
208+
Thread.sleep(30000)
209+
val result = executePuppeteerScript(testRejectPathScript)
210+
assertTrue(result.contains("new tab opened"))
211+
assertTrue(result.contains("View Diff opened"))
212+
assertTrue(result.contains("Result Reject"))
213+
assertTrue(result.contains("Unit test generation completed."))
214+
}
215+
}
216+
183217
companion object {
184218
@JvmStatic
185219
@AfterAll

ui-tests-starter/tst-243+/software/aws/toolkits/jetbrains/uitests/testTests/QTestGenerationChatTestScripts.kt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,101 @@ val unsupportedLanguagePath = """
327327
}
328328
testNavigation().catch(console.error);
329329
""".trimIndent()
330+
331+
val testRejectPathScript = """
332+
const puppeteer = require('puppeteer');
333+
async function testNavigation() {
334+
const browser = await puppeteer.connect({
335+
browserURL: "http://localhost:9222"
336+
})
337+
try {
338+
const pages = await browser.pages()
339+
for(const page of pages) {
340+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
341+
const element = await page.${'$'}('.mynah-chat-prompt-input')
342+
if(element) {
343+
const elements = await page.${'$'}${'$'}('.mynah-chat-command-selector-command');
344+
const attr = await Promise.all(
345+
elements.map(elem => elem.evaluate(el => el.getAttribute('command')))
346+
);
347+
await page.type('.mynah-chat-prompt-input', '/test')
348+
await page.keyboard.press('Enter');
349+
await page.keyboard.press('Enter');
350+
try {
351+
await waitForElementWithText(page, "Q - Test")
352+
console.log("new tab opened")
353+
await page.waitForFunction(
354+
() => {
355+
const button = document.querySelector('button[action-id="utg_view_diff"]');
356+
return button && button.isEnabled !== false && button.disabled !== true;
357+
},
358+
{ timeout: 300000 }
359+
);
360+
await page.evaluate(() => {
361+
const button = document.querySelector('button[action-id="utg_view_diff"]');
362+
if (button) {
363+
button.click();
364+
} else {
365+
throw new Error('Button not found after waiting');
366+
}
367+
});
368+
console.log("View Diff opened")
369+
await page.waitForFunction(
370+
() => {
371+
const button = document.querySelector('button[action-id="utg_reject"]');
372+
return button && button.isEnabled !== false && button.disabled !== true;
373+
},
374+
{ timeout: 300000 }
375+
);
376+
await page.evaluate(() => {
377+
const button = document.querySelector('button[action-id="utg_reject"]');
378+
if (button) {
379+
button.click();
380+
} else {
381+
throw new Error('Accept button not found after waiting');
382+
}
383+
});
384+
console.log("Result Reject")
385+
await waitForElementWithText(page, "Unit test generation completed.")
386+
console.log("Unit test generation completed.")
387+
} catch (e) {
388+
console.log("Element with text not found")
389+
console.log(e)
390+
throw e
391+
}
392+
393+
}
394+
}
395+
} finally {
396+
await browser.close();
397+
}
398+
}
399+
400+
async function waitForElementWithText(page, text) {
401+
await page.waitForFunction(
402+
(expectedText) => {
403+
const elements = document.querySelectorAll('*');
404+
return Array.from(elements).find(element =>
405+
element.textContent?.trim() === expectedText
406+
);
407+
},
408+
{},
409+
text
410+
);
411+
}
412+
413+
async function waitAndGetElementByText(page, text) {
414+
const element = await page.waitForFunction(
415+
(expectedText) => {
416+
const elements = document.querySelectorAll('*');
417+
return Array.from(elements).find(element =>
418+
element.textContent?.trim() === expectedText
419+
);
420+
},
421+
{},
422+
text
423+
);
424+
return element;
425+
}
426+
testNavigation().catch(console.error);
427+
""".trimIndent()

0 commit comments

Comments
 (0)