Skip to content

Commit

Permalink
Update some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijsgroen committed Jun 21, 2024
1 parent af84323 commit f72e56a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/modules/choose-team/ChooseTeamPage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ describe("<ChooseTeamPage />", () => {
});

it("navigates to the create team page", () => {
const { unmount } = renderComponent();
renderComponent();

const createTeamButton = screen.getByRole("button", {
name: "Create team",
});
fireEvent.click(createTeamButton);

expect(mockHistoryPush).toHaveBeenCalledWith("/create-team");
unmount();
});
});
100 changes: 47 additions & 53 deletions src/ui/Progress/GoalProgressIndicator.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,58 @@
import { render } from "@testing-library/react";
import { screen } from "@testing-library/react";
import GoalProgressIndicator from "./GoalProgressIndicator";
import { createGoal } from "./factory";
import { setTestSubject } from "../../support/testing/testSubject";

test("renders the goal progress indicator", () => {
const goals = {
activeGoals: [
createGoal("Third goal", 1500, null),
createGoal("Second goal", 1000, null),
createGoal("First goal", 500, null),
],
};
const { getAllByRole } = render(
<GoalProgressIndicator
activeKudosMeter={{ amount: 200 }}
goals={goals.activeGoals}
/>,
describe("GoalProgressIndicator", () => {
const { renderComponent, updateProps } = setTestSubject(
GoalProgressIndicator,
{
props: {
goals: [
createGoal("Third goal", 1500, null),
createGoal("Second goal", 1000, null),
createGoal("First goal", 500, null),
],
activeKudosMeter: { amount: 200 },
},
},
);

const progressBars = getAllByRole("progressbar");
expect(progressBars).toHaveLength(3);
});
it("renders the goal progress indicator", () => {
renderComponent();

test("renders the goal progress indicator with no goals achieved, but with progress", () => {
const goals = {
activeGoals: [
createGoal("Third goal", 1500, null),
createGoal("Second goal", 1000, null),
createGoal("First goal", 500, null),
],
};
const progressBars = screen.getAllByRole("progressbar");
expect(progressBars).toHaveLength(3);
});

const { getAllByRole } = render(
<GoalProgressIndicator
activeKudosMeter={{ amount: 200 }}
goals={goals.activeGoals}
/>,
);
it("renders the goal progress indicator with no goals achieved, but with progress", () => {
renderComponent();

const progressBars = getAllByRole("progressbar");
expect(progressBars).toHaveLength(3);
expect(progressBars[progressBars.length - 1]).toHaveAttribute("value", "40");
});
const progressBars = screen.getAllByRole("progressbar");
expect(progressBars).toHaveLength(3);
expect(progressBars[progressBars.length - 1]).toHaveAttribute(
"value",
"40",
);
});

test("renders the goal progress indicator with the first goal achieved", () => {
const goals = {
activeGoals: [
createGoal("Third goal", 1500, null),
createGoal("Second goal", 1000, null),
createGoal("First goal", 500, "2023-05-13"),
],
};
const { getAllByRole } = render(
<GoalProgressIndicator
activeKudosMeter={{ amount: 600 }}
goals={goals.activeGoals}
/>,
);
it("renders the goal progress indicator with the first goal achieved", () => {
updateProps({
goals: [
createGoal("Third goal", 1500, null),
createGoal("Second goal", 1000, null),
createGoal("First goal", 500, "2023-05-13"),
],
activeKudosMeter: { amount: 600 },
});
renderComponent();

const progressBars = getAllByRole("progressbar");
expect(progressBars).toHaveLength(3);
expect(progressBars[progressBars.length - 1]).toHaveAttribute("value", "100");
expect(progressBars[1]).toHaveAttribute("value", "20");
const progressBars = screen.getAllByRole("progressbar");
expect(progressBars).toHaveLength(3);
expect(progressBars[progressBars.length - 1]).toHaveAttribute(
"value",
"100",
);
expect(progressBars[1]).toHaveAttribute("value", "20");
});
});

0 comments on commit f72e56a

Please sign in to comment.