feat(server): add real-world prompt test for copilot apis (#8629)

fix AF-1432, PD-1176
This commit is contained in:
darkskygit
2024-11-01 07:05:12 +00:00
parent 1c22fdd371
commit 7a201984e9
32 changed files with 1928 additions and 58 deletions

View File

@@ -150,6 +150,68 @@ export async function createRandomUser(): Promise<{
} as any;
}
export async function createRandomAIUser(): Promise<{
name: string;
email: string;
password: string;
id: string;
}> {
const user = {
name: faker.internet.userName(),
email: faker.internet.email().toLowerCase(),
password: '123456',
};
const result = await runPrisma(async client => {
const freeFeatureId = await client.feature
.findFirst({
where: { feature: 'free_plan_v1' },
select: { id: true },
orderBy: { version: 'desc' },
})
.then(f => f!.id);
const aiFeatureId = await client.feature
.findFirst({
where: { feature: 'unlimited_copilot' },
select: { id: true },
orderBy: { version: 'desc' },
})
.then(f => f!.id);
await client.user.create({
data: {
...user,
emailVerifiedAt: new Date(),
password: await hash(user.password),
features: {
create: [
{
reason: 'created by test case',
activated: true,
featureId: freeFeatureId,
},
{
reason: 'created by test case',
activated: true,
featureId: aiFeatureId,
},
],
},
},
});
return await client.user.findUnique({
where: {
email: user.email,
},
});
});
cloudUserSchema.parse(result);
return {
...result,
password: user.password,
} as any;
}
export async function deleteUser(email: string) {
await runPrisma(async client => {
await client.user.delete({
@@ -178,7 +240,24 @@ export async function loginUser(
}
await clickSideBarCurrentWorkspaceBanner(page);
await page.getByTestId('cloud-signin-button').click();
await page.getByTestId('cloud-signin-button').click({
delay: 200,
});
await loginUserDirectly(page, user, config);
}
export async function loginUserDirectly(
page: Page,
user: {
email: string;
password: string;
},
config?: {
isElectron?: boolean;
beforeLogin?: () => Promise<void>;
afterLogin?: () => Promise<void>;
}
) {
await page.getByPlaceholder('Enter your email address').fill(user.email);
await page.getByTestId('continue-login-button').click({
delay: 200,
@@ -188,8 +267,10 @@ export async function loginUser(
await config.beforeLogin();
}
await page.waitForTimeout(200);
await page.getByTestId('sign-in-button').click();
await page.waitForTimeout(500);
const signIn = page.getByTestId('sign-in-button');
await signIn.click();
await signIn.waitFor({ state: 'detached' });
await page.waitForTimeout(200);
if (config?.afterLogin) {
await config.afterLogin();
}

View File

@@ -1,7 +1,11 @@
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
export const coreUrl = 'http://localhost:8080';
export let coreUrl = 'http://localhost:8080';
export function setCoreUrl(url: string) {
coreUrl = url;
}
export async function openHomePage(page: Page) {
await page.goto(coreUrl);

View File

@@ -1,6 +1,24 @@
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';
export function getAllPage(page: Page) {
const newPageButton = page.getByTestId('new-page-button-trigger');
const newPageDropdown = newPageButton.locator('svg');
const edgelessBlockCard = page.getByTestId('new-edgeless-button-in-all-page');
async function clickNewPageButton() {
const newPageButton = page.getByTestId('new-page-button-trigger');
return await newPageButton.click();
}
async function clickNewEdgelessDropdown() {
await newPageDropdown.click();
await edgelessBlockCard.click();
}
return { clickNewPageButton, clickNewEdgelessDropdown };
}
export async function waitForEditorLoad(page: Page) {
await page.waitForSelector('v-line', {
timeout: 20000,