import ModularUIResponse from "../../../modularui/ModularUIResponse";

import FormWithContentData from "./FormWithContentData.json";
import FormWithContentContributions from "./FormWithContentContributions.json";

import FormModel from "../FormModel";

describe("forms with content in data service", () => {
  it("should be able to create an empty FormModel object", () => {
    const response = ModularUIResponse.create({
      data: FormWithContentData,
      contributions: FormWithContentContributions,
    });
    const form = new FormModel(response);

    expect(form.label).toBe("Beslis noodzaak onderzoek (alle elementen)");

    expect(form.currentFormObject.label).toBe("Beslis noodzaak onderzoek");

    const attribute = form.currentFormObject.getAttributeByKey(
      "UitslagBlaastestType",
    );

    expect(attribute.hasContentFromData).toBe(true);
    expect(attribute.content.fromData).toBe(true);

    expect(attribute.label).toBe("Uitslag blaastest label");
    expect(attribute.content.properties).toStrictEqual([
      {
        type: "MeestGekozen",
        label: "Meest gekozen",
        value: "Pass",
      },
    ]);
    expect(attribute.content.textfragments).toStrictEqual([
      {
        text: "Dit is een text fragment",
        label: "Description",
        type: "Description",
      },
    ]);
    expect(attribute.content.sections[0].body).toBe(
      "<p>Vul hier de code in die het testapparaat op het display heeft getoond</p>",
    );

    const firstOption = attribute.options.first;
    expect(firstOption.code).toBe("BlaastestPass");

    expect(firstOption.hasContentFromData).toBe(true);
    expect(firstOption.content.fromData).toBe(true);

    expect(firstOption.label).toBe("Blaastest geslaagd");
    expect(firstOption.content.properties).toStrictEqual([
      {
        type: "Gemiddelde",
        label: "Gemiddelde",
        value: "80%",
      },
    ]);
    expect(firstOption.content.textfragments).toStrictEqual([
      {
        text: "Dit is een text fragment",
        label: "Description",
        type: "Description",
      },
    ]);
    expect(firstOption.content.sections[0].body).toBe(
      "<p>De blaastest heeft geen alcohol constateerd (versie 2017)</p>",
    );
  });
});
