mirror of https://github.com/msgbyte/tailchat
test: basic e2e usercase
parent
854bac53ea
commit
747ac33f7b
@ -1,3 +1,4 @@
|
||||
node_modules/
|
||||
test-results/
|
||||
playwright-report/
|
||||
auth.json
|
||||
|
@ -0,0 +1,39 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/');
|
||||
});
|
||||
|
||||
test.describe('entry page', () => {
|
||||
test('should auto jump to entry page', async ({ page }) => {
|
||||
await expect(page).toHaveURL('/entry/login');
|
||||
});
|
||||
|
||||
test('auto goto entry if not login', async ({ page }) => {
|
||||
await page.goto('/main');
|
||||
await expect(page).toHaveURL('/entry/login?redirect=%2Fmain'); // should with redirect
|
||||
});
|
||||
|
||||
test('registry', async ({ page }) => {
|
||||
await page.locator('text=注册账号').click();
|
||||
await expect(page).toHaveURL('/entry/register');
|
||||
|
||||
await page.locator('button:has-text("注册账号")').click();
|
||||
await expect(page.locator('p.text-red-500')).toHaveText('邮箱不能为空');
|
||||
|
||||
await page.locator('[name="reg-email"]').click();
|
||||
await page.locator('[name="reg-email"]').fill('123456789');
|
||||
await page.locator('button:has-text("注册账号")').click();
|
||||
await expect(page.locator('p.text-red-500')).toHaveText('邮箱格式不正确');
|
||||
|
||||
await page.locator('[name="reg-email"]').click();
|
||||
await page.locator('[name="reg-email"]').fill('test@moonrailgun.com');
|
||||
await page.locator('button:has-text("注册账号")').click();
|
||||
await expect(page.locator('p.text-red-500')).toHaveText('密码不能低于6位');
|
||||
|
||||
await page.locator('[name="reg-password"]').click();
|
||||
await page.locator('[name="reg-password"]').fill('1234');
|
||||
await page.locator('button:has-text("注册账号")').click();
|
||||
await expect(page.locator('p.text-red-500')).toHaveText('密码不能低于6位');
|
||||
});
|
||||
});
|
@ -0,0 +1,12 @@
|
||||
import { loginToDemoUser } from './utils/user';
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.beforeEach(async ({ page, context }) => {
|
||||
await loginToDemoUser(page, context);
|
||||
});
|
||||
|
||||
test.describe('Main Process', () => {
|
||||
test('Check Personal Route', () => {
|
||||
console.log('TODO');
|
||||
});
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
import { BrowserContext, expect, Page } from '@playwright/test';
|
||||
|
||||
const storagePath = './auth.json';
|
||||
|
||||
/**
|
||||
* 登录到测试账号
|
||||
*
|
||||
* 需要提前注册
|
||||
*/
|
||||
export async function loginToDemoUser(page: Page, context: BrowserContext) {
|
||||
await page.goto('/entry/login');
|
||||
await page
|
||||
.locator('input[name="login-email"]')
|
||||
.fill('tailchat-demo@msgbyte.com');
|
||||
await page.locator('input[name="login-password"]').fill('tailchat-demo');
|
||||
await page.locator('button:has-text("登录")').click();
|
||||
|
||||
await expect(page).toHaveURL('/main/personal/friends'); // should with redirect
|
||||
|
||||
await context.storageState({
|
||||
path: storagePath,
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue