Files
purewhiter--mobilegym/tests/wechatContactsLayout.test.ts
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

48 lines
1.6 KiB
TypeScript

import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const mockContacts = [
{ wxid: 'wxid_a', name: 'Alice', avatar: '/alice.png', category: 'A', isBlacklisted: false },
{ wxid: 'wxid_b', name: 'Bob', avatar: '/bob.png', category: 'B', isBlacklisted: false },
{ wxid: 'wxid_c', name: 'Carol', avatar: '/carol.png', category: 'C', isBlacklisted: true },
];
vi.mock('../apps/Wechat/hooks/useWechatStrings', () => ({
useWechatStrings: () => ({
contacts_new_friend: '新的朋友',
contacts_group_chat: '群聊',
contacts_tags: '标签',
contacts_official_accounts: '公众号',
contacts_count_suffix: '位联系人',
}),
}));
vi.mock('../apps/Wechat/hooks/useWechatGestures', () => ({
useWechatGestures: () => ({
bindTap: () => ({}),
}),
}));
vi.mock('../apps/Wechat/state', () => ({
useWechatStore: (selector: (state: { contacts: typeof mockContacts }) => unknown) =>
selector({ contacts: mockContacts }),
}));
describe('Wechat Contacts 布局', () => {
beforeEach(() => {
vi.resetModules();
});
it('字母索引栏位于滚动容器之外,避免跟随列表一起滚动', async () => {
const { default: Contacts } = await import('../apps/Wechat/pages/Contacts');
const markup = renderToStaticMarkup(React.createElement(Contacts));
expect(markup).toContain('data-scroll-container="main"');
expect(markup).toContain('2位联系人');
expect(markup).toContain('absolute right-0 top-10');
expect(markup).toContain('2位联系人</div></div><div class="absolute right-0 top-10');
});
});