feat(mobile): 区分移动端token存储键名并添加Playwright测试

修改mobile端token存储键名为'mobile_token'以区分不同客户端
添加Playwright测试套件用于知识库管理功能测试
更新.gitignore忽略node_modules和test-results目录
This commit is contained in:
yourname
2025-05-06 06:24:04 +00:00
parent fb00382b8d
commit f158ff6ff5
6 changed files with 147 additions and 1 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
.aider*
node_modules
test-results

View File

@@ -27,7 +27,7 @@ const ThemeContext = createContext<ThemeContextType | null>(null);
// 认证提供者组件
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [user, setUser] = useState<User | null>(null);
const [token, setToken] = useState<string | null>(getLocalStorageWithExpiry('token'));
const [token, setToken] = useState<string | null>(getLocalStorageWithExpiry('mobile_token'));
const [isAuthenticated, setIsAuthenticated] = useState(false);
const queryClient = useQueryClient();

75
test/package-lock.json generated Normal file
View File

@@ -0,0 +1,75 @@
{
"name": "test",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "test",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@playwright/test": "1.51.1"
}
},
"node_modules/@playwright/test": {
"version": "1.51.1",
"resolved": "https://registry.npmmirror.com/@playwright/test/-/test-1.51.1.tgz",
"integrity": "sha512-nM+kEaTSAoVlXmMPH10017vn3FSiFqr/bh4fKg9vmAdMfd9SDqRZNvPSiAHADc/itWak+qPvMPZQOPwCBW7k7Q==",
"license": "Apache-2.0",
"dependencies": {
"playwright": "1.51.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=18"
}
},
"node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/playwright": {
"version": "1.51.1",
"resolved": "https://registry.npmmirror.com/playwright/-/playwright-1.51.1.tgz",
"integrity": "sha512-kkx+MB2KQRkyxjYPc3a0wLZZoDczmppyGJIvQ43l+aZihkaVvmu/21kiyaHeHjiFxjxNNFnUncKmcGIyOojsaw==",
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.51.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=18"
},
"optionalDependencies": {
"fsevents": "2.3.2"
}
},
"node_modules/playwright-core": {
"version": "1.51.1",
"resolved": "https://registry.npmmirror.com/playwright-core/-/playwright-core-1.51.1.tgz",
"integrity": "sha512-/crRMj8+j/Nq5s8QcvegseuyeZPxpQCZb6HNk3Sos3BlZyAknRjoyJPFWkpNn8v0+P3WiwqFF8P+zQo4eqiNuw==",
"license": "Apache-2.0",
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=18"
}
}
}
}

14
test/package.json Normal file
View File

@@ -0,0 +1,14 @@
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@playwright/test":"1.51.1"
},
"author": "",
"license": "ISC",
"description": ""
}

View File

@@ -0,0 +1,42 @@
import { test, expect } from '@playwright/test';
test.describe('知识库管理CRUD测试', () => {
test.beforeEach(async ({ page }) => {
// 先登录获取有效token
await page.goto('https://pre-117-77-template.r.d8d.fun/admin/login');
await page.fill('input[placeholder="用户名"]', 'admin');
await page.fill('input[placeholder="密码"]', 'admin123');
await page.click('button:has-text("登 录")');
await expect(page).toHaveURL(/\/admin\/dashboard/);
// 导航到测试页面
await page.goto('https://pre-117-77-template.r.d8d.fun/admin/know-info');
});
test('添加测试文章', async ({ page }) => {
await page.click('button:has-text("添加文章")');
await page.fill('input[placeholder="请输入文章标题"]', '测试文章-自动化测试');
await page.click('button:has-text("确 定")');
await expect(page.locator('text=测试文章-自动化测试')).toBeVisible();
});
test('搜索测试文章', async ({ page }) => {
await page.fill('input[placeholder="要搜索的文章标题"]', '测试文章-自动化测试');
await page.click('button:has-text("搜 索")');
await expect(page.locator('text=测试文章-自动化测试')).toBeVisible();
await page.click('button:has-text("重 置")');
});
test('修改测试文章', async ({ page }) => {
await page.click('tr:has-text("测试文章-自动化测试") >> button:has-text("编辑")');
await page.fill('input[placeholder="请输入文章标题"]', '修改后的测试标题');
await page.click('button:has-text("确 定")');
await expect(page.locator('text=修改后的测试标题')).toBeVisible();
});
test('删除测试文章', async ({ page }) => {
await page.click('tr:has-text("修改后的测试标题") >> button:has-text("删除")');
await page.click('.ant-btn-primary:has-text("确 定")');
await expect(page.locator('text=修改后的测试标题')).not.toBeVisible();
});
});

13
test/playwright.config.ts Normal file
View File

@@ -0,0 +1,13 @@
// playwright.config.js
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
projects: [
{
name: 'chromium',
use: {
browserName: 'chromium',
},
},
],
});