import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import { OrganizationSchema, WebsiteSchema } from './structured-data';
import { COMPANY_INFO } from '@/lib/constants';

describe('StructuredData', () => {
  beforeEach(() => {
    jest.clearAllMocks();
  });

  describe('OrganizationSchema', () => {
    it('should render organization schema', () => {
      const { container } = render(<OrganizationSchema />);
      const script = container.querySelector('script[type="application/ld+json"]');
      expect(script).toBeInTheDocument();
    });

    it('should contain organization name', () => {
      const { container } = render(<OrganizationSchema />);
      const script = container.querySelector('script[type="application/ld+json"]');
      const schema = JSON.parse(script?.textContent || '{}');
      expect(schema.name).toBe(COMPANY_INFO.name);
    });

    it('should contain organization type', () => {
      const { container } = render(<OrganizationSchema />);
      const script = container.querySelector('script[type="application/ld+json"]');
      const schema = JSON.parse(script?.textContent || '{}');
      expect(schema['@type']).toBe('Organization');
    });

    it('should contain URL', () => {
      const { container } = render(<OrganizationSchema />);
      const script = container.querySelector('script[type="application/ld+json"]');
      const schema = JSON.parse(script?.textContent || '{}');
      expect(schema.url).toBe('https://www.novalon.cn');
    });
  });

  describe('WebsiteSchema', () => {
    it('should render website schema', () => {
      const { container } = render(<WebsiteSchema />);
      const script = container.querySelector('script[type="application/ld+json"]');
      expect(script).toBeInTheDocument();
    });

    it('should contain website type', () => {
      const { container } = render(<WebsiteSchema />);
      const script = container.querySelector('script[type="application/ld+json"]');
      const schema = JSON.parse(script?.textContent || '{}');
      expect(schema['@type']).toBe('WebSite');
    });

    it('should contain website name', () => {
      const { container } = render(<WebsiteSchema />);
      const script = container.querySelector('script[type="application/ld+json"]');
      const schema = JSON.parse(script?.textContent || '{}');
      expect(schema.name).toBe(COMPANY_INFO.name);
    });
  });
});
