import * as React from "react";
import "babel-polyfill";
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
import EditFormField from "./EditFormField";
import { FormFieldTypes } from "../types";
const testId = "FormBuilder-EditFormField";
const textFieldTestId = "FormBuilder-FormFields-TextField-EDITOR";
const dateFieldTestId = "FormBuilder-FormFields-DateField-EDITOR";
const dropDownTestId = "FormBuilder-FormFields-DropdownField-EDITOR";
const textAreaTestId = "FormBuilder-FormFields-TextAreaField-EDITOR";
const checkboxesTestId = "FormBuilder-FormFields-Checkboxes-EDITOR";
const multipleChoiceTestId = "FormBuilder-FormFields-MultipleChoice-EDITOR";
const contentFieldTestId = "FormBuilder-FormFields-ContentField-EDITOR";
const fileUploadTestId = "FormBuilder-FormFields-FileUpload-EDITOR";
const linearScaleTestId = "FormBuilder-FormFields-LinearScaleField-EDITOR";
const allTestIds = {
TEXT: textFieldTestId,
PASSWORD: textFieldTestId,
CHECKBOXES: checkboxesTestId,
// RADIO: multipleChoiceTestId,
TEXTAREA: textAreaTestId,
SELECT: dropDownTestId,
DATE: dateFieldTestId,
CONTENT: contentFieldTestId,
NUMBER: textFieldTestId,
CURRENCY: textFieldTestId,
DROPDOWN: dropDownTestId,
MULTIPLECHOICE: multipleChoiceTestId,
TYPOGRAPHY: contentFieldTestId,
FILEUPLOAD: fileUploadTestId,
LINEARSCALE: linearScaleTestId,
};
const props = {
isExpanded: true,
fieldData: {
attributeContainerDataSettings: { hide: false },
},
};
describe(" Rendering Tests", () => {
afterEach(cleanup);
it(`Should render in the dom`, () => {
render();
expect(screen.queryByTestId(testId)).toBeTruthy();
});
it(`Should show the when the type prop is TEXT`, () => {
render();
expect(screen.queryByTestId(textFieldTestId)).toBeTruthy();
});
it(`Should show the when the type prop is DATE`, () => {
render();
expect(screen.queryByTestId(dateFieldTestId)).toBeTruthy();
});
it(`Should show the input when the type prop is NUMBER`, () => {
render();
expect(screen.queryByTestId(textFieldTestId)).toBeTruthy();
});
it(`Should show the when the type prop is CURRENCY`, () => {
render();
expect(screen.queryByTestId(textFieldTestId)).toBeTruthy();
});
it(`Should show menu when the type prop is DROPDOWN`, () => {
render();
expect(screen.queryByTestId(dropDownTestId)).toBeTruthy();
});
it(`Should show a checkbox & label ( the when type prop is CHECKBOXES`, () => {
render();
expect(screen.queryByTestId(checkboxesTestId)).toBeTruthy();
});
it(`Should show radio input fields ( the when type prop is MULTIPLECHOICE`, () => {
render();
expect(screen.queryByTestId(multipleChoiceTestId)).toBeTruthy();
});
it(`Should show a the when type prop is TEXTAREA`, () => {
render();
expect(screen.queryByTestId(textAreaTestId)).toBeTruthy();
});
it(`Should show a the when type prop is TYPOGRAPHY`, () => {
render();
expect(screen.queryByTestId(contentFieldTestId)).toBeTruthy();
});
it(`Should show a component when the type prop is FILEUPLOAD`, () => {
render();
expect(screen.queryByTestId(fileUploadTestId)).toBeTruthy();
});
it(`Should show a component when the type prop is LINEARSCALE`, () => {
render();
expect(screen.queryByTestId(linearScaleTestId)).toBeTruthy();
});
it(`Should show an icon in the dom that reflects the item being loaded`, () => {
const iconTestId = "Properties-IconSelector-input";
const { rerender } = render(
);
// TextField
rerender();
expect(screen.queryByTestId(iconTestId)).toBeTruthy();
// DateField
rerender();
expect(screen.queryByTestId(iconTestId)).toBeTruthy();
// DropdownField
rerender();
expect(screen.queryByTestId(iconTestId)).toBeTruthy();
// TextAreaField
rerender();
expect(screen.queryByTestId(iconTestId)).toBeTruthy();
});
it(`Show in expanded state when isExpanded is true`, () => {
const { rerender } = render();
for (let type in FormFieldTypes) {
rerender(
);
expect(screen.queryByTestId(allTestIds[type])).not.toBeTruthy();
}
for (let type in FormFieldTypes) {
rerender();
expect(screen.queryByTestId(allTestIds[type])).toBeTruthy();
}
});
it(`Should show the LIVE preview of the component when showPreview is true`, () => {
const { rerender } = render();
for (let type in FormFieldTypes) {
rerender(
);
expect(
screen.queryByTestId(allTestIds[type].replace("EDITOR", "LIVE"))
).toBeTruthy();
}
});
it(`Should show the caption provided in the dom`, () => {
const caption = "Testing Caption Text";
render(
);
expect(screen.getAllByText(caption)).toBeTruthy();
});
});
describe(" Events Tests", () => {
afterEach(cleanup);
test.todo(
`Should trigger the onChange event when any change occurs in the form field`
);
test.todo(
`Should pass an object that matches the the shape of the LiveFormFieldProps type when onChange is called`
);
test.todo(`Should trigger the onClick method when the container is clicked`);
});
describe(" Actions Tests", () => {
afterEach(cleanup);
it(`Should toggle the expansion or collapsing of the container when clicked`, () => {});
});