Skip to content

Commit

Permalink
Complete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriarte committed Jun 27, 2024
1 parent b7ee032 commit f18780c
Show file tree
Hide file tree
Showing 16 changed files with 1,243 additions and 11 deletions.
24 changes: 14 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"@emotion/styled": "^11.11.5",
"@fontsource/roboto": "^5.0.13",
"@mui/material": "^5.15.19",
"@testing-library/dom": "^10.2.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/react": "^16.0.0",
"@types/node": "^20.13.0",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
Expand Down
1 change: 1 addition & 0 deletions tests/CVLogo.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="@testing-library/jest-dom" />
import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, expect, test } from "vitest";
Expand Down
72 changes: 72 additions & 0 deletions tests/SectionAwards.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/// <reference types="@testing-library/jest-dom" />
import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, expect, test } from "vitest";
import SectionAwards from "../src/SectionAwards";
import { LocaleContext } from "../src/I18NResume";
import type { Award } from "../src/interfaces";
import strings from "../src/strings.json";

const mockLocaleContext = {
locale: "en",
strings,
};

describe("SectionAwards Component", () => {
test("renders nothing when awards array is empty", () => {
const { container } = render(
<LocaleContext.Provider value={mockLocaleContext}>
<SectionAwards awards={[]} />
</LocaleContext.Provider>
);

expect(container.firstChild).toBeNull();
});

test("renders awards when provided", () => {
const awards: Award[] = [
{
key: "award1",
title: "Best Developer",
awarder: "Tech Conference",
date: "2023-05-15",
summary: "Awarded for outstanding contributions to open source",
},
{
key: "award2",
title: "Innovation Prize",
awarder: "Startup Incubator",
summary: "Recognized for creating a groundbreaking app",
},
];

render(
<LocaleContext.Provider value={mockLocaleContext}>
<SectionAwards awards={awards} />
</LocaleContext.Provider>
);

expect(screen.getByText("Awards")).toBeInTheDocument();
expect(screen.getByText("Best Developer")).toBeInTheDocument();
expect(screen.getByText("Innovation Prize")).toBeInTheDocument();
});

test("handles awards without dates", () => {
const awards: Award[] = [
{
key: "award1",
title: "Innovation Prize",
awarder: "Startup Incubator",
summary: "Recognized for creating a groundbreaking app",
},
];

render(
<LocaleContext.Provider value={mockLocaleContext}>
<SectionAwards awards={awards} />
</LocaleContext.Provider>
);

expect(screen.queryByText(/\d{4}-\d{2}-\d{2}/)).not.toBeInTheDocument();
});
});
93 changes: 93 additions & 0 deletions tests/SectionCertificates.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/// <reference types="@testing-library/jest-dom" />
import { render, screen } from "@testing-library/react";
import { describe, expect, test } from "vitest";
import SectionCertificates from "../src/SectionCertificates";
import { LocaleContext } from "../src/I18NResume";
import React from "react";
import strings from "../src/strings.json";

const mockLocaleContext = {
locale: "en",
strings,
};

