Skip to content

Commit 284d855

Browse files
authored
Translate UT for UI (opea-project#423)
Signed-off-by: Yue, Wenjiao <wenjiao.yue@intel.com>
1 parent 290a74f commit 284d855

File tree

6 files changed

+96
-1
lines changed

6 files changed

+96
-1
lines changed

Translation/docker/ui/svelte/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^4.0.0"
1515
},
1616
"devDependencies": {
17-
"@playwright/test": "^1.44.1",
17+
"@playwright/test": "^1.45.2",
1818
"@sveltejs/adapter-auto": "^3.0.0",
1919
"@sveltejs/kit": "^2.0.0",
2020
"@sveltejs/package": "^2.0.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { defineConfig, devices } from "@playwright/test";
5+
6+
/**
7+
* Read environment variables from file.
8+
* https://github.com/motdotla/dotenv
9+
*/
10+
// require('dotenv').config();
11+
12+
/**
13+
* See https://playwright.dev/docs/test-configuration.
14+
*/
15+
export default defineConfig({
16+
testDir: "./tests",
17+
/* Maximum time one test can run for. */
18+
timeout: 30 * 1000,
19+
expect: {
20+
/**
21+
* Maximum time expect() should wait for the condition to be met.
22+
* For example in `await expect(locator).toHaveText();`
23+
*/
24+
timeout: 5000,
25+
},
26+
/* Run tests in files in parallel */
27+
fullyParallel: true,
28+
/* Fail the build on CI if you accidentally left test.only in the source code. */
29+
forbidOnly: !!process.env.CI,
30+
/* Retry on CI only */
31+
retries: process.env.CI ? 2 : 0,
32+
/* Opt out of parallel tests on CI. */
33+
workers: process.env.CI ? 1 : undefined,
34+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
35+
reporter: [["html", { open: "never" }]],
36+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
37+
use: {
38+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
39+
actionTimeout: 0,
40+
/* Base URL to use in actions like `await page.goto('/')`. */
41+
baseURL: "http://localhost:5173",
42+
43+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
44+
trace: "on-first-retry",
45+
},
46+
47+
/* Configure projects for major browsers */
48+
projects: [
49+
{
50+
name: "webkit",
51+
use: { ...devices["Desktop Safari"] },
52+
},
53+
],
54+
});

Translation/docker/ui/svelte/src/routes/+page.svelte

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
rows="25"
129129
placeholder="Input"
130130
bind:value={input}
131+
data-testid="translate-input"
132+
131133
/>
132134
<textarea
133135
readonly
@@ -137,6 +139,7 @@
137139
rows="25"
138140
placeholder="Translation"
139141
bind:value={output}
142+
data-testid="translate-output"
140143
/>
141144
</div>
142145
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { test, expect, type Page } from "@playwright/test";
5+
6+
// Initialization before each test
7+
test.beforeEach(async ({ page }) => {
8+
await page.goto("/");
9+
});
10+
11+
// Constants definition
12+
const TRANSLATE_ITEMS = ["hello"];
13+
14+
// Helper function: Enter message to chat
15+
async function enterMessageToChat(page: Page, message: string) {
16+
await page.getByTestId("translate-input").click();
17+
await page.getByTestId("translate-input").fill(message);
18+
await page.waitForTimeout(10000);
19+
const outputText = await page.getByTestId("translate-output").inputValue();
20+
console.log("Actual text:", outputText);
21+
await expect(page.getByTestId("translate-output")).not.toHaveValue("");
22+
}
23+
24+
// Test description: New Doc Summary
25+
test.describe("New Translation", () => {
26+
// Test: Enter message to summary
27+
test("should enter message to translate", async ({ page }) => {
28+
await enterMessageToChat(page, TRANSLATE_ITEMS[0]);
29+
});
30+
});

Translation/tests/test_translation_on_gaudi.sh

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function start_services() {
3535
export LLM_SERVICE_HOST_IP=${ip_address}
3636
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:8888/v1/translation"
3737

38+
sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env
39+
3840
if [[ "$IMAGE_REPO" != "" ]]; then
3941
# Replace the container name with a test-specific name
4042
echo "using image repository $IMAGE_REPO and image tag $IMAGE_TAG"
@@ -151,6 +153,7 @@ function main() {
151153

152154
validate_microservices
153155
validate_megaservice
156+
validate_frontend
154157

155158
stop_docker
156159
echo y | docker system prune

Translation/tests/test_translation_on_xeon.sh

+5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ function build_docker_images() {
1212
cd $WORKPATH
1313
git clone https://github.com/opea-project/GenAIComps.git
1414
cd GenAIComps
15+
1516
docker build --no-cache -t opea/llm-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/llms/text-generation/tgi/Dockerfile .
1617

1718
cd $WORKPATH/docker
1819
docker build --no-cache -t opea/translation:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile .
1920

2021
cd $WORKPATH/docker/ui
2122
docker build --no-cache -t opea/translation-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f docker/Dockerfile .
23+
2224
docker images
2325
}
2426

@@ -32,6 +34,8 @@ function start_services() {
3234
export LLM_SERVICE_HOST_IP=${ip_address}
3335
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:8888/v1/translation"
3436

37+
sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env
38+
3539
if [[ "$IMAGE_REPO" != "" ]]; then
3640
# Replace the container name with a test-specific name
3741
echo "using image repository $IMAGE_REPO and image tag $IMAGE_TAG"
@@ -146,6 +150,7 @@ function main() {
146150

147151
validate_microservices
148152
validate_megaservice
153+
validate_frontend
149154

150155
stop_docker
151156
echo y | docker system prune

0 commit comments

Comments
 (0)