import * as React from "react";
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
import { EditorMode } from "../../../../Editor/types";
import reactToCSS from "react-style-object-to-css";
import { styleClean } from "@sc/utils";
import FileUpload from "./FileUpload";
import { styleData } from "../../FormBuilder.stories";
import { IconTypes } from "@sc/plugins/webcomponents/v2/Icon";
const testId = "FormBuilder-FormFields-FileUpload";
const props = {
styles: styleData,
attributeContainerDataSettings: { hide: false },
};
describe(" Rendering Tests", () => {
it(`Should render in the dom`, () => {
render();
expect(screen.queryByTestId(testId)).toBeTruthy();
});
it(`Should render an EDITOR or LIVE version of the component based on the value of the mode prop`, () => {
const testIdLive = "FormBuilder-FormFields-FileUpload-LIVE";
const testIdEditor = "FormBuilder-FormFields-FileUpload-EDITOR";
const { rerender } = render(
);
expect(screen.queryByTestId(testIdLive)).toBeTruthy();
rerender();
expect(screen.queryByTestId(testIdEditor)).toBeTruthy();
});
it(`Should render a regular file upload field when the mode is live`, () => {
const testIdLive = "FormBuilder-FormFields-FileUpload-LIVE";
render();
expect(
screen.queryByTestId(testIdLive).querySelector("input")
).toBeTruthy();
});
it(`Should render the AttributeContainer component when the mode is edit`, () => {
const attrTestId = "FormBuilder-AttributeContainer";
render();
expect(screen.queryByTestId(attrTestId)).toBeTruthy();
});
it(`Should see that the component has been rendered in the dom`, () => {
const labelTestId = "FormBuilder-Attributes-Label";
render();
expect(screen.queryByTestId(labelTestId)).toBeTruthy();
});
it(`Should see that the component has been rendered in the dom`, () => {
const descriptionTestId = "FormBuilder-Attributes-Description";
render();
expect(screen.queryByTestId(descriptionTestId)).toBeTruthy();
});
it(`Should see that the component has been rendered in the dom`, () => {
const columnsTestId = "FormBuilder-Attributes-Columns";
render();
expect(screen.queryByTestId(columnsTestId)).toBeTruthy();
});
it(`Should see that the component has been rendered in the dom`, () => {
const requiredTestId = "FormBuilder-Attributes-Required";
render();
expect(screen.queryByTestId(requiredTestId)).toBeTruthy();
});
it(`Should render a descriptionStyle, containerStyle, and labelStyle when specified`, () => {
const label = "Label Check";
const description = "Description Check";
render(
);
// descriptionStyle
expect(
styleClean(screen.getByText(description).getAttribute("style"))
).toContain(styleClean(reactToCSS(styleData.descriptionStyle)));
// containerStyle
expect(
styleClean(screen.getByTestId(testId).getAttribute("style"))
).toContain(styleClean(reactToCSS(styleData.containerStyle)));
// labelStyle
expect(styleClean(screen.getByText(label).getAttribute("style"))).toContain(
styleClean(reactToCSS(styleData.labelStyle))
);
});
test.skip(`Should only see that the component has been rendered if the "hide" value is false`, () => {});
});
describe(" Events Tests", () => {
test.todo(
`Should trigger the onChange event (via handleChange()) if the AttributeContainer's onChange event is called`
);
});
describe(" Actions Tests", () => {
test.todo(
`handleChange should convert the incoming payload to LiveFormFieldProps`
);
});