describe("SectionCertificates Component", () => {
const renderWithLocale = (ui, { localeValue = mockLocaleContext } = {}) => {
return render(
<LocaleContext.Provider value={localeValue}>{ui}</LocaleContext.Provider>
);
};

test("renders nothing when no certificates are provided", () => {
renderWithLocale(<SectionCertificates certificates={undefined} />);
expect(screen.queryByRole("list")).not.toBeInTheDocument();
});

test("renders certificate list when certificates are provided", () => {
const certificates = [
{
key: "1",
name: "Certificate 1",
issuer: "Issuer 1",
date: "2023-06-01",
url: "https://example.com",
keywords: ["cert1"],
},
];
renderWithLocale(<SectionCertificates certificates={certificates} />, {
localeValue: mockLocaleContext,
});

expect(
screen.getByRole("heading", { name: "Certificates Collapse section" })
).toBeInTheDocument();
expect(screen.getByText("Certificate 1")).toBeInTheDocument();
expect(screen.getByText(". Issuer 1")).toBeInTheDocument();
expect(screen.getByRole("link")).toHaveAttribute(
"href",
"https://example.com"
);
});

test("renders certificate without link when url is not provided", () => {
const certificates = [
{
key: "2",
name: "Certificate 2",
issuer: "Issuer 2",
date: "2023-07-01",
url: "",
keywords: ["cert2"],
},
];
renderWithLocale(<SectionCertificates certificates={certificates} />, {
localeValue: mockLocaleContext,
});

expect(
screen.getByRole("heading", { name: "Certificates Collapse section" })
).toBeInTheDocument();
expect(screen.getByText("Certificate 2")).toBeInTheDocument();
expect(screen.getByText(". Issuer 2")).toBeInTheDocument();
expect(screen.queryByRole("link")).not.toBeInTheDocument();
});

test("applies OpacityFilter to certificates", () => {
const certificates = [
{
key: "3",
name: "Certificate 3",
issuer: "Issuer 3",
date: "2023-08-01",
url: "",
keywords: ["cert3"],
},
];
renderWithLocale(<SectionCertificates certificates={certificates} />, {
localeValue: mockLocaleContext,
});

const filterElement = screen.getByText("Certificate 3").closest("div");
expect(filterElement).toHaveClass("transition-opacity");
});
});
97 changes: 97 additions & 0 deletions tests/SectionContact.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/// <reference types="@testing-library/jest-dom" />
import { render, screen } from "@testing-library/react";
import { describe, expect, test } from "vitest";
import SectionContact from "../src/SectionContact";
import { LocaleContext } from "../src/I18NResume";
import React from "react";
import strings from "../src/strings.json";

const mockLocaleContext = {
locale: "en",
strings,
};

describe("SectionContact Component", () => {
const renderWithLocale = (ui, { localeValue = mockLocaleContext } = {}) => {
return render(
<LocaleContext.Provider value={localeValue}>{ui}</LocaleContext.Provider>
);
};

test("renders nothing when no contact information is provided", () => {
renderWithLocale(<SectionContact basics={undefined} />);
expect(screen.queryByRole("list")).not.toBeInTheDocument();
});

test("renders contact section with email", () => {
const basics = {
email: "test@example.com",
};
renderWithLocale(<SectionContact basics={basics} />, {
localeValue: mockLocaleContext,
});

expect(
screen.getByRole("heading", {
name: "Contact information Collapse section",
})
).toBeInTheDocument();
expect(screen.getByText("test@example.com")).toBeInTheDocument();
expect(screen.getByLabelText("Email")).toBeInTheDocument();
});

test("renders contact section with phone", () => {
const basics = {
phone: "123-456-7890",
};
renderWithLocale(<SectionContact basics={basics} />, {
localeValue: mockLocaleContext,
});

expect(
screen.getByRole("heading", {
name: "Contact information Collapse section",
})
).toBeInTheDocument();
expect(screen.getByText("123-456-7890")).toBeInTheDocument();
expect(screen.getByLabelText("Phone")).toBeInTheDocument();
});

test("renders contact section with address", () => {
const basics = {
location: { city: "City", countryCode: "US" },
};
renderWithLocale(<SectionContact basics={basics} />, {
localeValue: mockLocaleContext,
});

expect(
screen.getByRole("heading", {
name: "Contact information Collapse section",
})
).toBeInTheDocument();
expect(screen.getByLabelText("Address")).toBeInTheDocument();
});

test("renders contact section with all details", () => {
const basics = {
email: "test@example.com",
phone: "123-456-7890",
location: { city: "City", countryCode: "US" },
};
renderWithLocale(<SectionContact basics={basics} />, {
localeValue: mockLocaleContext,
});

expect(
screen.getByRole("heading", {
name: "Contact information Collapse section",
})
).toBeInTheDocument();
expect(screen.getByText("test@example.com")).toBeInTheDocument();
expect(screen.getByText("123-456-7890")).toBeInTheDocument();
expect(screen.getByLabelText("Email")).toBeInTheDocument();
expect(screen.getByLabelText("Phone")).toBeInTheDocument();
expect(screen.getByLabelText("Address")).toBeInTheDocument();
});
});
Loading

0 comments on commit f18780c

Please sign in to comment.