style-compliance.test.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import React from 'react'
  2. import { render } from '@testing-library/react'
  3. import HomePage from '../../src/pages/home/index'
  4. import ActivitySelectPage from '../../src/pages/select-activity/ActivitySelectPage'
  5. import ScheduleListPage from '../../src/pages/schedule-list/ScheduleListPage'
  6. // Mock Taro navigation
  7. jest.mock('@tarojs/taro', () => ({
  8. useRouter: () => ({
  9. params: {}
  10. }),
  11. navigateTo: jest.fn()
  12. }))
  13. // Mock React Query
  14. const mockUseQuery = jest.fn()
  15. jest.mock('@tanstack/react-query', () => ({
  16. useQuery: (...args: any[]) => mockUseQuery(...args)
  17. }))
  18. // Mock API client
  19. jest.mock('../../src/api', () => ({
  20. routeClient: {
  21. search: {
  22. $get: jest.fn()
  23. }
  24. }
  25. }))
  26. describe('样式合规性测试', () => {
  27. beforeEach(() => {
  28. mockUseQuery.mockReturnValue({
  29. data: null,
  30. isLoading: false,
  31. error: null
  32. })
  33. })
  34. describe('设计系统类名验证', () => {
  35. test('首页使用正确的设计系统类名', () => {
  36. const { container } = render(<HomePage />)
  37. // 验证主要颜色类名
  38. expect(container.innerHTML).toMatch(/bg-gradient-to-r from-primary to-primary-dark/)
  39. expect(container.innerHTML).toMatch(/rounded-button/)
  40. expect(container.innerHTML).toMatch(/shadow-primary/)
  41. // 验证包车主题类名(在getVehicleTypeStyle函数中定义)
  42. expect(container.innerHTML).toMatch(/from-charter to-charter-light/)
  43. expect(container.innerHTML).toMatch(/shadow-charter/)
  44. // 验证圆角系统
  45. expect(container.innerHTML).toMatch(/rounded-card/)
  46. expect(container.innerHTML).toMatch(/rounded-small/)
  47. expect(container.innerHTML).toMatch(/rounded-medium/)
  48. // 验证阴影系统
  49. expect(container.innerHTML).toMatch(/shadow-light/)
  50. expect(container.innerHTML).toMatch(/shadow-medium/)
  51. expect(container.innerHTML).toMatch(/shadow-heavy/)
  52. })
  53. test('活动选择页面使用正确的设计系统类名', () => {
  54. const { container } = render(<ActivitySelectPage />)
  55. // 验证头部渐变
  56. expect(container.innerHTML).toMatch(/bg-gradient-to-r from-primary to-primary-dark/)
  57. // 验证去程活动区域
  58. expect(container.innerHTML).toMatch(/from-primary to-primary-dark/)
  59. // 验证返程活动区域(包车主题)
  60. expect(container.innerHTML).toMatch(/from-charter-dark to-charter-bg/)
  61. expect(container.innerHTML).toMatch(/text-charter/)
  62. // 验证卡片样式
  63. expect(container.innerHTML).toMatch(/rounded-card/)
  64. expect(container.innerHTML).toMatch(/p-card/)
  65. expect(container.innerHTML).toMatch(/shadow-light/)
  66. })
  67. test('班次列表页面使用正确的设计系统类名', () => {
  68. const { container } = render(<ScheduleListPage />)
  69. // 验证头部渐变
  70. expect(container.innerHTML).toMatch(/bg-gradient-to-r from-primary to-primary-dark/)
  71. // 验证日期选择器
  72. expect(container.innerHTML).toMatch(/border-primary/)
  73. expect(container.innerHTML).toMatch(/bg-primary\/10/)
  74. expect(container.innerHTML).toMatch(/text-primary/)
  75. // 验证包车卡片样式
  76. expect(container.innerHTML).toMatch(/from-charter-dark to-charter-bg/)
  77. expect(container.innerHTML).toMatch(/border-charter/)
  78. expect(container.innerHTML).toMatch(/bg-charter\/20/)
  79. // 验证预订按钮
  80. expect(container.innerHTML).toMatch(/shadow-primary/)
  81. expect(container.innerHTML).toMatch(/from-primary to-primary-dark/)
  82. expect(container.innerHTML).toMatch(/from-charter to-charter-light/)
  83. })
  84. })
  85. describe('包车主题切换测试', () => {
  86. test('包车出行方式使用正确的主题样式', () => {
  87. const { container } = render(<HomePage />)
  88. // 验证包车主题类名存在(在getVehicleTypeStyle函数中定义)
  89. expect(container.innerHTML).toMatch(/from-charter to-charter-light/)
  90. expect(container.innerHTML).toMatch(/shadow-charter/)
  91. })
  92. test('返程活动使用包车主题', () => {
  93. const { container } = render(<ActivitySelectPage />)
  94. // 验证返程活动区域使用包车主题
  95. expect(container.innerHTML).toMatch(/from-charter-dark to-charter-bg/)
  96. expect(container.innerHTML).toMatch(/text-charter/)
  97. })
  98. test('包车班次卡片使用特殊样式', () => {
  99. const { container } = render(<ScheduleListPage />)
  100. // 验证包车卡片样式类名(在条件渲染中定义)
  101. expect(container.innerHTML).toMatch(/from-charter-dark to-charter-bg/)
  102. expect(container.innerHTML).toMatch(/border-charter/)
  103. expect(container.innerHTML).toMatch(/text-charter/)
  104. })
  105. })
  106. describe('设计系统颜色一致性', () => {
  107. test('主要颜色类名正确应用', () => {
  108. const { container } = render(<HomePage />)
  109. // 验证主要颜色类名
  110. const classNames = container.innerHTML
  111. // primary 颜色相关类名
  112. expect(classNames).toMatch(/bg-primary/)
  113. expect(classNames).toMatch(/text-primary/)
  114. expect(classNames).toMatch(/from-primary/)
  115. expect(classNames).toMatch(/to-primary-dark/)
  116. // charter 颜色相关类名
  117. expect(classNames).toMatch(/bg-charter/)
  118. expect(classNames).toMatch(/text-charter/)
  119. expect(classNames).toMatch(/from-charter/)
  120. expect(classNames).toMatch(/to-charter-light/)
  121. // 功能颜色类名
  122. expect(classNames).toMatch(/bg-success/)
  123. expect(classNames).toMatch(/bg-warning/)
  124. expect(classNames).toMatch(/bg-error/)
  125. })
  126. test('圆角系统一致性', () => {
  127. const { container } = render(<HomePage />)
  128. const classNames = container.innerHTML
  129. // 验证圆角类名
  130. expect(classNames).toMatch(/rounded-card/)
  131. expect(classNames).toMatch(/rounded-button/)
  132. expect(classNames).toMatch(/rounded-small/)
  133. expect(classNames).toMatch(/rounded-medium/)
  134. })
  135. test('阴影系统一致性', () => {
  136. const { container } = render(<HomePage />)
  137. const classNames = container.innerHTML
  138. // 验证阴影类名
  139. expect(classNames).toMatch(/shadow-light/)
  140. expect(classNames).toMatch(/shadow-medium/)
  141. expect(classNames).toMatch(/shadow-heavy/)
  142. expect(classNames).toMatch(/shadow-primary/)
  143. expect(classNames).toMatch(/shadow-charter/)
  144. })
  145. })
  146. describe('间距系统验证', () => {
  147. test('间距类名正确应用', () => {
  148. const { container } = render(<HomePage />)
  149. const classNames = container.innerHTML
  150. // 验证间距类名
  151. expect(classNames).toMatch(/p-card/)
  152. expect(classNames).toMatch(/py-button/)
  153. })
  154. })
  155. })