Skip to content

Commit fb1e9a3

Browse files
committed
Add unit tests and Vitest configuration for Calendar, Gantt, Grid, Kanban, List, Map, and Timeline plugins
1 parent 1b9555b commit fb1e9a3

21 files changed

Lines changed: 380 additions & 0 deletions
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from 'vite';
3+
import react from '@vitejs/plugin-react';
4+
import path from 'path';
5+
6+
export default defineConfig({
7+
plugins: [react()],
8+
test: {
9+
environment: 'happy-dom',
10+
globals: true,
11+
setupFiles: ['./vitest.setup.ts'],
12+
},
13+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
describe('Plugin Charts Registration', () => {
7+
beforeAll(async () => {
8+
await import('./index');
9+
});
10+
11+
it('registers bar-chart component', () => {
12+
const config = ComponentRegistry.get('bar-chart');
13+
expect(config).toBeDefined();
14+
});
15+
16+
it('registers chart component types', () => {
17+
expect(ComponentRegistry.get('chart-renderer')).toBeDefined(); // Assuming base
18+
// Verify aliases if they exist
19+
expect(ComponentRegistry.get('pie-chart')).toBeDefined();
20+
expect(ComponentRegistry.get('donut-chart')).toBeDefined();
21+
});
22+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from 'vite';
3+
import react from '@vitejs/plugin-react';
4+
import path from 'path';
5+
6+
export default defineConfig({
7+
plugins: [react()],
8+
test: {
9+
environment: 'happy-dom',
10+
globals: true,
11+
setupFiles: ['./vitest.setup.ts'],
12+
},
13+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
describe('Plugin Detail Registration', () => {
7+
beforeAll(async () => {
8+
await import('./index');
9+
});
10+
11+
it('registers detail-view component', () => {
12+
const config = ComponentRegistry.get('detail-view');
13+
expect(config).toBeDefined();
14+
expect(config?.label).toBe('Detail View');
15+
});
16+
17+
it('registers related sub-components', () => {
18+
// Assuming these might be registered in future or implicitly available
19+
// If index.tsx exports them, they are available to import.
20+
// If they are not registered in Registry, we don't test registry for them.
21+
});
22+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from 'vite';
3+
import react from '@vitejs/plugin-react';
4+
import path from 'path';
5+
6+
export default defineConfig({
7+
plugins: [react()],
8+
test: {
9+
environment: 'happy-dom',
10+
globals: true,
11+
setupFiles: ['./vitest.setup.ts'],
12+
},
13+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
vi.mock('./ObjectGantt', () => ({
12+
ObjectGantt: ({ dataSource }: any) => (
13+
<div data-testid="gantt-mock">
14+
{dataSource ? `DataSource: ${dataSource.type}` : 'No DataSource'}
15+
</div>
16+
)
17+
}));
18+
19+
describe('Plugin Gantt Registration', () => {
20+
beforeAll(async () => {
21+
await import('./index');
22+
});
23+
24+
it('registers object-gantt component', () => {
25+
const config = ComponentRegistry.get('object-gantt');
26+
expect(config).toBeDefined();
27+
expect(config?.label).toBe('Object Gantt');
28+
});
29+
30+
it('registered component passes dataSource from context', () => {
31+
const config = ComponentRegistry.get('object-gantt');
32+
const Renderer = config?.component as React.FC<any>;
33+
34+
render(<Renderer schema={{}} />);
35+
expect(screen.getByTestId('gantt-mock')).toHaveTextContent('DataSource: mock-datasource');
36+
});
37+
});

0 commit comments

Comments
 (0)