/**
 * Tests for edgeTypeUtils
 */

import { getEdgeType, getEdgeTypeWithCondition } from '../edgeTypeUtils';

describe('edgeTypeUtils', () => {
  describe('getEdgeType', () => {
    it('should return "default" for null data', () => {
      expect(getEdgeType(null)).toBe('default');
    });

    it('should return "default" for undefined data', () => {
      expect(getEdgeType(undefined)).toBe('default');
    });

    it('should return "default" for empty data', () => {
      expect(getEdgeType({})).toBe('default');
    });

    it('should return "condition" when data has condition', () => {
      expect(getEdgeType({ condition: 'some-plugin' })).toBe('condition');
    });

    it('should return "condition" when data has conditionLabel', () => {
      expect(getEdgeType({ conditionLabel: 'My Condition' })).toBe('condition');
    });

    it('should return "condition" when data has conditionConfiguration', () => {
      expect(getEdgeType({ conditionConfiguration: { key: 'value' } })).toBe('condition');
    });

    it('should return "annotation" when data has annotation', () => {
      expect(getEdgeType({ annotation: 'Some note' })).toBe('annotation');
    });

    it('should return "condition" when both condition and annotation exist', () => {
      expect(getEdgeType({ condition: 'plugin', annotation: 'note' })).toBe('condition');
    });

    it('should return "default" when all condition fields are null/empty', () => {
      expect(getEdgeType({ condition: null, conditionLabel: null, conditionConfiguration: null, annotation: null })).toBe('default');
    });

    it('should return "default" when condition is empty string', () => {
      expect(getEdgeType({ condition: '' })).toBe('default');
    });
  });

  describe('getEdgeTypeWithCondition', () => {
    it('should return "condition" when newCondition is truthy', () => {
      expect(getEdgeTypeWithCondition('plugin-id', {})).toBe('condition');
    });

    it('should return "condition" when newCondition is null but existingData has condition', () => {
      expect(getEdgeTypeWithCondition(null, { condition: 'existing' })).toBe('condition');
    });

    it('should return "annotation" when no conditions but annotation exists', () => {
      expect(getEdgeTypeWithCondition(null, { annotation: 'note' })).toBe('annotation');
    });

    it('should return "default" when no condition and no annotation', () => {
      expect(getEdgeTypeWithCondition(null, {})).toBe('default');
    });

    it('should return "default" when all values are null/undefined', () => {
      expect(getEdgeTypeWithCondition(null, null)).toBe('default');
    });

    it('should return "default" when newCondition is undefined', () => {
      expect(getEdgeTypeWithCondition(undefined, undefined)).toBe('default');
    });

    it('should return "condition" when newCondition is truthy and annotation also exists', () => {
      expect(getEdgeTypeWithCondition('plugin', { annotation: 'note' })).toBe('condition');
    });

    it('should return "condition" when existingData has conditionConfiguration', () => {
      expect(getEdgeTypeWithCondition(null, { conditionConfiguration: { key: 'val' } })).toBe('condition');
    });
  });
});
