import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react-native';
import { ProductEditorItem } from '../ProductEditorItem';
import { Product } from '@/lib/product';
import { area } from 'enheter';

describe('ProductEditorItem', () => {
  const mockProduct = new Product(
    25,
    area("squareFoot", 4 * 8),
    {"name": "Product 1"},
  )

  const mockOnProductUpdated = jest.fn();
  const mockOnProductDeleted = jest.fn();

  it('renders correctly', () => {
    render(
      <ProductEditorItem
        product={mockProduct}
        onProductUpdated={mockOnProductUpdated}
        onProductDeleted={mockOnProductDeleted}
      />
    );
    expect(screen.getAllByText('Product 1').length).toEqual(1);
  });

  it('calls onProductUpdated when TouchableHighlight is pressed', () => {
    render(
      <ProductEditorItem
        product={mockProduct}
        onProductUpdated={mockOnProductUpdated}
        onProductDeleted={mockOnProductDeleted}
      />
    );
    fireEvent.press(screen.getByText("Product 1"));
    expect(screen.getByText('name')).toBeTruthy();
    expect(screen.getAllByText('Product 1').length).toEqual(2);
  });
});
