|
| 1 | + |
| 2 | +import { describe, it, expect, vi, beforeAll } from 'vitest'; |
| 3 | +import { render, screen, waitFor } from '@testing-library/react'; |
| 4 | +import { MemoryRouter, Routes, Route } from 'react-router-dom'; |
| 5 | +import React from 'react'; |
| 6 | +import appConfig from '../../objectstack.config'; |
| 7 | + |
| 8 | +// ----------------------------------------------------------------------------- |
| 9 | +// SYSTEM INTEGRATION TEST |
| 10 | +// ----------------------------------------------------------------------------- |
| 11 | +// This test simulates the exact browser runtime environment of the Console App. |
| 12 | +// It verifies that the configuration loaded from 'kitchen-sink' is correctly |
| 13 | +// processed by the router and the 'PageRenderer' component we just fixed. |
| 14 | +// ----------------------------------------------------------------------------- |
| 15 | + |
| 16 | +// 1. Mock the DataSource to avoid real network calls |
| 17 | +class MockDataSource { |
| 18 | + async retrieve() { return {}; } |
| 19 | + async find() { return []; } |
| 20 | +} |
| 21 | +const mockClient = { |
| 22 | + connect: vi.fn().mockResolvedValue(true) |
| 23 | +}; |
| 24 | + |
| 25 | +// 2. Mock App Dependencies that are outside the scope of UI rendering |
| 26 | +vi.mock('@objectstack/client', () => ({ |
| 27 | + ObjectStackClient: vi.fn(() => mockClient) |
| 28 | +})); |
| 29 | +vi.mock('../dataSource', () => ({ |
| 30 | + ObjectStackDataSource: vi.fn(() => new MockDataSource()) |
| 31 | +})); |
| 32 | + |
| 33 | +// 3. Import Components under test |
| 34 | +import { PageView } from '../components/PageView'; |
| 35 | + |
| 36 | +describe('System Integration: Help Page Rendering', () => { |
| 37 | + |
| 38 | + it('should successfully locate and render the "help_page" from kitchen-sink config', async () => { |
| 39 | + // A. Verify Configuration Integrity |
| 40 | + const helpPage = appConfig.pages?.find((p: any) => p.name === 'help_page'); |
| 41 | + expect(helpPage).toBeDefined(); |
| 42 | + |
| 43 | + // B. Simulate Browser Navigation |
| 44 | + // IMPORTANT: We must setup the Route path so :pageName param is captured |
| 45 | + render( |
| 46 | + <MemoryRouter initialEntries={['/page/help_page']}> |
| 47 | + <Routes> |
| 48 | + <Route path="/page/:pageName" element={<PageView />} /> |
| 49 | + </Routes> |
| 50 | + </MemoryRouter> |
| 51 | + ); |
| 52 | + |
| 53 | + // C. Verify Visual Output |
| 54 | + await waitFor(() => { |
| 55 | + expect(screen.getByText(/Application Guide/i)).toBeInTheDocument(); |
| 56 | + }); |
| 57 | + |
| 58 | + expect(screen.getByText(/Welcome to the ObjectStack Console/i)).toBeInTheDocument(); |
| 59 | + expect(screen.getByText(/Dynamic Object CRUD/i)).toBeInTheDocument(); |
| 60 | + }); |
| 61 | +}); |
0 commit comments