|
@@ -10,7 +10,7 @@ jest.mock('@/api', () => ({
|
|
|
':id': {
|
|
':id': {
|
|
|
$get: jest.fn()
|
|
$get: jest.fn()
|
|
|
},
|
|
},
|
|
|
- cancelOrder: {
|
|
|
|
|
|
|
+ 'cancel-order': {
|
|
|
$post: jest.fn()
|
|
$post: jest.fn()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -80,14 +80,15 @@ describe('OrderDetailPage', () => {
|
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
|
mockGetOrder.mockImplementation(() => new Promise(() => {})) // 永不resolve
|
|
mockGetOrder.mockImplementation(() => new Promise(() => {})) // 永不resolve
|
|
|
|
|
|
|
|
- const { getByText } = render(
|
|
|
|
|
|
|
+ const { container } = render(
|
|
|
<TestWrapper>
|
|
<TestWrapper>
|
|
|
<OrderDetailPage />
|
|
<OrderDetailPage />
|
|
|
</TestWrapper>
|
|
</TestWrapper>
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- // 检查加载状态
|
|
|
|
|
- expect(getByText('订单详情')).toBeTruthy()
|
|
|
|
|
|
|
+ // 检查加载状态 - 应该显示加载指示器
|
|
|
|
|
+ const loadingSpinner = container.querySelector('.i-heroicons-arrow-path-20-solid.animate-spin')
|
|
|
|
|
+ expect(loadingSpinner).toBeTruthy()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should show error when order not found', async () => {
|
|
it('should show error when order not found', async () => {
|
|
@@ -110,7 +111,7 @@ describe('OrderDetailPage', () => {
|
|
|
json: () => Promise.resolve(mockOrder)
|
|
json: () => Promise.resolve(mockOrder)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- const { findByText, getByText } = render(
|
|
|
|
|
|
|
+ const { findByText, getByText, container } = render(
|
|
|
<TestWrapper>
|
|
<TestWrapper>
|
|
|
<OrderDetailPage />
|
|
<OrderDetailPage />
|
|
|
</TestWrapper>
|
|
</TestWrapper>
|
|
@@ -121,14 +122,15 @@ describe('OrderDetailPage', () => {
|
|
|
fireEvent.click(getByText('取消订单'))
|
|
fireEvent.click(getByText('取消订单'))
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
- expect(getByText('取消订单')).toBeTruthy() // 对话框标题
|
|
|
|
|
- expect(getByText('请选择或填写取消原因:')).toBeTruthy()
|
|
|
|
|
|
|
+ // 检查对话框是否通过DOM查询器找到
|
|
|
|
|
+ const dialog = container.querySelector('[role="dialog"]')
|
|
|
|
|
+ expect(dialog).toBeTruthy()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should call cancel API when cancel is confirmed', async () => {
|
|
it('should call cancel API when cancel is confirmed', async () => {
|
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
|
- const mockCancelOrder = require('@/api').orderClient.cancelOrder.$post as jest.Mock
|
|
|
|
|
|
|
+ const mockCancelOrder = require('@/api').orderClient['cancel-order'].$post as jest.Mock
|
|
|
const mockShowModal = Taro.showModal as jest.Mock
|
|
const mockShowModal = Taro.showModal as jest.Mock
|
|
|
|
|
|
|
|
mockGetOrder.mockResolvedValue({
|
|
mockGetOrder.mockResolvedValue({
|
|
@@ -174,7 +176,7 @@ describe('OrderDetailPage', () => {
|
|
|
|
|
|
|
|
it('should show success message when cancel succeeds', async () => {
|
|
it('should show success message when cancel succeeds', async () => {
|
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
|
- const mockCancelOrder = require('@/api').orderClient.cancelOrder.$post as jest.Mock
|
|
|
|
|
|
|
+ const mockCancelOrder = require('@/api').orderClient['cancel-order'].$post as jest.Mock
|
|
|
const mockShowToast = Taro.showToast as jest.Mock
|
|
const mockShowToast = Taro.showToast as jest.Mock
|
|
|
const mockShowModal = Taro.showModal as jest.Mock
|
|
const mockShowModal = Taro.showModal as jest.Mock
|
|
|
|
|
|
|
@@ -219,7 +221,7 @@ describe('OrderDetailPage', () => {
|
|
|
|
|
|
|
|
it('should show error message when cancel fails', async () => {
|
|
it('should show error message when cancel fails', async () => {
|
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
const mockGetOrder = require('@/api').orderClient[':id'].$get as jest.Mock
|
|
|
- const mockCancelOrder = require('@/api').orderClient.cancelOrder.$post as jest.Mock
|
|
|
|
|
|
|
+ const mockCancelOrder = require('@/api').orderClient['cancel-order'].$post as jest.Mock
|
|
|
const mockShowToast = Taro.showToast as jest.Mock
|
|
const mockShowToast = Taro.showToast as jest.Mock
|
|
|
const mockShowModal = Taro.showModal as jest.Mock
|
|
const mockShowModal = Taro.showModal as jest.Mock
|
|
|
|
|
|