tests
This commit is contained in:
55
sites/src/__tests__/fileAccess.test.ts
Normal file
55
sites/src/__tests__/fileAccess.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Tests for File Access
|
||||
* Phase 5: Sites Renderer & Bulk Generation
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { getFileUrl, getImageUrl } from '../utils/fileAccess';
|
||||
|
||||
// Mock fetch
|
||||
global.fetch = vi.fn();
|
||||
|
||||
describe('File Access', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('loads images correctly', async () => {
|
||||
// Test: File access works (images, documents, media)
|
||||
const mockImageUrl = 'https://example.com/images/test.jpg';
|
||||
|
||||
(global.fetch as any).mockResolvedValueOnce({
|
||||
ok: true,
|
||||
url: mockImageUrl,
|
||||
});
|
||||
|
||||
const url = await getImageUrl(1, 'test.jpg', 1);
|
||||
expect(url).toBeDefined();
|
||||
});
|
||||
|
||||
it('loads documents correctly', async () => {
|
||||
// Test: File access works (images, documents, media)
|
||||
const mockDocUrl = 'https://example.com/documents/test.pdf';
|
||||
|
||||
(global.fetch as any).mockResolvedValueOnce({
|
||||
ok: true,
|
||||
url: mockDocUrl,
|
||||
});
|
||||
|
||||
const url = await getFileUrl(1, 'documents', 'test.pdf', 1);
|
||||
expect(url).toBeDefined();
|
||||
});
|
||||
|
||||
it('loads media files correctly', async () => {
|
||||
// Test: File access works (images, documents, media)
|
||||
const mockMediaUrl = 'https://example.com/media/test.mp4';
|
||||
|
||||
(global.fetch as any).mockResolvedValueOnce({
|
||||
ok: true,
|
||||
url: mockMediaUrl,
|
||||
});
|
||||
|
||||
const url = await getFileUrl(1, 'media', 'test.mp4', 1);
|
||||
expect(url).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
86
sites/src/__tests__/layoutRenderer.test.tsx
Normal file
86
sites/src/__tests__/layoutRenderer.test.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Tests for Layout Renderer
|
||||
* Phase 5: Sites Renderer & Bulk Generation
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { renderLayout } from '../utils/layoutRenderer';
|
||||
|
||||
describe('Layout Renderer', () => {
|
||||
it('renders default layout correctly', () => {
|
||||
// Test: Multiple layouts work correctly
|
||||
const siteDefinition = {
|
||||
layout: 'default',
|
||||
pages: [],
|
||||
};
|
||||
|
||||
const result = renderLayout(siteDefinition);
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
it('renders minimal layout correctly', () => {
|
||||
// Test: Multiple layouts work correctly
|
||||
const siteDefinition = {
|
||||
layout: 'minimal',
|
||||
pages: [],
|
||||
};
|
||||
|
||||
const result = renderLayout(siteDefinition);
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
it('renders magazine layout correctly', () => {
|
||||
// Test: Multiple layouts work correctly
|
||||
const siteDefinition = {
|
||||
layout: 'magazine',
|
||||
pages: [],
|
||||
};
|
||||
|
||||
const result = renderLayout(siteDefinition);
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
it('renders ecommerce layout correctly', () => {
|
||||
// Test: Multiple layouts work correctly
|
||||
const siteDefinition = {
|
||||
layout: 'ecommerce',
|
||||
pages: [],
|
||||
};
|
||||
|
||||
const result = renderLayout(siteDefinition);
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
it('renders portfolio layout correctly', () => {
|
||||
// Test: Multiple layouts work correctly
|
||||
const siteDefinition = {
|
||||
layout: 'portfolio',
|
||||
pages: [],
|
||||
};
|
||||
|
||||
const result = renderLayout(siteDefinition);
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
it('renders blog layout correctly', () => {
|
||||
// Test: Multiple layouts work correctly
|
||||
const siteDefinition = {
|
||||
layout: 'blog',
|
||||
pages: [],
|
||||
};
|
||||
|
||||
const result = renderLayout(siteDefinition);
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
it('renders corporate layout correctly', () => {
|
||||
// Test: Multiple layouts work correctly
|
||||
const siteDefinition = {
|
||||
layout: 'corporate',
|
||||
pages: [],
|
||||
};
|
||||
|
||||
const result = renderLayout(siteDefinition);
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
49
sites/src/__tests__/loadSiteDefinition.test.ts
Normal file
49
sites/src/__tests__/loadSiteDefinition.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Tests for Site Definition Loader
|
||||
* Phase 5: Sites Renderer & Bulk Generation
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { loadSiteDefinition } from '../loaders/loadSiteDefinition';
|
||||
|
||||
// Mock fetch
|
||||
global.fetch = vi.fn();
|
||||
|
||||
describe('Site Definition Loader', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('loads site definitions from API', async () => {
|
||||
// Test: Sites renderer loads site definitions
|
||||
const mockSiteDefinition = {
|
||||
id: 1,
|
||||
name: 'Test Site',
|
||||
pages: [
|
||||
{ id: 1, slug: 'home', title: 'Home' },
|
||||
{ id: 2, slug: 'about', title: 'About' },
|
||||
],
|
||||
};
|
||||
|
||||
(global.fetch as any).mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({ data: mockSiteDefinition }),
|
||||
});
|
||||
|
||||
const result = await loadSiteDefinition(1);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.name).toBe('Test Site');
|
||||
expect(result.pages).toHaveLength(2);
|
||||
expect(global.fetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining('/api/v1/site-builder/blueprints/1/')
|
||||
);
|
||||
});
|
||||
|
||||
it('handles API errors gracefully', async () => {
|
||||
// Test: Sites renderer loads site definitions
|
||||
(global.fetch as any).mockRejectedValueOnce(new Error('API Error'));
|
||||
|
||||
await expect(loadSiteDefinition(1)).rejects.toThrow('API Error');
|
||||
});
|
||||
});
|
||||
|
||||
28
sites/src/__tests__/setup.ts
Normal file
28
sites/src/__tests__/setup.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Test Setup
|
||||
* Phase 5: Sites Renderer Tests
|
||||
*/
|
||||
import { expect, afterEach } from 'vitest';
|
||||
import { cleanup } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
// Cleanup after each test
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
// Mock window.matchMedia
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
writable: true,
|
||||
value: (query: string) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: () => {},
|
||||
removeListener: () => {},
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
dispatchEvent: () => {},
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user