|
@@ -4,7 +4,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
|
import HomePage from '../../src/pages/home/index'
|
|
import HomePage from '../../src/pages/home/index'
|
|
|
|
|
|
|
|
// 导入 Taro mock 函数
|
|
// 导入 Taro mock 函数
|
|
|
-import taroMock from '../__mocks__/taroMock'
|
|
|
|
|
|
|
+import taroMock, { mockUseShareAppMessage, mockUseShareTimeline } from '../__mocks__/taroMock'
|
|
|
|
|
|
|
|
// Mock API 客户端
|
|
// Mock API 客户端
|
|
|
const mockAreaClient = {
|
|
const mockAreaClient = {
|
|
@@ -659,4 +659,57 @@ describe('首页集成测试', () => {
|
|
|
const destinationText = screen.getByText('请选择地区')
|
|
const destinationText = screen.getByText('请选择地区')
|
|
|
expect(destinationText).toBeInTheDocument()
|
|
expect(destinationText).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ test('应该配置分享功能', () => {
|
|
|
|
|
+ render(
|
|
|
|
|
+ <Wrapper>
|
|
|
|
|
+ <HomePage />
|
|
|
|
|
+ </Wrapper>
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // 检查分享 Hook 被调用
|
|
|
|
|
+ expect(mockUseShareAppMessage).toHaveBeenCalled()
|
|
|
|
|
+ expect(mockUseShareTimeline).toHaveBeenCalled()
|
|
|
|
|
+
|
|
|
|
|
+ // 获取分享 Hook 的回调函数
|
|
|
|
|
+ const shareAppMessageCallback = mockUseShareAppMessage.mock.calls[0][0]
|
|
|
|
|
+ const shareTimelineCallback = mockUseShareTimeline.mock.calls[0][0]
|
|
|
|
|
+
|
|
|
|
|
+ // 测试分享到好友的配置
|
|
|
|
|
+ const shareAppMessageResult = shareAppMessageCallback()
|
|
|
|
|
+ expect(shareAppMessageResult).toEqual({
|
|
|
|
|
+ title: '开心去看,就用去看出行',
|
|
|
|
|
+ path: '/pages/home/index',
|
|
|
|
|
+ imageUrl: process.env.TARO_APP_PUBLIC_IMAGE_BASE_URL + '/images/wp_home_share.jpg'
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 测试分享到朋友圈的配置
|
|
|
|
|
+ const shareTimelineResult = shareTimelineCallback()
|
|
|
|
|
+ expect(shareTimelineResult).toEqual({
|
|
|
|
|
+ title: '开心去看,就用去看出行',
|
|
|
|
|
+ imageUrl: process.env.TARO_APP_PUBLIC_IMAGE_BASE_URL + '/images/wp_home_share.jpg'
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('应该验证分享图片路径配置', () => {
|
|
|
|
|
+ // 设置环境变量
|
|
|
|
|
+ process.env.TARO_APP_PUBLIC_IMAGE_BASE_URL = 'https://example.com'
|
|
|
|
|
+
|
|
|
|
|
+ render(
|
|
|
|
|
+ <Wrapper>
|
|
|
|
|
+ <HomePage />
|
|
|
|
|
+ </Wrapper>
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // 获取分享 Hook 的回调函数
|
|
|
|
|
+ const shareAppMessageCallback = mockUseShareAppMessage.mock.calls[0][0]
|
|
|
|
|
+ const shareTimelineCallback = mockUseShareTimeline.mock.calls[0][0]
|
|
|
|
|
+
|
|
|
|
|
+ // 验证分享图片路径
|
|
|
|
|
+ const shareAppMessageResult = shareAppMessageCallback()
|
|
|
|
|
+ expect(shareAppMessageResult.imageUrl).toBe('https://example.com/images/wp_home_share.jpg')
|
|
|
|
|
+
|
|
|
|
|
+ const shareTimelineResult = shareTimelineCallback()
|
|
|
|
|
+ expect(shareTimelineResult.imageUrl).toBe('https://example.com/images/wp_home_share.jpg')
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|