40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
const DATA_DIR = path.join(process.cwd(), 'app', 'test_data_sections');
|
|
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
|
|
|
|
|
|
describe('Editor Sections API Test', () => {
|
|
beforeEach(async () => {
|
|
await fs.mkdir(DATA_DIR, { recursive: true });
|
|
const dummyConfig = {
|
|
site_info: { title: 'Test Site', homepage_id: 'page_1' },
|
|
pages: [
|
|
{
|
|
id: 'page_1',
|
|
slug: '/',
|
|
title: 'Home',
|
|
sections: [{ id: 'sec_1', type: 'HeroSection', settings: { title: 'Old Hero' } }]
|
|
}
|
|
]
|
|
};
|
|
await fs.writeFile(draftPath, JSON.stringify(dummyConfig, null, 2), 'utf-8');
|
|
});
|
|
|
|
it('soll Sektionen in site.config.draft.json erfolgreich überschreiben', async () => {
|
|
const raw = await fs.readFile(draftPath, 'utf-8');
|
|
const config = JSON.parse(raw);
|
|
|
|
config.pages[0].sections.push({ id: 'sec_2', type: 'BentoGrid', settings: {} });
|
|
await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
|
|
const updatedRaw = await fs.readFile(draftPath, 'utf-8');
|
|
const updatedConfig = JSON.parse(updatedRaw);
|
|
|
|
expect(updatedConfig.pages[0].sections).toHaveLength(2);
|
|
expect(updatedConfig.pages[0].sections[1].type).toBe('BentoGrid');
|
|
});
|
|
});
|