From f158ff6ff5615f9c41ab4ab3a6e50ad0f6c86aed Mon Sep 17 00:00:00 2001 From: yourname Date: Tue, 6 May 2025 06:24:04 +0000 Subject: [PATCH] =?UTF-8?q?feat(mobile):=20=E5=8C=BA=E5=88=86=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E7=AB=AFtoken=E5=AD=98=E5=82=A8=E9=94=AE=E5=90=8D?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0Playwright=E6=B5=8B=E8=AF=95=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9mobile=E7=AB=AFtoken=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E9=94=AE=E5=90=8D=E4=B8=BA'mobile=5Ftoken'=E4=BB=A5=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E4=B8=8D=E5=90=8C=E5=AE=A2=E6=88=B7=E7=AB=AF=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0Playwright=E6=B5=8B=E8=AF=95=E5=A5=97?= =?UTF-8?q?=E4=BB=B6=E7=94=A8=E4=BA=8E=E7=9F=A5=E8=AF=86=E5=BA=93=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD=E6=B5=8B=E8=AF=95=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0.gitignore=E5=BF=BD=E7=95=A5node=5Fmodules=E5=92=8Ctes?= =?UTF-8?q?t-results=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + client/mobile/hooks.tsx | 2 +- test/package-lock.json | 75 ++++++++++++++++++++++++++++++++++++ test/package.json | 14 +++++++ test/pages_know_info.test.ts | 42 ++++++++++++++++++++ test/playwright.config.ts | 13 +++++++ 6 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 test/package-lock.json create mode 100644 test/package.json create mode 100644 test/pages_know_info.test.ts create mode 100644 test/playwright.config.ts diff --git a/.gitignore b/.gitignore index b0ac3ed..c6842fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .aider* +node_modules +test-results \ No newline at end of file diff --git a/client/mobile/hooks.tsx b/client/mobile/hooks.tsx index 9b4e1ee..fcffb21 100644 --- a/client/mobile/hooks.tsx +++ b/client/mobile/hooks.tsx @@ -27,7 +27,7 @@ const ThemeContext = createContext(null); // 认证提供者组件 export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [user, setUser] = useState(null); - const [token, setToken] = useState(getLocalStorageWithExpiry('token')); + const [token, setToken] = useState(getLocalStorageWithExpiry('mobile_token')); const [isAuthenticated, setIsAuthenticated] = useState(false); const queryClient = useQueryClient(); diff --git a/test/package-lock.json b/test/package-lock.json new file mode 100644 index 0000000..07f03fe --- /dev/null +++ b/test/package-lock.json @@ -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" + } + } + } +} diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..ebf45cf --- /dev/null +++ b/test/package.json @@ -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": "" +} diff --git a/test/pages_know_info.test.ts b/test/pages_know_info.test.ts new file mode 100644 index 0000000..23f043c --- /dev/null +++ b/test/pages_know_info.test.ts @@ -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(); + }); +}); \ No newline at end of file diff --git a/test/playwright.config.ts b/test/playwright.config.ts new file mode 100644 index 0000000..a5e2df1 --- /dev/null +++ b/test/playwright.config.ts @@ -0,0 +1,13 @@ +// playwright.config.js +const { defineConfig } = require('@playwright/test'); + +module.exports = defineConfig({ + projects: [ + { + name: 'chromium', + use: { + browserName: 'chromium', + }, + }, + ], +}); \ No newline at end of file