Skip to content

Commit

Permalink
updates factory
Browse files Browse the repository at this point in the history
  • Loading branch information
rosschapman committed Dec 24, 2024
1 parent 1089492 commit 813597b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/components/ui/Cards/EventCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { EventCard } from "./EventCard";
import { HOME_PAGE_EVENTS_DATA_FORMATTED } from "../../../../test/fixtures/EventsData";
import { createFormattedHomePageEventsData } from "../../../../test/fixtures/EventsData";

describe("<EventCard />", () => {
const eventData = HOME_PAGE_EVENTS_DATA_FORMATTED[0];
const eventData = createFormattedHomePageEventsData()[0];

it("displays title, link, date, and call to action", () => {
render(<EventCard event={eventData} />);
Expand Down
4 changes: 2 additions & 2 deletions app/components/ui/Cards/EventCardSection.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { HOME_PAGE_EVENTS_DATA_FORMATTED } from "../../../../test/fixtures/EventsData";
import { createFormattedHomePageEventsData } from "../../../../test/fixtures/EventsData";
import { EventCardSection } from "components/ui/Cards/EventCardSection";

describe("<EventCardSection />", () => {
const eventData = HOME_PAGE_EVENTS_DATA_FORMATTED;
const eventData = createFormattedHomePageEventsData();

it("displays the correct number of event cards", () => {
render(<EventCardSection events={eventData} />);
Expand Down
17 changes: 5 additions & 12 deletions app/pages/EventDetailPage/EventDetailPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { EventDetailPage } from "pages/EventDetailPage/EventDetailPage";
import { EVENTS_DATA } from "../../../test/fixtures/EventsData";
import {
createFormattedEventData,
EVENTS_DATA,

Check warning on line 6 in app/pages/EventDetailPage/EventDetailPage.test.tsx

View workflow job for this annotation

GitHub Actions / build_and_test_app

'EVENTS_DATA' is defined but never used
} from "../../../test/fixtures/EventsData";
import { useEventData } from "hooks/StrapiAPI";
import { BrowserRouter } from "react-router-dom";
import { HelmetProvider } from "react-helmet-async";

let MOCK_EVENT: {
Expand All @@ -17,10 +19,6 @@ let MOCK_EVENT: {
};

jest.mock("hooks/StrapiAPI", () => ({
// TODO: This shouldn't have to be mocked here but I'm not quite an expert
// enough yet in jest mocking to figure out how to import the fixtures without
// doing this.
formatHomePageEventsData: () => null,
useEventData: () => MOCK_EVENT,
}));

Expand All @@ -32,12 +30,7 @@ beforeEach(() => {

it("displays every page section and table row", async () => {
MOCK_EVENT = {
data: {
...EVENTS_DATA[0].data.attributes,
id: 10,
categories: ["fakeCategory"],
eligibilities: ["fakeEligibility"],
} as unknown as ReturnType<typeof useEventData>["data"],
data: createFormattedEventData(),
error: null,
isLoading: false,
};
Expand Down
36 changes: 23 additions & 13 deletions test/fixtures/EventsData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Sample data from a real api request to our Strapi production server. This
// data may have to change as the api changes so developers should feel at
// liberty to update these fixtures as needed.

import { RootNode } from "@strapi/blocks-react-renderer/dist/BlocksRenderer";
import { formatHomePageEventsData } from "hooks/StrapiAPI";
import { formatHomePageEventsData, useEventData } from "hooks/StrapiAPI";

// liberty to update these fixtures as needed.
export const EVENTS_DATA = [
{
data: {
Expand Down Expand Up @@ -1386,15 +1386,25 @@ export const EVENTS_DATA = [
},
];

export const HOME_PAGE_EVENTS_DATA_FORMATTED = formatHomePageEventsData({
data: [
{
id: EVENTS_DATA[0].data.id,
attributes: EVENTS_DATA[0].data.attributes,
},
{
id: EVENTS_DATA[1].data.id,
attributes: EVENTS_DATA[1].data.attributes,
},
],
export const createFormattedHomePageEventsData = () =>
formatHomePageEventsData({
data: [
{
id: EVENTS_DATA[0].data.id,
attributes: EVENTS_DATA[0].data.attributes,
},
{
id: EVENTS_DATA[1].data.id,
attributes: EVENTS_DATA[1].data.attributes,
},
],
});

export const createFormattedEventData = (): ReturnType<
typeof useEventData
>["data"] => ({
...EVENTS_DATA[0].data.attributes,
id: 10,
categories: [{ id: 11111, label: "Fake Label" }],
eligibilities: [{ id: 11111, label: "Fake Label" }],
});

0 comments on commit 813597b

Please sign in to comment.