Skip to content

Commit

Permalink
Tests added from Eduardo de Valle to NoDataCard.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardodeValle committed Jun 15, 2024
1 parent e02f808 commit 888cfa8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/FormTextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("FormTextInput Component", () => {
expect(screen.getByLabelText("Email Address")).toBeInTheDocument();
});

// Jose Eduardo De Valle Lara A01734957 - Test #2/5
// José Eduardo de Valle Lara A01734957 - Test #2/5
it("toggles password visibility when show button is clicked", () => {
render(<FormTextInput name="password" type="password" label="Password" />);

Expand All @@ -30,23 +30,23 @@ describe("FormTextInput Component", () => {
expect(input).toHaveAttribute("type", "password");
});

// Jose Eduardo De Valle Lara A01734957 - Test #3/5
// José Eduardo de Valle Lara A01734957 - Test #3/5
it("sets autocomplete attribute based on type and name", () => {
render(<FormTextInput name="name" type="text" label="Full Name" />);

const input = screen.getByTestId("name");
expect(input).toHaveAttribute("autocomplete", "on");
});

// Jose Eduardo De Valle Lara A01734957 - Test #4/5
// José Eduardo de Valle Lara A01734957 - Test #4/5
it("sets autocomplete attribute for email", () => {
render(<FormTextInput name="email" type="email" label="Email Address" />);

const input = screen.getByTestId("email");
expect(input).toHaveAttribute("autocomplete", "on");
});

// Jose Eduardo De Valle Lara A01734957 - Test #5/5
// José Eduardo de Valle Lara A01734957 - Test #5/5
it("sets autocomplete attribute off for other fields", () => {
render(<FormTextInput name="username" type="text" label="Username" />);

Expand Down
37 changes: 37 additions & 0 deletions test/NoDataCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import NoDataCard from "@/components/NoDataCard";

describe("NoDataCard Component", () => {
// José Eduardo de Valle Lara A01734957 - Test #6/10
it("renders correctly with provided text", () => {
const testText = "No data available";
render(<NoDataCard text={testText} />);

const textElement = screen.getByText(testText);
expect(textElement).toBeInTheDocument();
expect(textElement).toHaveClass(
"text-center text-sm font-medium text-grayText",
);
});

// José Eduardo de Valle Lara A01734957 - Test #7/10
it("renders image on medium and larger screens", () => {
render(<NoDataCard text="No data available" />);

const imageElement = screen.getByAltText("No Data Image");

Check failure on line 23 in test/NoDataCard.test.tsx

View workflow job for this annotation

GitHub Actions / unit-test

test/NoDataCard.test.tsx > NoDataCard Component > renders image on medium and larger screens

TestingLibraryElementError: Unable to find an element with the alt text: No Data Image Ignored nodes: comments, script, style <body> <div> <div class="flex flex-col items-center justify-center" > <img alt="NoDataSVG" class="hidden md:block" height="70" src="/NoData.svg" width="100" /> <p class="text-center text-sm font-medium text-grayText" > No data available </p> </div> </div> </body> ❯ Object.getElementError node_modules/@testing-library/dom/dist/config.js:37:19 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:76:38 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:52:17 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:95:19 ❯ test/NoDataCard.test.tsx:23:33
expect(imageElement).toBeInTheDocument();
expect(imageElement).toHaveClass("hidden md:block");
});

// José Eduardo de Valle Lara A01734957 - Test #8/10
it("contains the provided text", () => {
const testText = "No data available";
render(<NoDataCard text={testText} />);

const textElement = screen.getByText(testText);
expect(textElement).toBeInTheDocument();
expect(textElement).toHaveTextContent(testText);
});
});

0 comments on commit 888cfa8

Please sign in to comment.