import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import defaultI18n from '../src/locale/index.ts'; const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const billingPagePath = path.join( adminRoot, 'src/pages/settings/billing/index.tsx' ); const billingLocalePath = path.join( adminRoot, 'src/pages/settings/billing/locale/index.ts' ); function readPage(): string { assert.ok(fs.existsSync(billingPagePath), '订阅账单页面必须存在'); return fs.readFileSync(billingPagePath, 'utf-8'); } function readLocale(): string { assert.ok(fs.existsSync(billingLocalePath), '订阅账单语言包必须存在'); return fs.readFileSync(billingLocalePath, 'utf-8'); } test('1. settings/billing 必须请求 billing/currentPlan', () => { const content = readPage(); assert.ok( content.includes('billing/currentPlan'), '必须请求 POST /api/admin/team/billing/currentPlan' ); assert.ok( content.includes('admin/team/billing/currentPlan'), '必须请求完整后台路径 /api/admin/team/billing/currentPlan' ); assert.ok(content.includes('axios'), '必须使用 axios 发请求'); assert.ok( content.includes('{}'), '进入页必须 POST currentPlan {}' ); assert.ok( content.includes("from '@arco-design/web-react'"), '必须从 @arco-design/web-react 引入组件' ); assert.ok( content.includes('code === 1000') || content.includes('code ===1000'), '必须按 Cool-Admin code === 1000 判断成功' ); assert.ok(content.includes('Message.error'), '失败必须使用 Arco Message.error'); assert.ok(content.includes('BillingQuota'), '必须使用 BillingQuota 类型'); assert.ok(content.includes('TenantPlanType'), '必须使用 TenantPlanType 类型'); assert.ok(content.includes("from '@/types/omni'"), '必须复用 admin/src/types/omni.ts'); assert.ok( !content.includes('Mock.js') && !content.includes("from 'mockjs'"), '禁止用 Mock.js 假数据冒充成功' ); assert.ok(!/\bany\b/.test(content), '禁止使用 any'); assert.ok( !content.includes('stripe.com') && !content.includes('sk_live'), '源码不含 stripe.com 或 sk_live' ); }); test('2. settings/billing 必须使用 Card / Progress / Tag', () => { const content = readPage(); assert.ok(content.includes('Card'), '必须使用 Arco Card'); assert.ok(content.includes('Progress'), '必须使用 Arco Progress'); assert.ok(content.includes('Tag'), '必须使用 Arco Tag'); assert.ok(content.includes('Alert'), '必须使用 Arco Alert 说明后续接入'); assert.ok(content.includes('planType'), 'Card 必须展示 planType'); assert.ok(content.includes('seatsUsed'), 'Progress 必须展示 seatsUsed'); assert.ok(content.includes('seatsLimit'), 'Progress 必须展示 seatsLimit'); assert.ok(content.includes('cardsUsed'), 'Progress 必须展示 cardsUsed'); assert.ok(content.includes('cardsLimit'), 'Progress 必须展示 cardsLimit'); assert.ok(content.includes("'free'"), '必须说明 free 套餐'); assert.ok(content.includes("'pro'"), '必须说明 pro 套餐'); assert.ok(content.includes("'enterprise'"), '必须说明 enterprise 套餐'); assert.ok(content.includes('lightColors'), '颜色必须引用 lightColors token'); assert.ok(content.includes('type="primary"'), '必须有一个主 CTA 刷新配额'); assert.ok( !/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b/.test(content), '禁止硬编码颜色' ); assert.ok( !content.includes('#000') && !content.includes('#000000'), '禁止纯黑' ); assert.ok( !content.includes('Mock.js') && !content.includes("from 'mockjs'"), '禁止用 Mock.js' ); assert.ok(!/\bany\b/.test(content), '禁止使用 any'); assert.ok( !content.includes('stripe.com') && !content.includes('sk_live'), '源码不含 stripe.com 或 sk_live' ); }); test('3. settings/billing locale 必须包含 menu.settings.billing', () => { const content = readLocale(); assert.ok( content.includes("'menu.settings.billing'"), '页面语言包必须包含 menu.settings.billing' ); assert.ok(content.includes("'en-US'"), '必须包含英文案'); assert.ok(content.includes("'zh-CN'"), '必须包含中文案'); assert.ok( content.includes('settingsBilling.request.fail'), '必须包含失败提示文案' ); assert.ok( content.includes('settingsBilling.action.refresh'), '必须包含刷新配额主 CTA 文案' ); assert.ok( content.includes('settingsBilling.alert'), '必须包含国际卡与发票后续接入提示' ); assert.ok(!/\bany\b/.test(content), 'locale 禁止使用 any'); assert.ok( !/[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u.test(content), 'locale 禁止使用 emoji' ); assert.ok( !content.includes('stripe.com') && !content.includes('sk_live'), '源码不含 stripe.com 或 sk_live' ); assert.equal(defaultI18n['en-US']['menu.settings.billing'], 'Billing'); assert.equal(defaultI18n['zh-CN']['menu.settings.billing'], '订阅账单'); });