/* eslint-disable quotes */
import {
  AI_AUTO_GENERATED_FIELDS_DEFAULT,
  parseAiAutoGeneratedFieldsString,
  parseTitleAndCaption,
} from "@/photo/ai";

describe('AI parses', () => {
  describe('auto-generated fields', () => {
    it('with spaces', () => {
      expect(parseAiAutoGeneratedFieldsString())
        .toStrictEqual(AI_AUTO_GENERATED_FIELDS_DEFAULT);
      expect(parseAiAutoGeneratedFieldsString('all'))
        .toStrictEqual(['title', 'caption', 'tags', 'semantic']);
      expect(parseAiAutoGeneratedFieldsString('title'))
        .toStrictEqual(['title']);
      expect(parseAiAutoGeneratedFieldsString('title, caption'))
        .toStrictEqual(['title', 'caption']);
      expect(parseAiAutoGeneratedFieldsString('title, caption, invalid'))
        .toStrictEqual(['title', 'caption']);
      expect(parseAiAutoGeneratedFieldsString('title, caption, invalid, tags'))
        .toStrictEqual(['title', 'caption', 'tags']);
      expect(parseAiAutoGeneratedFieldsString('none'))
        .toStrictEqual([]);
    });
    it('without spaces', () => {
      expect(parseAiAutoGeneratedFieldsString('title,caption'))
        .toStrictEqual(['title', 'caption']);
      expect(parseAiAutoGeneratedFieldsString('title,caption,invalid'))
        .toStrictEqual(['title', 'caption']);
      expect(parseAiAutoGeneratedFieldsString('title,caption,invalid,tags'))
        .toStrictEqual(['title', 'caption', 'tags']);
    });
  });
  it('received titles and captions', () => {
    // Complex case
    expect(parseTitleAndCaption(
      `'Title: "Ephemeral Beauty" Caption: "Roses bask in fleeting sunlight."'`,
    )).toStrictEqual({
      title: 'Ephemeral Beauty',
      caption: 'Roses bask in fleeting sunlight',
    });
    // Without surrounding single quotes
    expect(parseTitleAndCaption(
      `Title: "Ephemeral Beauty"  Caption: "Roses bask in fleeting sunlight."`,
    )).toStrictEqual({
      title: 'Ephemeral Beauty',
      caption: 'Roses bask in fleeting sunlight',
    });
    // Without trailing period
    expect(parseTitleAndCaption(
      `Title: "Ephemeral Beauty"  Caption: "Roses bask in fleeting sunlight"`,
    )).toStrictEqual({
      title: 'Ephemeral Beauty',
      caption: 'Roses bask in fleeting sunlight',
    });
    // Without and quotes
    expect(parseTitleAndCaption(
      `Title: Ephemeral Beauty  Caption: Roses bask in fleeting sunlight`,
    )).toStrictEqual({
      title: 'Ephemeral Beauty',
      caption: 'Roses bask in fleeting sunlight',
    });
    // With single space
    expect(parseTitleAndCaption(
      `Title: Ephemeral Beauty Caption: Roses bask in fleeting sunlight`,
    )).toStrictEqual({
      title: 'Ephemeral Beauty',
      caption: 'Roses bask in fleeting sunlight',
    });
  });
});
