import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import ContentEditPage from './page';
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
back: jest.fn(),
}),
useParams: () => ({
id: 'new',
}),
}));
jest.mock('next/link', () => {
return ({ children, href }: { children: React.ReactNode; href: string }) => {
return {children};
};
});
jest.mock('next/dynamic', () => () => {
return function MockEditor() {
return
Editor
;
};
});
global.fetch = jest.fn();
describe('ContentEditPage', () => {
beforeEach(() => {
jest.clearAllMocks();
(global.fetch as jest.Mock).mockResolvedValue({
ok: true,
json: async () => ({
type: 'news',
title: 'Test Content',
slug: 'test-content',
excerpt: 'Test excerpt',
content: 'Test content
',
coverImage: '',
category: '',
tags: [],
status: 'draft',
}),
});
});
describe('Rendering', () => {
it('should render content edit page', () => {
render();
const container = document.body;
expect(container).toBeTruthy();
});
it('should render form', () => {
render();
const container = document.body;
expect(container).toBeTruthy();
});
it('should render back button', () => {
render();
const container = document.body;
expect(container).toBeTruthy();
});
});
describe('Functionality', () => {
it('should initialize with default values for new content', () => {
render();
const container = document.body;
expect(container).toBeTruthy();
});
});
describe('Accessibility', () => {
it('should have form labels', () => {
render();
const container = document.body;
expect(container).toBeTruthy();
});
});
});