-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): create playwground e2e test
Signed-off-by: Vladimir Lazar <vlazar@redhat.com>
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,76 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import type { Locator, Page } from '@playwright/test'; | ||
import { expect as playExpect } from '@playwright/test'; | ||
import { AILabBasePage } from './ai-lab-base-page'; | ||
import { handleConfirmationDialog } from '@podman-desktop/tests-playwright'; | ||
|
||
export class AILabPlaygroundsPage extends AILabBasePage { | ||
readonly additionalActions: Locator; | ||
readonly newPlaygroundButton: Locator; | ||
readonly playgroundNameInput: Locator; | ||
readonly createPlaygroundButton: Locator; | ||
|
||
constructor(page: Page, webview: Page) { | ||
super(page, webview, 'Playground Environments'); | ||
this.additionalActions = this.webview.getByRole('group', { name: 'additionalActions' }); | ||
this.newPlaygroundButton = this.additionalActions.getByRole('button', { name: 'New Playground', exact: true }); | ||
this.playgroundNameInput = this.webview.getByRole('textbox', { name: 'playgroundName' }); | ||
this.createPlaygroundButton = this.webview.getByRole('button', { name: 'Create playground', exact: true }); | ||
} | ||
|
||
async waitForLoad(): Promise<void> { | ||
await playExpect(this.heading).toBeVisible(); | ||
} | ||
|
||
async createNewPlayground(name: string): Promise<this> { | ||
await playExpect(this.newPlaygroundButton).toBeEnabled(); | ||
await this.newPlaygroundButton.click(); | ||
await playExpect(this.playgroundNameInput).toBeVisible(); | ||
await this.playgroundNameInput.fill(name); | ||
await playExpect(this.playgroundNameInput).toHaveValue(name); | ||
await playExpect(this.createPlaygroundButton).toBeEnabled(); | ||
await this.createPlaygroundButton.click(); | ||
return this; | ||
} | ||
|
||
async deletePlayground(playgroundName: string): Promise<this> { | ||
const playgroundRow = await this.getPlaygroundRowByName(playgroundName); | ||
if (!playgroundRow) { | ||
throw new Error(`Playground ${playgroundName} not found`); | ||
} | ||
const deleteButton = playgroundRow.getByRole('button', { name: 'Delete conversation', exact: true }); | ||
await playExpect(deleteButton).toBeEnabled(); | ||
await deleteButton.click(); | ||
await handleConfirmationDialog(this.page, 'Podman AI Lab', true, 'Confirm'); | ||
return this; | ||
} | ||
|
||
async doesPlaygroundExist(playgroundName: string): Promise<boolean> { | ||
return (await this.getPlaygroundRowByName(playgroundName)) !== undefined; | ||
} | ||
|
||
private async getPlaygroundRowByName(playgroundName: string): Promise<Locator | undefined> { | ||
const row = this.webview.getByRole('row', { name: playgroundName, exact: true }); | ||
if ((await row.count()) > 0) { | ||
return row; | ||
} | ||
return undefined; | ||
} | ||
} |