App.test.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { render, screen, waitFor } from '@testing-library/react'
  2. import { describe, expect, it, vi, beforeEach } from 'vitest'
  3. import App from '../App'
  4. vi.mock('../pages/public/LandingPage', () => ({
  5. LandingPage: () => <div>landing-page</div>,
  6. }))
  7. vi.mock('../pages/public/LoginPage', () => ({
  8. LoginPage: () => <div>login-page</div>,
  9. }))
  10. vi.mock('../pages/dashboard/DashboardPage', () => ({
  11. DashboardPage: () => <div>dashboard-page</div>,
  12. }))
  13. vi.mock('../pages/dashboard/customers/CustomerListPage', () => ({
  14. CustomerListPage: () => <div>customer-list-page</div>,
  15. }))
  16. vi.mock('../pages/dashboard/customers/CustomerFormPage', () => ({
  17. CustomerFormPage: () => <div>customer-form-new</div>,
  18. }))
  19. vi.mock('../pages/dashboard/customers/CustomerDetailPage', () => ({
  20. CustomerDetailPage: () => <div>customer-detail-page</div>,
  21. }))
  22. vi.mock('../pages/dashboard/templates/TemplateListPage', () => ({
  23. TemplateListPage: () => <div>template-list-page</div>,
  24. }))
  25. vi.mock('../pages/dashboard/templates/TemplateFormPage', () => ({
  26. TemplateFormPage: () => <div>template-form-page</div>,
  27. }))
  28. vi.mock('../pages/dashboard/templates/TemplateDetailPage', () => ({
  29. TemplateDetailPage: () => <div>template-detail-page</div>,
  30. }))
  31. vi.mock('../pages/dashboard/templates/TemplateMakeTaskPage', () => ({
  32. TemplateMakeTaskPage: () => <div>template-make-task-page</div>,
  33. }))
  34. vi.mock('../pages/dashboard/templates/TemplateEditPage', () => ({
  35. TemplateEditPage: () => <div>template-edit-page</div>,
  36. }))
  37. vi.mock('../pages/dashboard/simulation/StylistSimulationPage', () => ({
  38. StylistSimulationPage: () => <div>simulation-page</div>,
  39. }))
  40. vi.mock('../pages/dashboard/simulation/SimulationResultPage', () => ({
  41. SimulationResultPage: () => <div>simulation-result-page</div>,
  42. }))
  43. vi.mock('../pages/dashboard/simulation/SimulationEditPage', () => ({
  44. SimulationEditPage: () => <div>simulation-edit-page</div>,
  45. }))
  46. vi.mock('../pages/dashboard/simulation/AftercareResultPage', () => ({
  47. AftercareResultPage: () => <div>aftercare-result-page</div>,
  48. }))
  49. vi.mock('../pages/customer/StylistProfilePage', () => ({
  50. StylistProfilePage: () => <div>stylist-profile-page</div>,
  51. }))
  52. vi.mock('../pages/customer/CustomerSimulationPage', () => ({
  53. CustomerSimulationPage: () => <div>customer-simulation-page</div>,
  54. }))
  55. vi.mock('../shared/RequireAuth', () => ({
  56. RequireAuth: ({ children }: { children: React.ReactNode }) => <>{children}</>,
  57. }))
  58. describe('App customer routes', () => {
  59. beforeEach(() => {
  60. window.history.replaceState({}, '', '/zh')
  61. })
  62. it('renders customer detail route', async () => {
  63. window.history.replaceState({}, '', '/zh/customers/123')
  64. render(<App />)
  65. await waitFor(() => {
  66. expect(screen.getByText('customer-detail-page')).toBeInTheDocument()
  67. })
  68. })
  69. it('renders customer edit route with the shared form page', async () => {
  70. window.history.replaceState({}, '', '/zh/customers/123/edit')
  71. render(<App />)
  72. await waitFor(() => {
  73. expect(screen.getByText('customer-form-new')).toBeInTheDocument()
  74. })
  75. })
  76. it('renders simulation result detail route with simulationId param', async () => {
  77. window.history.replaceState({}, '', '/zh/simulation/result/91')
  78. render(<App />)
  79. await waitFor(() => {
  80. expect(screen.getByText('simulation-result-page')).toBeInTheDocument()
  81. })
  82. })
  83. it('renders template make task route', async () => {
  84. window.history.replaceState({}, '', '/zh/templates/tasks/88')
  85. render(<App />)
  86. await waitFor(() => {
  87. expect(screen.getByText('template-make-task-page')).toBeInTheDocument()
  88. })
  89. })
  90. it('renders template edit route', async () => {
  91. window.history.replaceState({}, '', '/zh/templates/101/edit')
  92. render(<App />)
  93. await waitFor(() => {
  94. expect(screen.getByText('template-edit-page')).toBeInTheDocument()
  95. })
  96. })
  97. })