Skip to content

Commit 1daf71b

Browse files
authored
chore(test): Extend playground test (#2952)
* test: test Signed-off-by: Anton Misskii <[email protected]> * chore(test): extend playground test Signed-off-by: Anton Misskii <[email protected]> * fix: fix Signed-off-by: Anton Misskii <[email protected]> * fix: fix Signed-off-by: Anton Misskii <[email protected]> * test: test Signed-off-by: Anton Misskii <[email protected]> * chore: get assistant message by index Signed-off-by: Anton Misskii <[email protected]> --------- Signed-off-by: Anton Misskii <[email protected]>
1 parent 9d598a3 commit 1daf71b

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

packages/frontend/src/lib/conversation/ChatMessage.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function getMessageParagraphs(message: ChatMessage): string[] {
2929
{roles[message.role]}
3030
</div>
3131
<div
32+
aria-label={`${roles[message.role]} message`}
3233
class="p-4 rounded-md text-[var(--pd-content-card-text)]"
3334
class:bg-[var(--pd-content-card-bg)]={isUserChat(message)}
3435
class:bg-[var(--pd-content-bg)]={isSystemPrompt(message)}

tests/playwright/src/ai-lab-extension.spec.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import type { Page } from '@playwright/test';
19+
import type { Locator, Page } from '@playwright/test';
2020
import type { NavigationBar, ExtensionsPage } from '@podman-desktop/tests-playwright';
2121
import {
2222
expect as playExpect,
@@ -350,13 +350,15 @@ test.describe.serial(`AI Lab extension installation and verification`, () => {
350350
});
351351
});
352352

353-
['instructlab/granite-7b-lab-GGUF'].forEach(modelName => {
353+
['lmstudio-community/granite-3.0-8b-instruct-GGUF'].forEach(modelName => {
354354
test.describe.serial(`AI Lab playground creation and deletion`, () => {
355355
let catalogPage: AILabCatalogPage;
356356
let playgroundsPage: AILabPlaygroundsPage;
357357
let playgroundDetailsPage: AILabPlaygroundDetailsPage;
358+
let assistantResponse: Locator;
358359

359360
const playgroundName = 'test playground';
361+
const systemPrompt = 'Always respond with: "Hello, I am Chat Bot"';
360362

361363
test.beforeAll(`Open AI Lab Catalog`, async ({ runner, page, navigationBar }) => {
362364
[page, webview] = await handleWebview(runner, page, navigationBar);
@@ -402,9 +404,17 @@ test.describe.serial(`AI Lab extension installation and verification`, () => {
402404
await playExpect(playgroundDetailsPage.deletePlaygroundButton).toBeEnabled();
403405
});
404406

405-
test(`Define prompt for ${modelName}`, async () => {
406-
const prompt = 'Hello, how are you?';
407-
await playgroundDetailsPage.definePrompt(prompt);
407+
test('Set system prompt, submit user input, and verify assistant response is visible', async () => {
408+
test.setTimeout(100_000);
409+
await playgroundDetailsPage.defineSystemPrompt(systemPrompt);
410+
await playgroundDetailsPage.submitUserInput('Hello');
411+
// Get the first assistant response
412+
assistantResponse = await playgroundDetailsPage.getAssistantResponse(0);
413+
await playExpect(assistantResponse).toBeVisible();
414+
});
415+
416+
test('Verify assistant response contains the expected system prompt', async () => {
417+
playExpect(await assistantResponse.innerText()).toContain('Hello, I am Chat Bot');
408418
});
409419

410420
test(`Delete AI Lab playground for ${modelName}`, async () => {

tests/playwright/src/model/ai-lab-playground-details-page.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export class AILabPlaygroundDetailsPage extends AILabBasePage {
3131
readonly temperatureSliderLocator: Locator;
3232
readonly maxTokensSliderLocator: Locator;
3333
readonly topPSliderLocator: Locator;
34-
readonly promptTextAreaLoctor: Locator;
34+
readonly systemPromptTextAreaLocator: Locator;
3535
readonly clearSystemPromptButtonLocator: Locator;
3636
readonly editSystemPromptButtonLocator: Locator;
37+
readonly promptTextAreaLocator: Locator;
38+
readonly sendPromptButton: Locator;
3739

3840
constructor(page: Page, webview: Page, playgroundName: string) {
3941
super(page, webview, playgroundName);
@@ -46,24 +48,26 @@ export class AILabPlaygroundDetailsPage extends AILabBasePage {
4648
this.temperatureSliderLocator = this.parametersSectionLocator.getByLabel('temperature slider', { exact: true });
4749
this.maxTokensSliderLocator = this.parametersSectionLocator.getByLabel('max tokens slider', { exact: true });
4850
this.topPSliderLocator = this.parametersSectionLocator.getByLabel('top-p slider', { exact: true });
49-
this.promptTextAreaLoctor = this.conversationSectionLocator.getByLabel('system-prompt-textarea');
51+
this.systemPromptTextAreaLocator = this.conversationSectionLocator.getByLabel('system-prompt-textarea');
5052
this.clearSystemPromptButtonLocator = this.conversationSectionLocator.getByTitle('Clear', { exact: true });
5153
this.editSystemPromptButtonLocator = this.conversationSectionLocator.getByTitle('Edit system prompt', {
5254
exact: true,
5355
});
56+
this.promptTextAreaLocator = this.webview.getByLabel('prompt', { exact: true });
57+
this.sendPromptButton = this.webview.getByRole('button', { name: 'Send prompt' });
5458
}
5559

5660
async waitForLoad(): Promise<void> {
5761
await playExpect(this.heading).toBeVisible();
5862
}
5963

60-
async definePrompt(prompt: string): Promise<void> {
64+
async defineSystemPrompt(systemPrompt: string): Promise<void> {
6165
await playExpect(this.editSystemPromptButtonLocator).toBeVisible();
6266
await this.editSystemPromptButtonLocator.click();
63-
await playExpect(this.promptTextAreaLoctor).toBeVisible();
64-
await this.promptTextAreaLoctor.fill(prompt);
67+
await playExpect(this.systemPromptTextAreaLocator).toBeVisible();
68+
await this.systemPromptTextAreaLocator.fill(systemPrompt);
6569
await this.editSystemPromptButtonLocator.click();
66-
await playExpect(this.promptTextAreaLoctor).not.toBeVisible();
70+
await playExpect(this.systemPromptTextAreaLocator).not.toBeVisible();
6771
}
6872

6973
async deletePlayground(): Promise<AILabPlaygroundsPage> {
@@ -72,4 +76,17 @@ export class AILabPlaygroundDetailsPage extends AILabBasePage {
7276
await handleConfirmationDialog(this.page, 'Podman AI Lab', true, 'Confirm');
7377
return new AILabPlaygroundsPage(this.page, this.webview);
7478
}
79+
80+
async submitUserInput(prompt: string): Promise<void> {
81+
await this.promptTextAreaLocator.fill(prompt);
82+
await playExpect(this.promptTextAreaLocator).toHaveValue(prompt);
83+
await playExpect(this.sendPromptButton).toBeEnabled({ timeout: 30_000 });
84+
await this.sendPromptButton.click();
85+
}
86+
87+
async getAssistantResponse(index: number): Promise<Locator> {
88+
await playExpect(this.sendPromptButton).toBeVisible({ timeout: 100_000 });
89+
const assistantResponse = this.conversationSectionLocator.getByLabel('Assistant message').nth(index);
90+
return assistantResponse;
91+
}
7592
}

0 commit comments

Comments
 (0)