|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { describe, it, expect, vi, beforeAll } from 'vitest'; |
| 4 | +import { ComponentRegistry } from '@object-ui/core'; |
| 5 | + |
| 6 | +// Mock dependencies |
| 7 | +vi.mock('@object-ui/react', () => ({ |
| 8 | + useSchemaContext: vi.fn(() => ({ dataSource: { type: 'mock-datasource' } })), |
| 9 | +})); |
| 10 | + |
| 11 | +// Mock the implementation |
| 12 | +vi.mock('./ObjectCalendar', () => ({ |
| 13 | + ObjectCalendar: ({ dataSource }: any) => ( |
| 14 | + <div data-testid="calendar-mock"> |
| 15 | + {dataSource ? `DataSource: ${dataSource.type}` : 'No DataSource'} |
| 16 | + </div> |
| 17 | + ) |
| 18 | +})); |
| 19 | + |
| 20 | +describe('Plugin Calendar Registration', () => { |
| 21 | + beforeAll(async () => { |
| 22 | + // Import index to trigger registration |
| 23 | + await import('./index'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('registers object-calendar component', () => { |
| 27 | + const config = ComponentRegistry.get('object-calendar'); |
| 28 | + expect(config).toBeDefined(); |
| 29 | + // Label might be 'Object Calendar' - checking existence mostly |
| 30 | + }); |
| 31 | + |
| 32 | + it('registered component passes dataSource from context', () => { |
| 33 | + const config = ComponentRegistry.get('object-calendar'); |
| 34 | + const Renderer = config?.component as React.FC<any>; |
| 35 | + |
| 36 | + expect(Renderer).toBeDefined(); |
| 37 | + |
| 38 | + render(<Renderer schema={{}} />); |
| 39 | + |
| 40 | + expect(screen.getByTestId('calendar-mock')).toHaveTextContent('DataSource: mock-datasource'); |
| 41 | + }); |
| 42 | +}); |
0 commit comments