Files
Genarrative/src/components/platform-entry/platformProfileApiKeysModal.test.ts
T
kdletters e5ebdf0a8e
Project CI / Repository checks (push) Failing after 40s
Project CI / Frontend tests (push) Successful in 3m8s
Project CI / Backend tests (push) Successful in 3m55s
Project CI / Native shell tests (push) Successful in 14m3s
修复开发者密钥时间显示
复用个人中心时间解析逻辑格式化秒级小数时间戳
统一展示密钥创建时间和最近使用时间
补充弹窗回归测试与接入文档约束
2026-08-05 21:48:30 +08:00

46 lines
1.4 KiB
TypeScript

/* @vitest-environment jsdom */
import { render, screen } from '@testing-library/react';
import { createElement } from 'react';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import { PlatformProfileApiKeysModal } from './PlatformProfileApiKeysModal';
const listExternalApiKeysMock = vi.hoisted(() => vi.fn());
vi.mock('../../services/platform-entry/platformProfileClient', () => ({
createPlatformProfileExternalApiKey: vi.fn(),
listPlatformProfileExternalApiKeys: listExternalApiKeysMock,
revokePlatformProfileExternalApiKey: vi.fn(),
}));
describe('PlatformProfileApiKeysModal', () => {
beforeEach(() => {
listExternalApiKeysMock.mockReset();
});
test('将 API Key 时间戳格式化为日期', async () => {
listExternalApiKeysMock.mockResolvedValueOnce({
keys: [
{
keyId: 'api-key-1',
name: '外部 API Key',
keyPrefix: 'tnr_sk_example',
scopes: ['editor:project'],
createdAt: '1785913407.182731Z',
lastUsedAt: null,
revokedAt: null,
updatedAt: '1785913407.182731Z',
},
],
});
render(createElement(PlatformProfileApiKeysModal, { onClose: vi.fn() }));
expect(
await screen.findByText('创建 2026-08-05 · 最近使用 尚未使用'),
).toBeTruthy();
expect(screen.queryByText(/1785913407\.182731Z/u)).toBeNull();
});
});