@@ -91,42 +91,98 @@ describe('Console View Switching Integration', () => {
9191 expect ( screen . getByText ( 'Sites' ) ) . toBeInTheDocument ( ) ;
9292 } ) ;
9393
94- it ( 'switches to Timeline view correctly' , ( ) => {
94+ it ( 'switches to Timeline view correctly' , async ( ) => {
9595 // Force view to 'history' (timeline)
9696 mockSearchParams . set ( 'view' , 'history' ) ;
9797
98- renderObjectView ( ) ;
98+ // Mock data for project task
99+ // We must mock the find method to return data that the TIMELINE can render
100+ // Timeline expects: titleField='name', dateField='due_date'
101+ const mockTasks = [
102+ { id : '1' , name : 'Task 1' , due_date : '2023-01-01' , status : 'Todo' } ,
103+ { id : '2' , name : 'Task 2' , due_date : '2023-01-05' , status : 'Done' }
104+ ] ;
105+
106+ // Setup mock response
107+ mockDataSource . find . mockResolvedValue ( { value : mockTasks } ) ;
108+
109+ const { container, debug } = renderObjectView ( ) ;
99110
100111 // 1. Check registry has the component (verifies import)
101112 expect ( ComponentRegistry . has ( 'object-timeline' ) ) . toBe ( true ) ;
102113
103114 // 2. Check no error boundary (verifies unknown type)
104115 expect ( screen . queryByText ( / U n k n o w n c o m p o n e n t t y p e / i) ) . not . toBeInTheDocument ( ) ;
105116
106- // 3. Check CONTENT is rendered (verifies options/props passed correctly + not blank)
107- // Since we are using the real Timeline component, we need to know what it renders when empty.
108- // It usually renders a list or empty state.
109- // If options were missing, it might crash or render completely blank.
110- // Let's assume it renders at least the wrapper or "No items"
111- const timeline = document . querySelector ( '.object-timeline' ) || document . querySelector ( 'ol' ) ;
112- expect ( timeline ) . toBeInTheDocument ( ) ;
117+ // 3. Wait for data loading and verify CONTENT
118+ // Timeline renders <Timeline> -> <TimelineItem>
119+ // We expect to see "Task 1" and "Task 2" in the document
120+ await waitFor ( ( ) => {
121+ expect ( screen . getByText ( 'Task 1' ) ) . toBeInTheDocument ( ) ;
122+ expect ( screen . getByText ( 'Task 2' ) ) . toBeInTheDocument ( ) ;
123+ } ) ;
124+
125+ // Inspect DOM structure slightly deeper
126+ // Timeline plugins usually use distinct classes or elements (ol/li)
127+ const timelineList = container . querySelector ( 'ol' ) ;
128+ expect ( timelineList ) . toBeInTheDocument ( ) ;
113129 } ) ;
114130
115- it ( 'switches to Map view correctly' , ( ) => {
131+ it ( 'switches to Map view correctly' , async ( ) => {
116132 mockSearchParams . set ( 'view' , 'sites' ) ;
117- renderObjectView ( ) ;
133+
134+ // Mock Map Data with Location
135+ const mockSites = [
136+ { id : '1' , name : 'Site Alpha' , location : { lat : 40 , lng : - 74 } } ,
137+ { id : '2' , name : 'Site Beta' , location : { lat : 41 , lng : - 75 } }
138+ ] ;
139+ mockDataSource . find . mockResolvedValue ( { value : mockSites } ) ;
140+
141+ const { container } = renderObjectView ( ) ;
118142
119143 expect ( ComponentRegistry . has ( 'object-map' ) ) . toBe ( true ) ;
120144 expect ( screen . queryByText ( / U n k n o w n c o m p o n e n t t y p e / i) ) . not . toBeInTheDocument ( ) ;
121145
122146 // 3. Verify content
123147 // Map usually renders a container.
124- // If we missed options mapping, it might be 0 height or error.
125- const mapContainer = document . querySelector ( '.object-map' ) || document . querySelector ( '[class*="leaflet"]' ) ;
126- // Since we don't have leaflet installed/mocked fully, it might be just a div.
127- // But checking that *something* is in the View area is key.
148+ // It might be hard to verify "Site Alpha" if it's rendered inside a Canvas or proprietary Map,
149+ // BUT our ObjectMap implementation might render markers as divs if it's a simple implementation.
150+ // Let's assume it renders a marker list or similar for accessibility if map fails,
151+ // OR we just verify the container exists.
152+
153+ // If ObjectMap uses Leaflet/GoogleMaps, checking for specific text inside the map container might be flaky
154+ // unless we mock the map library.
155+ // For now, let's verify the wrapper is there.
128156 const viewArea = document . querySelector ( '.flex-1.overflow-hidden.relative' ) ;
129157 expect ( viewArea ) . not . toBeEmptyDOMElement ( ) ;
158+
159+ // Attempt to wait for map initialization (if async)
160+ await waitFor ( ( ) => {
161+ // If ObjectMap lists items in a side panel or similar:
162+ // expect(screen.getByText('Site Alpha')).toBeInTheDocument();
163+
164+ // If not, we just confirm the view didn't crash
165+ expect ( ComponentRegistry . has ( 'object-map' ) ) . toBe ( true ) ;
166+ } ) ;
167+ } ) ;
168+
169+ it ( 'switches to Gantt view correctly' , async ( ) => {
170+ mockSearchParams . set ( 'view' , 'roadmap' ) ;
171+
172+ const mockGanttData = [
173+ { id : '1' , name : 'Phase 1' , start : '2023-01-01' , end : '2023-01-05' }
174+ ] ;
175+ mockDataSource . find . mockResolvedValue ( { value : mockGanttData } ) ;
176+
177+ const { container } = renderObjectView ( ) ;
178+
179+ expect ( screen . queryByText ( / U n k n o w n c o m p o n e n t t y p e / i) ) . not . toBeInTheDocument ( ) ;
180+
181+ // Verify Gantt loaded
182+ // Usually Gantt renders "Phase 1" in the task list on the left
183+ await waitFor ( ( ) => {
184+ expect ( screen . getByText ( 'Phase 1' ) ) . toBeInTheDocument ( ) ;
185+ } ) ;
130186 } ) ;
131187
132188 it ( 'switches to Gantt view correctly' , ( ) => {
0 commit comments