const { createCardFactory } = require('./card-factory');

describe('Card Factory', () => {
  it('should create new text card with details object', () => {
    const textCard = createCardFactory('TEXT');
    const validate = textCard.validate();
    expect(textCard.details).toEqual({
      header: null,
      draftJs: null,
      text: '',
    });
    expect(validate.valid).toBeTruthy();
  });

  it('should create acknowledgement card with label details', () => {
    const card = createCardFactory('ACKNOWLEDGEMENT', {
      details: { prompt: 'ack' },
    });
    const validate = card.validate();
    expect(validate.valid).toBeTruthy();
    expect(card.details.prompt).toMatch(/ack/);
  });

  it('should create line item card', () => {
    const card = createCardFactory('TABLE', {
      details: {
        schema: [
          { key: 'description', label: 'Description', type: 'TEXT' },
          { key: 'date', label: 'Date', type: 'DATE' },
        ],
      },
    });

    const validate = card.validate();
    expect(validate.valid).toBeTruthy();
  });

  it('should create a condition card with children cards', () => {
    const card = createCardFactory('CONDITION', {
      details: {
        header: 'Equipments',
        conditions: {
          SIT: [
            {
              type: 'VALUE_UNIT',
              details: {
                unitOptions: ['Quantity'],
                countLabel: 'Sit to Stand device(s) Non Powered',
                valueDescription: 'Quantity',
                infoDescription: null,
              },
            },
            {
              type: 'SELECT',
              isMovable: false,
              allowAttachments: false,
              details: {
                name: 'Asset Information',
                optionsId: '5acd4016cee0ae01aac5c62b',
                questions: [
                  {
                    label: 'Has RFID?',
                    value: null,
                  },
                ],
                notes: null,
              },
            },
          ],
        },
      },
    });

    const validate = card.validate();
    expect(validate.valid).toBeTruthy();
    expect(card.details.conditions.SIT.length).toEqual(2);
    expect(card.details.conditions.SIT.map((c) => c.type)).toEqual(expect.arrayContaining(['VALUE_UNIT', 'SELECT']));
  });
});
