Skip to content

Commit

Permalink
clean up more arrange/act comments
Browse files Browse the repository at this point in the history
  • Loading branch information
beaesguerra committed Nov 12, 2024
1 parent 5e7b4c0 commit 906af54
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -828,27 +828,25 @@ describe("TextArea", () => {

it("should set aria-invalid to false if the error prop is false", async () => {
// Arrange
// Act
render(
<TextArea value="text" onChange={() => {}} error={false} />,
defaultOptions,
);

// Act

// Assert
const textArea = await screen.findByRole("textbox");
expect(textArea).toHaveAttribute("aria-invalid", "false");
});

it("should set aria-invalid to false if the error prop is not provided", async () => {
// Arrange
// Act
render(
<TextArea value="text" onChange={() => {}} />,
defaultOptions,
);

// Act

// Assert
const textArea = await screen.findByRole("textbox");
expect(textArea).toHaveAttribute("aria-invalid", "false");
Expand All @@ -860,6 +858,7 @@ describe("TextArea", () => {
describe("validate prop", () => {
it("should be in an error state if the initial value is not empty and not valid", async () => {
// Arrange
// Act
render(
<TextArea
value="tooShort"
Expand All @@ -872,7 +871,6 @@ describe("TextArea", () => {
/>,
defaultOptions,
);
// Act

// Assert
const textArea = await screen.findByRole("textbox");
Expand All @@ -881,6 +879,7 @@ describe("TextArea", () => {

it("should not be in an error state if the initial value is empty and not valid", async () => {
// Arrange
// Act
render(
<TextArea
value=""
Expand All @@ -893,7 +892,6 @@ describe("TextArea", () => {
/>,
defaultOptions,
);
// Act

// Assert
const textArea = await screen.findByRole("textbox");
Expand All @@ -902,6 +900,7 @@ describe("TextArea", () => {

it("should not be in an error state if the initial value is valid", async () => {
// Arrange
// Act
render(
<TextArea
value="LongerThan10"
Expand All @@ -914,7 +913,6 @@ describe("TextArea", () => {
/>,
defaultOptions,
);
// Act

// Assert
const textArea = await screen.findByRole("textbox");
Expand Down Expand Up @@ -998,9 +996,10 @@ describe("TextArea", () => {

it("should call the onValidate function only once when it is first rendered (once after mount)", async () => {
// Arrange
// Act
const onValidate = jest.fn();
const errorMessage = "Error message";

// Act
render(
<TextArea
value="text"
Expand All @@ -1019,8 +1018,9 @@ describe("TextArea", () => {

it("should not call the validate function when it is first rendered if it is disabled and value is not empty", async () => {
// Arrange
// Act
const validate = jest.fn();

// Act
render(
<TextArea
value="text"
Expand All @@ -1038,6 +1038,8 @@ describe("TextArea", () => {
it("should not call the validate function when it is first rendered if the value is empty", async () => {
// Arrange
const validate = jest.fn();

// Act
render(
<TextArea
value=""
Expand All @@ -1046,7 +1048,6 @@ describe("TextArea", () => {
/>,
defaultOptions,
);
// Act

// Assert
expect(validate).not.toHaveBeenCalled();
Expand Down Expand Up @@ -1110,6 +1111,8 @@ describe("TextArea", () => {
// Arrange
const handleValidate = jest.fn();
const errorMsg = "error message";

// Act
render(
<TextArea
value="text"
Expand All @@ -1119,7 +1122,6 @@ describe("TextArea", () => {
/>,
defaultOptions,
);
// Act

// Assert
expect(handleValidate).toHaveBeenCalledExactlyOnceWith(
Expand All @@ -1130,6 +1132,8 @@ describe("TextArea", () => {
it("should call the onValidate prop with null if the validate prop returns null", () => {
// Arrange
const handleValidate = jest.fn();

// Act
render(
<TextArea
value="text"
Expand All @@ -1139,7 +1143,6 @@ describe("TextArea", () => {
/>,
defaultOptions,
);
// Act

// Assert
expect(handleValidate).toHaveBeenCalledExactlyOnceWith(null);
Expand All @@ -1148,6 +1151,8 @@ describe("TextArea", () => {
it("should call the onValidate prop with null if the validate prop is a void function", () => {
// Arrange
const handleValidate = jest.fn();

// Act
render(
<TextArea
value="text"
Expand All @@ -1157,7 +1162,6 @@ describe("TextArea", () => {
/>,
defaultOptions,
);
// Act

// Assert
expect(handleValidate).toHaveBeenCalledExactlyOnceWith(null);
Expand All @@ -1167,6 +1171,7 @@ describe("TextArea", () => {
describe("required prop", () => {
it("should initially render with no error if it is required and the value is empty", async () => {
// Arrange
// Act
render(
<TextArea
value=""
Expand All @@ -1176,15 +1181,14 @@ describe("TextArea", () => {
defaultOptions,
);

// Act

// Assert
const textArea = await screen.findByRole("textbox");
expect(textArea).toHaveAttribute("aria-invalid", "false");
});

it("should initially render with no error if it is required and the value is not empty", async () => {
// Arrange
// Act
render(
<TextArea
value="Text"
Expand All @@ -1194,8 +1198,6 @@ describe("TextArea", () => {
defaultOptions,
);

// Act

// Assert
const textArea = await screen.findByRole("textbox");
expect(textArea).toHaveAttribute("aria-invalid", "false");
Expand Down Expand Up @@ -1246,6 +1248,7 @@ describe("TextArea", () => {

it("should not call onValidate on first render if the value is empty and required prop is used", async () => {
// Arrange
// Act
const handleValidate = jest.fn();
render(
<TextArea
Expand All @@ -1257,14 +1260,13 @@ describe("TextArea", () => {
defaultOptions,
);

// Act

// Assert
expect(handleValidate).not.toHaveBeenCalled();
});

it("should call onValidate with no error message on first render if the value is not empty and required prop is used", async () => {
// Arrange
// Act
const handleValidate = jest.fn();
render(
<TextArea
Expand All @@ -1276,8 +1278,6 @@ describe("TextArea", () => {
defaultOptions,
);

// Act

// Assert
expect(handleValidate).toHaveBeenCalledExactlyOnceWith(null);
});
Expand Down
Loading

0 comments on commit 906af54

Please sign in to comment.