|
@@ -13,13 +13,13 @@ import taroMock, { mockUseRouter } from '../../tests/__mocks__/taroMock'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// Mock React Query
|
|
|
|
|
|
|
+// 模拟 React Query
|
|
|
const mockUseQuery = jest.fn()
|
|
const mockUseQuery = jest.fn()
|
|
|
const mockUseMutation = jest.fn()
|
|
const mockUseMutation = jest.fn()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// Mock React Query
|
|
|
|
|
|
|
+// 模拟 React Query
|
|
|
jest.mock('@tanstack/react-query', () => {
|
|
jest.mock('@tanstack/react-query', () => {
|
|
|
const actual = jest.requireActual('@tanstack/react-query')
|
|
const actual = jest.requireActual('@tanstack/react-query')
|
|
|
return {
|
|
return {
|
|
@@ -48,7 +48,7 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Mock API客户端
|
|
|
|
|
|
|
+// 模拟 API客户端
|
|
|
jest.mock('@/api', () => ({
|
|
jest.mock('@/api', () => ({
|
|
|
orderClient: {
|
|
orderClient: {
|
|
|
$post: jest.fn()
|
|
$post: jest.fn()
|
|
@@ -138,7 +138,7 @@ describe('OrderPage', () => {
|
|
|
taroMock.getEnv.mockReturnValue('WEB')
|
|
taroMock.getEnv.mockReturnValue('WEB')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should render order page correctly', () => {
|
|
|
|
|
|
|
+ it('应该正确渲染订单页面', () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -151,7 +151,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('price-per-unit')).toHaveTextContent('¥100/车')
|
|
expect(screen.getByTestId('price-per-unit')).toHaveTextContent('¥100/车')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should show loading state', () => {
|
|
|
|
|
|
|
+ it('应该显示加载状态', () => {
|
|
|
mockUseQuery.mockImplementation((options) => {
|
|
mockUseQuery.mockImplementation((options) => {
|
|
|
if (options.queryKey?.[0] === 'route') {
|
|
if (options.queryKey?.[0] === 'route') {
|
|
|
return { data: null, isLoading: true }
|
|
return { data: null, isLoading: true }
|
|
@@ -168,7 +168,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByText('加载中...')).toBeInTheDocument()
|
|
expect(screen.getByText('加载中...')).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle phone number acquisition', async () => {
|
|
|
|
|
|
|
+ it('应该处理手机号获取', async () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -182,7 +182,7 @@ describe('OrderPage', () => {
|
|
|
// 由于Taro API的限制,实际测试可能需要更复杂的模拟
|
|
// 由于Taro API的限制,实际测试可能需要更复杂的模拟
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle passenger selection', async () => {
|
|
|
|
|
|
|
+ it('应该处理乘客选择', async () => {
|
|
|
// 模拟已获取手机号的状态
|
|
// 模拟已获取手机号的状态
|
|
|
// 由于组件内部状态难以直接模拟,我们测试乘客选择器的基本功能
|
|
// 由于组件内部状态难以直接模拟,我们测试乘客选择器的基本功能
|
|
|
render(
|
|
render(
|
|
@@ -212,7 +212,7 @@ describe('OrderPage', () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should validate payment prerequisites', async () => {
|
|
|
|
|
|
|
+ it('应该验证支付前提条件', async () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -235,7 +235,7 @@ describe('OrderPage', () => {
|
|
|
// 这里需要模拟已获取手机号但未添加乘客的情况
|
|
// 这里需要模拟已获取手机号但未添加乘客的情况
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle successful payment flow', async () => {
|
|
|
|
|
|
|
+ it('应该处理成功的支付流程', async () => {
|
|
|
// Mock成功的订单创建
|
|
// Mock成功的订单创建
|
|
|
const mockOrderResponse = { id: 123 }
|
|
const mockOrderResponse = { id: 123 }
|
|
|
const mockPaymentResponse = {
|
|
const mockPaymentResponse = {
|
|
@@ -285,7 +285,7 @@ describe('OrderPage', () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle payment failure', async () => {
|
|
|
|
|
|
|
+ it('应该处理支付失败', async () => {
|
|
|
// Mock失败的订单创建
|
|
// Mock失败的订单创建
|
|
|
mockUseMutation.mockImplementation(() => ({
|
|
mockUseMutation.mockImplementation(() => ({
|
|
|
mutateAsync: async () => {
|
|
mutateAsync: async () => {
|
|
@@ -313,7 +313,7 @@ describe('OrderPage', () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle user cancellation', async () => {
|
|
|
|
|
|
|
+ it('应该处理用户取消', async () => {
|
|
|
// Mock用户取消支付
|
|
// Mock用户取消支付
|
|
|
taroMock.requestPayment.mockRejectedValue({
|
|
taroMock.requestPayment.mockRejectedValue({
|
|
|
errMsg: 'requestPayment:fail cancel'
|
|
errMsg: 'requestPayment:fail cancel'
|
|
@@ -338,7 +338,7 @@ describe('OrderPage', () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should calculate total price correctly', () => {
|
|
|
|
|
|
|
+ it('应该正确计算总价', () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -350,7 +350,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('total-price')).toHaveTextContent('¥100')
|
|
expect(screen.getByTestId('total-price')).toHaveTextContent('¥100')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should validate seat availability', async () => {
|
|
|
|
|
|
|
+ it('应该验证座位可用性', async () => {
|
|
|
// 测试拼车模式的座位验证
|
|
// 测试拼车模式的座位验证
|
|
|
mockUseRouter.mockReturnValue({
|
|
mockUseRouter.mockReturnValue({
|
|
|
params: {
|
|
params: {
|
|
@@ -394,7 +394,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('service-type')).toHaveTextContent('班次信息')
|
|
expect(screen.getByTestId('service-type')).toHaveTextContent('班次信息')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle successful phone number acquisition', async () => {
|
|
|
|
|
|
|
+ it('应该处理成功的手机号获取', async () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -409,7 +409,7 @@ describe('OrderPage', () => {
|
|
|
expect(getPhoneButton).toHaveAttribute('openType', 'getPhoneNumber')
|
|
expect(getPhoneButton).toHaveAttribute('openType', 'getPhoneNumber')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle phone number acquisition failure', async () => {
|
|
|
|
|
|
|
+ it('应该处理手机号获取失败', async () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -421,7 +421,7 @@ describe('OrderPage', () => {
|
|
|
expect(getPhoneButton).toBeInTheDocument()
|
|
expect(getPhoneButton).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle passenger deletion', async () => {
|
|
|
|
|
|
|
+ it('应该处理乘客删除', async () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -434,7 +434,7 @@ describe('OrderPage', () => {
|
|
|
expect(addPassengerButton).toBeInTheDocument()
|
|
expect(addPassengerButton).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle route data loading error', async () => {
|
|
|
|
|
|
|
+ it('应该处理路线数据加载错误', async () => {
|
|
|
// 模拟路线数据加载失败
|
|
// 模拟路线数据加载失败
|
|
|
mockUseQuery.mockImplementation((options) => {
|
|
mockUseQuery.mockImplementation((options) => {
|
|
|
if (options.queryKey?.[0] === 'route') {
|
|
if (options.queryKey?.[0] === 'route') {
|
|
@@ -458,7 +458,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByText('加载中...')).toBeInTheDocument()
|
|
expect(screen.getByText('加载中...')).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle passenger data loading error', async () => {
|
|
|
|
|
|
|
+ it('应该处理乘客数据加载错误', async () => {
|
|
|
// 模拟乘客数据加载失败
|
|
// 模拟乘客数据加载失败
|
|
|
mockUseQuery.mockImplementation((options) => {
|
|
mockUseQuery.mockImplementation((options) => {
|
|
|
if (options.queryKey?.[0] === 'route') {
|
|
if (options.queryKey?.[0] === 'route') {
|
|
@@ -488,7 +488,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('add-passenger-button')).toBeInTheDocument()
|
|
expect(screen.getByTestId('add-passenger-button')).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle order creation failure', async () => {
|
|
|
|
|
|
|
+ it('应该处理订单创建失败', async () => {
|
|
|
// Mock失败的订单创建
|
|
// Mock失败的订单创建
|
|
|
mockUseMutation.mockImplementation(() => ({
|
|
mockUseMutation.mockImplementation(() => ({
|
|
|
mutateAsync: async () => {
|
|
mutateAsync: async () => {
|
|
@@ -516,7 +516,7 @@ describe('OrderPage', () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle payment creation failure', async () => {
|
|
|
|
|
|
|
+ it('应该处理支付创建失败', async () => {
|
|
|
// Mock成功的订单创建但失败的支付创建
|
|
// Mock成功的订单创建但失败的支付创建
|
|
|
mockUseMutation.mockImplementation((options) => {
|
|
mockUseMutation.mockImplementation((options) => {
|
|
|
if (options.mutationKey?.[0] === 'createOrder') {
|
|
if (options.mutationKey?.[0] === 'createOrder') {
|
|
@@ -558,7 +558,7 @@ describe('OrderPage', () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle carpool mode correctly', async () => {
|
|
|
|
|
|
|
+ it('应该正确处理拼车模式', async () => {
|
|
|
// 测试拼车模式
|
|
// 测试拼车模式
|
|
|
mockUseRouter.mockReturnValue({
|
|
mockUseRouter.mockReturnValue({
|
|
|
params: {
|
|
params: {
|
|
@@ -594,7 +594,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('price-per-unit')).toHaveTextContent('¥100/人')
|
|
expect(screen.getByTestId('price-per-unit')).toHaveTextContent('¥100/人')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle business charter mode correctly', async () => {
|
|
|
|
|
|
|
+ it('应该正确处理商务包车模式', async () => {
|
|
|
// 测试商务包车模式
|
|
// 测试商务包车模式
|
|
|
mockUseRouter.mockReturnValue({
|
|
mockUseRouter.mockReturnValue({
|
|
|
params: {
|
|
params: {
|
|
@@ -615,7 +615,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('price-per-unit')).toHaveTextContent('¥100/车')
|
|
expect(screen.getByTestId('price-per-unit')).toHaveTextContent('¥100/车')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle empty activity name', async () => {
|
|
|
|
|
|
|
+ it('应该处理空活动名称', async () => {
|
|
|
// 测试空活动名称的情况
|
|
// 测试空活动名称的情况
|
|
|
mockUseRouter.mockReturnValue({
|
|
mockUseRouter.mockReturnValue({
|
|
|
params: {
|
|
params: {
|
|
@@ -635,7 +635,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('activity-name')).toHaveTextContent('活动')
|
|
expect(screen.getByTestId('activity-name')).toHaveTextContent('活动')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle URL encoded activity name', async () => {
|
|
|
|
|
|
|
+ it('应该处理URL编码的活动名称', async () => {
|
|
|
// 测试URL编码的活动名称
|
|
// 测试URL编码的活动名称
|
|
|
const encodedActivityName = encodeURIComponent('测试活动名称')
|
|
const encodedActivityName = encodeURIComponent('测试活动名称')
|
|
|
mockUseRouter.mockReturnValue({
|
|
mockUseRouter.mockReturnValue({
|
|
@@ -656,7 +656,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getByTestId('activity-name')).toHaveTextContent('测试活动名称')
|
|
expect(screen.getByTestId('activity-name')).toHaveTextContent('测试活动名称')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should display departure time as customer service confirmation message', async () => {
|
|
|
|
|
|
|
+ it('应该将出发时间显示为客服确认信息', async () => {
|
|
|
render(
|
|
render(
|
|
|
<Wrapper>
|
|
<Wrapper>
|
|
|
<OrderPage />
|
|
<OrderPage />
|
|
@@ -675,7 +675,7 @@ describe('OrderPage', () => {
|
|
|
expect(screen.getAllByText('包车价格').length).toBeGreaterThan(0)
|
|
expect(screen.getAllByText('包车价格').length).toBeGreaterThan(0)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should apply time display optimization for both carpool and charter services', async () => {
|
|
|
|
|
|
|
+ it('应该对拼车和包车服务都应用时间显示优化', async () => {
|
|
|
// 测试拼车模式
|
|
// 测试拼车模式
|
|
|
mockUseRouter.mockReturnValue({
|
|
mockUseRouter.mockReturnValue({
|
|
|
params: {
|
|
params: {
|