|
|
@@ -9,6 +9,8 @@ jest.mock('@tarojs/taro', () => ({
|
|
|
params: {
|
|
|
startAreaIds: JSON.stringify([1, 2]),
|
|
|
endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ startAreaName: '',
|
|
|
+ endAreaName: '',
|
|
|
date: '2025-10-31',
|
|
|
vehicleType: 'bus',
|
|
|
travelMode: 'carpool',
|
|
|
@@ -162,7 +164,7 @@ describe('ScheduleListPage', () => {
|
|
|
// 验证活动名称显示
|
|
|
expect(screen.getByText('测试活动')).toBeInTheDocument()
|
|
|
|
|
|
- // 验证路线信息显示
|
|
|
+ // 验证路线信息显示 - 起点使用地点名称,终点保持不变
|
|
|
expect(screen.getByText('起点 → 终点')).toBeInTheDocument()
|
|
|
expect(screen.getByText('去程')).toBeInTheDocument()
|
|
|
|
|
|
@@ -246,6 +248,425 @@ describe('ScheduleListPage', () => {
|
|
|
expect(screen.getByText('暂无班次')).toBeInTheDocument()
|
|
|
})
|
|
|
|
|
|
- expect(screen.getByText('请选择其他日期查看')).toBeInTheDocument()
|
|
|
+ expect(screen.getByText('当前选择的路线暂无可用班次,请返回重新选择路线')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('应该在没有省市区名称时使用默认值', async () => {
|
|
|
+ // Mock router without area names
|
|
|
+ const mockTaro = require('@tarojs/taro')
|
|
|
+ mockTaro.useRouter.mockImplementationOnce(() => ({
|
|
|
+ params: {
|
|
|
+ startAreaIds: JSON.stringify([1, 2]),
|
|
|
+ endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ date: '2025-10-31',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ activityId: '1',
|
|
|
+ routeType: 'departure'
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ render(
|
|
|
+ <Wrapper>
|
|
|
+ <ScheduleListPage />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('选择班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 应该显示路线数据中的起点名称和终点名称
|
|
|
+ expect(screen.getByText('起点 → 终点')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('应该优先使用路由参数中的省市区名称', async () => {
|
|
|
+ // Mock router with custom area names
|
|
|
+ const mockTaro = require('@tarojs/taro')
|
|
|
+ mockTaro.useRouter.mockImplementation(() => ({
|
|
|
+ params: {
|
|
|
+ startAreaIds: JSON.stringify([1, 2]),
|
|
|
+ endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ startAreaName: encodeURIComponent('北京市 朝阳区'),
|
|
|
+ date: '2025-10-31',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ activityId: '1',
|
|
|
+ routeType: 'departure'
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ // Mock empty route data
|
|
|
+ const mockApi = require('../../src/api')
|
|
|
+ mockApi.routeClient.search.$get.mockImplementation(() => Promise.resolve({
|
|
|
+ status: 200,
|
|
|
+ json: () => Promise.resolve({
|
|
|
+ data: {
|
|
|
+ routes: [],
|
|
|
+ activities: []
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }))
|
|
|
+
|
|
|
+ render(
|
|
|
+ <Wrapper>
|
|
|
+ <ScheduleListPage />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('选择班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 等待数据加载完成,确保显示正确的内容
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('暂无班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 检查地区名称显示 - 等待组件渲染完成
|
|
|
+ await waitFor(() => {
|
|
|
+ const areaDisplay = screen.getByTestId('area-display')
|
|
|
+ expect(areaDisplay).toHaveTextContent('请选择路线 → 请选择路线')
|
|
|
+ }, { timeout: 5000 })
|
|
|
+ })
|
|
|
+
|
|
|
+ test('应该在没有路线数据时显示默认地区信息', async () => {
|
|
|
+ // Mock empty data and no area names
|
|
|
+ const mockTaro = require('@tarojs/taro')
|
|
|
+ mockTaro.useRouter.mockImplementationOnce(() => ({
|
|
|
+ params: {
|
|
|
+ startAreaIds: JSON.stringify([1, 2]),
|
|
|
+ endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ date: '2025-10-31',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ activityId: '1',
|
|
|
+ routeType: 'departure'
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ const mockApi = require('../../src/api')
|
|
|
+ mockApi.routeClient.search.$get.mockResolvedValueOnce({
|
|
|
+ status: 200,
|
|
|
+ json: () => Promise.resolve({
|
|
|
+ data: {
|
|
|
+ routes: [],
|
|
|
+ activities: []
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ render(
|
|
|
+ <Wrapper>
|
|
|
+ <ScheduleListPage />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('暂无班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 应该显示默认的起点名称和终点名称
|
|
|
+ expect(screen.getByText('请选择路线 → 请选择路线')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('去程路线应该优化起点显示为省市区格式', async () => {
|
|
|
+ // Mock router with area names for departure route
|
|
|
+ const mockTaro = require('@tarojs/taro')
|
|
|
+ mockTaro.useRouter.mockImplementation(() => ({
|
|
|
+ params: {
|
|
|
+ startAreaIds: JSON.stringify([1, 2]),
|
|
|
+ endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ startAreaName: encodeURIComponent('广东省 广州市 市辖区'),
|
|
|
+ endAreaName: '',
|
|
|
+ date: '2025-10-31',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ activityId: '1',
|
|
|
+ routeType: 'departure'
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ // Mock API to return departure route data
|
|
|
+ const mockApi = require('../../src/api')
|
|
|
+ mockApi.routeClient.search.$get.mockImplementation(() => Promise.resolve({
|
|
|
+ status: 200,
|
|
|
+ json: () => Promise.resolve({
|
|
|
+ data: {
|
|
|
+ routes: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: '测试路线',
|
|
|
+ description: null,
|
|
|
+ startLocationId: 1,
|
|
|
+ endLocationId: 2,
|
|
|
+ startLocation: {
|
|
|
+ id: 1,
|
|
|
+ name: '起点',
|
|
|
+ provinceId: 1,
|
|
|
+ cityId: 1,
|
|
|
+ districtId: 1,
|
|
|
+ address: '起点地址'
|
|
|
+ },
|
|
|
+ endLocation: {
|
|
|
+ id: 2,
|
|
|
+ name: '终点',
|
|
|
+ provinceId: 2,
|
|
|
+ cityId: 2,
|
|
|
+ districtId: 2,
|
|
|
+ address: '终点地址'
|
|
|
+ },
|
|
|
+ pickupPoint: '上车点',
|
|
|
+ dropoffPoint: '下车点',
|
|
|
+ departureTime: '2025-10-31T08:00:00Z',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ price: 100,
|
|
|
+ seatCount: 40,
|
|
|
+ availableSeats: 20,
|
|
|
+ activityId: 1,
|
|
|
+ activity: {
|
|
|
+ id: 1,
|
|
|
+ name: '测试活动',
|
|
|
+ description: null,
|
|
|
+ venueLocationId: 3,
|
|
|
+ venueLocation: {
|
|
|
+ id: 3,
|
|
|
+ name: '活动场地',
|
|
|
+ provinceId: 3,
|
|
|
+ cityId: 3,
|
|
|
+ districtId: 3,
|
|
|
+ address: '活动场地地址'
|
|
|
+ },
|
|
|
+ startDate: '2025-10-31',
|
|
|
+ endDate: '2025-11-01'
|
|
|
+ },
|
|
|
+ routeType: 'departure',
|
|
|
+ isDisabled: 0,
|
|
|
+ isDeleted: 0,
|
|
|
+ createdAt: '2025-10-31T00:00:00Z',
|
|
|
+ updatedAt: '2025-10-31T00:00:00Z'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ activities: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: '测试活动',
|
|
|
+ description: null,
|
|
|
+ venueLocationId: 3,
|
|
|
+ venueLocation: {
|
|
|
+ id: 3,
|
|
|
+ name: '活动场地',
|
|
|
+ provinceId: 3,
|
|
|
+ cityId: 3,
|
|
|
+ districtId: 3,
|
|
|
+ address: '活动场地地址'
|
|
|
+ },
|
|
|
+ startDate: '2025-10-31',
|
|
|
+ endDate: '2025-11-01'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }))
|
|
|
+
|
|
|
+ render(
|
|
|
+ <Wrapper>
|
|
|
+ <ScheduleListPage />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('选择班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 去程路线:应该显示"省份 城市 区县 → 地点名称"格式(只优化起点)
|
|
|
+ expect(screen.getByText('广东省 广州市 市辖区 → 起点')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('返程路线应该优化终点显示为省市区格式', async () => {
|
|
|
+ // Mock router with area names for return route
|
|
|
+ const mockTaro = require('@tarojs/taro')
|
|
|
+ mockTaro.useRouter.mockImplementation(() => ({
|
|
|
+ params: {
|
|
|
+ startAreaIds: JSON.stringify([1, 2]),
|
|
|
+ endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ endAreaName: encodeURIComponent('广东省 广州市 市辖区'),
|
|
|
+ date: '2025-10-31',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ activityId: '1',
|
|
|
+ routeType: 'return'
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ // Mock API to return return route data
|
|
|
+ const mockApi = require('../../src/api')
|
|
|
+ mockApi.routeClient.search.$get.mockImplementation(() => Promise.resolve({
|
|
|
+ status: 200,
|
|
|
+ json: () => Promise.resolve({
|
|
|
+ data: {
|
|
|
+ routes: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: '测试路线',
|
|
|
+ description: null,
|
|
|
+ startLocationId: 1,
|
|
|
+ endLocationId: 2,
|
|
|
+ startLocation: {
|
|
|
+ id: 1,
|
|
|
+ name: '起点',
|
|
|
+ provinceId: 1,
|
|
|
+ cityId: 1,
|
|
|
+ districtId: 1,
|
|
|
+ address: '起点地址'
|
|
|
+ },
|
|
|
+ endLocation: {
|
|
|
+ id: 2,
|
|
|
+ name: '终点',
|
|
|
+ provinceId: 2,
|
|
|
+ cityId: 2,
|
|
|
+ districtId: 2,
|
|
|
+ address: '终点地址'
|
|
|
+ },
|
|
|
+ pickupPoint: '上车点',
|
|
|
+ dropoffPoint: '下车点',
|
|
|
+ departureTime: '2025-10-31T08:00:00Z',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ price: 100,
|
|
|
+ seatCount: 40,
|
|
|
+ availableSeats: 20,
|
|
|
+ activityId: 1,
|
|
|
+ activity: {
|
|
|
+ id: 1,
|
|
|
+ name: '测试活动',
|
|
|
+ description: null,
|
|
|
+ venueLocationId: 3,
|
|
|
+ venueLocation: {
|
|
|
+ id: 3,
|
|
|
+ name: '活动场地',
|
|
|
+ provinceId: 3,
|
|
|
+ cityId: 3,
|
|
|
+ districtId: 3,
|
|
|
+ address: '活动场地地址'
|
|
|
+ },
|
|
|
+ startDate: '2025-10-31',
|
|
|
+ endDate: '2025-11-01'
|
|
|
+ },
|
|
|
+ routeType: 'return',
|
|
|
+ isDisabled: 0,
|
|
|
+ isDeleted: 0,
|
|
|
+ createdAt: '2025-10-31T00:00:00Z',
|
|
|
+ updatedAt: '2025-10-31T00:00:00Z'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ activities: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: '测试活动',
|
|
|
+ description: null,
|
|
|
+ venueLocationId: 3,
|
|
|
+ venueLocation: {
|
|
|
+ id: 3,
|
|
|
+ name: '活动场地',
|
|
|
+ provinceId: 3,
|
|
|
+ cityId: 3,
|
|
|
+ districtId: 3,
|
|
|
+ address: '活动场地地址'
|
|
|
+ },
|
|
|
+ startDate: '2025-10-31',
|
|
|
+ endDate: '2025-11-01'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }))
|
|
|
+
|
|
|
+ render(
|
|
|
+ <Wrapper>
|
|
|
+ <ScheduleListPage />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('选择班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 返程路线:应该显示"地点名称 → 省份 城市 区县"格式(只优化终点)
|
|
|
+ expect(screen.getByText('终点 → 广东省 广州市 市辖区')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('页面加载时不应该默认选择路线', async () => {
|
|
|
+ // Mock router with no route data
|
|
|
+ const mockTaro = require('@tarojs/taro')
|
|
|
+ mockTaro.useRouter.mockImplementationOnce(() => ({
|
|
|
+ params: {
|
|
|
+ startAreaIds: JSON.stringify([1, 2]),
|
|
|
+ endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ date: '2025-10-31',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ activityId: '1',
|
|
|
+ routeType: 'departure'
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ const mockApi = require('../../src/api')
|
|
|
+ mockApi.routeClient.search.$get.mockResolvedValueOnce({
|
|
|
+ status: 200,
|
|
|
+ json: () => Promise.resolve({
|
|
|
+ data: {
|
|
|
+ routes: [],
|
|
|
+ activities: []
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ render(
|
|
|
+ <Wrapper>
|
|
|
+ <ScheduleListPage />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('暂无班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 应该显示"请选择路线"而不是默认的路线信息
|
|
|
+ expect(screen.getByText('请选择路线 → 请选择路线')).toBeInTheDocument()
|
|
|
+ expect(screen.getByText('当前选择的路线暂无可用班次,请返回重新选择路线')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('应该正确处理省市区信息从路由参数传递', async () => {
|
|
|
+ // Mock router with complete area information
|
|
|
+ const mockTaro = require('@tarojs/taro')
|
|
|
+ mockTaro.useRouter.mockImplementation(() => ({
|
|
|
+ params: {
|
|
|
+ startAreaIds: JSON.stringify([1, 2]),
|
|
|
+ endAreaIds: JSON.stringify([3, 4]),
|
|
|
+ startAreaName: encodeURIComponent('北京市 朝阳区'),
|
|
|
+ endAreaName: encodeURIComponent('上海市 浦东新区'),
|
|
|
+ date: '2025-10-31',
|
|
|
+ vehicleType: 'bus',
|
|
|
+ travelMode: 'carpool',
|
|
|
+ activityId: '1',
|
|
|
+ routeType: 'departure'
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ render(
|
|
|
+ <Wrapper>
|
|
|
+ <ScheduleListPage />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('选择班次')).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 应该正确显示从路由参数传递的省市区信息
|
|
|
+ // 去程路线:只优化起点显示为省市区格式
|
|
|
+ expect(screen.getByText('北京市 朝阳区 → 起点')).toBeInTheDocument()
|
|
|
})
|
|
|
})
|