feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('登录功能Mock测试', () => {
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('http://localhost:5173/login');
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
test('登录页面 - 应正确显示所有元素', async ({ page }) => {
|
||||
await expect(page.locator('[data-testid="username-input"]')).toBeVisible();
|
||||
await expect(page.locator('[data-testid="password-input"]')).toBeVisible();
|
||||
await expect(page.locator('[data-testid="remember-me"]')).toBeVisible();
|
||||
await expect(page.locator('[data-testid="login-button"]')).toBeVisible();
|
||||
});
|
||||
|
||||
test('登录表单 - 应验证空用户名', async ({ page }) => {
|
||||
await page.fill('[data-testid="password-input"]', 'admin123');
|
||||
await page.click('[data-testid="login-button"]');
|
||||
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
const usernameInput = page.locator('[data-testid="username-input"]');
|
||||
await expect(usernameInput).toBeVisible();
|
||||
});
|
||||
|
||||
test('登录表单 - 应验证空密码', async ({ page }) => {
|
||||
await page.fill('[data-testid="username-input"]', 'admin');
|
||||
await page.click('[data-testid="login-button"]');
|
||||
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
const passwordInput = page.locator('[data-testid="password-input"]');
|
||||
await expect(passwordInput).toBeVisible();
|
||||
});
|
||||
|
||||
test('登录表单 - 应接受有效的输入', async ({ page }) => {
|
||||
await page.fill('[data-testid="username-input"]', 'admin');
|
||||
await page.fill('[data-testid="password-input"]', 'admin123');
|
||||
await page.check('[data-testid="remember-me"]');
|
||||
|
||||
const usernameValue = await page.locator('[data-testid="username-input"]').inputValue();
|
||||
const passwordValue = await page.locator('[data-testid="password-input"]').inputValue();
|
||||
const rememberMeChecked = await page.locator('[data-testid="remember-me"]').isChecked();
|
||||
|
||||
expect(usernameValue).toBe('admin');
|
||||
expect(passwordValue).toBe('admin123');
|
||||
expect(rememberMeChecked).toBe(true);
|
||||
});
|
||||
|
||||
test('登录按钮 - 应有正确的状态', async ({ page }) => {
|
||||
const loginButton = page.locator('[data-testid="login-button"]');
|
||||
|
||||
await expect(loginButton).toBeVisible();
|
||||
await expect(loginButton).toHaveText(/登.*录|Login/i);
|
||||
|
||||
await expect(loginButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test('记住我复选框 - 应可切换状态', async ({ page }) => {
|
||||
const rememberMeCheckbox = page.locator('[data-testid="remember-me"]');
|
||||
|
||||
await expect(rememberMeCheckbox).toBeVisible();
|
||||
|
||||
const initialState = await rememberMeCheckbox.isChecked();
|
||||
expect(initialState).toBe(false);
|
||||
|
||||
await rememberMeCheckbox.check();
|
||||
const checkedState = await rememberMeCheckbox.isChecked();
|
||||
expect(checkedState).toBe(true);
|
||||
|
||||
await rememberMeCheckbox.uncheck();
|
||||
const uncheckedState = await rememberMeCheckbox.isChecked();
|
||||
expect(uncheckedState).toBe(false);
|
||||
});
|
||||
|
||||
test('输入框 - 应支持输入和清除', async ({ page }) => {
|
||||
const usernameInput = page.locator('[data-testid="username-input"]');
|
||||
|
||||
await usernameInput.fill('testuser');
|
||||
const filledValue = await usernameInput.inputValue();
|
||||
expect(filledValue).toBe('testuser');
|
||||
|
||||
await usernameInput.clear();
|
||||
const clearedValue = await usernameInput.inputValue();
|
||||
expect(clearedValue).toBe('');
|
||||
});
|
||||
|
||||
test('页面标题 - 应显示正确的文本', async ({ page }) => {
|
||||
const title = await page.title();
|
||||
expect(title).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user