import { describe, beforeEach } from '@jest/globals';
import { screen } from '@testing-library/react';
import { renderWithProviders, resetFlowStore } from '../.././/./../../test-utils/test-utils';
import type { XYPosition } from '@xyflow/react';
import { NodeTypes, NodeDefaults } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/NodeRegistry';
import '@testing-library/jest-dom'


describe('NormNode', () => {
  // let user: ReturnType<typeof userEvent.setup>;

  // Copied from VisStores.
  function createNode(id: string, type: string, position: XYPosition, data: Record<string, unknown>, deletable? : boolean) {
    const defaultData = NodeDefaults[type as keyof typeof NodeDefaults]
    const newData = {
        id: id,
        type: type,
        position: position,
        data: data,
        deletable: deletable,
    }
    return {...defaultData, ...newData}
  }  
    

  beforeEach(() => {
    resetFlowStore();
    // user = userEvent.setup();
  });

  describe('Rendering', () => {
    test.each([Object.entries(NodeTypes)].map(([t])=>t))('it should render each node with the default data', (nodeType) => {
        let newNode = createNode(nodeType + "1", nodeType, {x: 200, y:200}, {})
        let uiElement = Object.entries(NodeTypes).find(([t])=>t==nodeType)?.[1]!;
        let props = {
          id:newNode.id,
          type:newNode.type as string,
          data:newNode.data as any,
          selected:false,
          isConnectable:true,
          zIndex:0,
          dragging:false,
          selectable:true,
          deletable:true,
          draggable:true,
          positionAbsoluteX:0,
          positionAbsoluteY:0,}
        renderWithProviders(uiElement(props));
        const elements = screen.queryAllByText((content, ) => 
        content.toLowerCase().includes(nodeType.toLowerCase())
      );
      expect(elements.length).toBeGreaterThan(0);
    }); 
  });
});