Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
DEVPROD-4166 Add breaking commits option in previous commits dropdown (
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana authored Feb 29, 2024
1 parent d52e011 commit d43ca82
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/analytics/task/useTaskAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "gql/generated/types";
import { TASK } from "gql/queries";
import { useQueryParam } from "hooks/useQueryParam";
import { CommitType } from "pages/task/actionButtons/previousCommits/types";
import { CommitType } from "pages/task/actionButtons/RelevantCommits/types";
import { RequiredQueryParams, LogTypes } from "types/task";

type LogViewer = "raw" | "html" | "parsley";
Expand Down Expand Up @@ -70,7 +70,7 @@ type Action =
| { name: "Click Last Failing Stepback Task Link" }
| { name: "Click Previous Stepback Task Link" }
| { name: "Click Next Stepback Task Link" }
| { name: "Submit Previous Commit Selector"; type: CommitType };
| { name: "Submit Relevant Commit Selector"; type: CommitType };

export const useTaskAnalytics = () => {
const { id } = useParams<{ id: string }>();
Expand Down
2 changes: 2 additions & 0 deletions src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5409,6 +5409,7 @@ export type BaseVersionAndTaskQuery = {
execution: number;
id: string;
projectIdentifier?: string | null;
status: string;
baseTask?: {
__typename?: "Task";
execution: number;
Expand Down Expand Up @@ -6173,6 +6174,7 @@ export type LastMainlineCommitQuery = {
__typename?: "Task";
execution: number;
id: string;
order: number;
status: string;
} | null> | null;
} | null> | null;
Expand Down
1 change: 1 addition & 0 deletions src/gql/queries/base-version-and-task.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ query BaseVersionAndTask($taskId: String!) {
execution
id
projectIdentifier
status
versionMetadata {
baseVersion {
id
Expand Down
1 change: 1 addition & 0 deletions src/gql/queries/last-mainline-commit.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ query LastMainlineCommit(
tasks {
execution
id
order
status
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/task/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
import { useLGButtonRouterLink } from "hooks/useLGButtonRouterLink";
import { useQueryParam } from "hooks/useQueryParam";
import { TaskStatus } from "types/task";
import { PreviousCommits } from "./actionButtons/previousCommits";
import { RelevantCommits } from "./actionButtons/RelevantCommits";
import { TaskNotificationModal } from "./actionButtons/TaskNotificationModal";

interface Props {
Expand Down Expand Up @@ -254,7 +254,7 @@ export const ActionButtons: React.FC<Props> = ({
<PageButtonRow>
{!isExecutionTask && (
<>
<PreviousCommits taskId={taskId} />
<RelevantCommits taskId={taskId} />
<Button
size="small"
data-cy="task-history"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import {
import { BASE_VERSION_AND_TASK, LAST_MAINLINE_COMMIT } from "gql/queries";
import { renderWithRouterMatch, screen, userEvent, waitFor } from "test_utils";
import { ApolloMock } from "types/gql";
import { PreviousCommits } from ".";
import { RelevantCommits } from ".";

describe("previous commits", () => {
describe("relevant commits", () => {
// Patch and mainline commit behavior only have a significant difference when it comes to determining
// the base or previous task. Patch gets the base task directly from BASE_VERSION_AND_TASK, while
// mainline commits needs to run another query LAST_MAINLINE_COMMIT to get previous task.
describe("patch specific", () => {
it("the button is disabled when there is no base task", async () => {
const { Component } = RenderFakeToastContext(
<MockedProvider mocks={[getPatchTaskWithNoBaseTask]}>
<PreviousCommits taskId="t1" />
<RelevantCommits taskId="t1" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);
await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});
Expand All @@ -37,14 +37,14 @@ describe("previous commits", () => {
<MockedProvider
mocks={[getMainlineTaskWithBaseVersion, getNullParentTask]}
>
<PreviousCommits taskId="t4" />
<RelevantCommits taskId="t4" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});
Expand All @@ -54,14 +54,14 @@ describe("previous commits", () => {
<MockedProvider
mocks={[getMainlineTaskWithBaseVersion, getParentTaskWithError]}
>
<PreviousCommits taskId="t4" />
<RelevantCommits taskId="t4" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});
Expand All @@ -70,19 +70,19 @@ describe("previous commits", () => {
it("the button is disabled when no base version exists", async () => {
const { Component } = RenderFakeToastContext(
<MockedProvider mocks={[getPatchTaskWithNoBaseVersion]}>
<PreviousCommits taskId="t3" />
<RelevantCommits taskId="t3" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});

it("when base task is passing, all dropdown items generate the same link", async () => {
it("when base task is passing, last passing, base commit, and last executed dropdown items generate the same link and breaking commit is disabled", async () => {
const user = userEvent.setup();
const { Component } = RenderFakeToastContext(
<MockedProvider
Expand All @@ -92,16 +92,16 @@ describe("previous commits", () => {
getLastExecutedVersion,
]}
>
<PreviousCommits taskId="t1" />
<RelevantCommits taskId="t1" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await screen.findByRole("button", { name: "Previous commits" });
await screen.findByRole("button", { name: "Relevant commits" });
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "false");
await user.click(screen.getByRole("button", { name: "Previous commits" }));
await user.click(screen.getByRole("button", { name: "Relevant commits" }));
await waitFor(() => {
expect(screen.getByRole("menu")).toBeVisible();
});
Expand All @@ -115,24 +115,31 @@ describe("previous commits", () => {
expect(
screen.getByRole("menuitem", { name: "Go to last executed version" }),
).toHaveAttribute("href", baseTaskHref);
expect(
screen.getByRole("menuitem", { name: "Go to breaking commit" }),
).toHaveAttribute("aria-disabled", "true");
});

it("when base task is failing, 'Go to base commit' and 'Go to last executed' dropdown items generate the same link and 'Go to last passing version' will be different.", async () => {
it("when base task is failing, 'Go to base commit' and 'Go to last executed' dropdown items generate the same link and 'Go to last passing version' will be different and 'Go to breaking commit' will be populated", async () => {
const user = userEvent.setup();
const { Component } = RenderFakeToastContext(
<MockedProvider
mocks={[getPatchTaskWithFailingBaseTask, getLastPassingVersion]}
mocks={[
getPatchTaskWithFailingBaseTask,
getLastPassingVersion,
getBreakingCommit,
]}
>
<PreviousCommits taskId="t1" />
<RelevantCommits taskId="t1" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await screen.findByRole("button", { name: "Previous commits" });
await screen.findByRole("button", { name: "Relevant commits" });
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "false");
await user.click(screen.getByRole("button", { name: "Previous commits" }));
await user.click(screen.getByRole("button", { name: "Relevant commits" }));
await waitFor(() => {
expect(screen.getByRole("menu")).toBeVisible();
});
Expand All @@ -146,28 +153,32 @@ describe("previous commits", () => {
expect(
screen.getByRole("menuitem", { name: "Go to last executed version" }),
).toHaveAttribute("href", baseTaskHref);
expect(
screen.getByRole("menuitem", { name: "Go to breaking commit" }),
).toHaveAttribute("href", "/task/breaking_commit");
});

it("when base task is not in a finished state, the last executed & passing task is not the same as the base commit", async () => {
it("when base task is not in a finished state, the last executed, and passing task are not the same as the base commit and breaking commit is empty", async () => {
const user = userEvent.setup();
const { Component } = RenderFakeToastContext(
<MockedProvider
mocks={[
getPatchTaskWithRunningBaseTask,
getLastPassingVersion,
getLastExecutedVersion,
getBreakingCommit,
]}
>
<PreviousCommits taskId="t3" />
<RelevantCommits taskId="t3" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await screen.findByRole("button", { name: "Previous commits" });
await screen.findByRole("button", { name: "Relevant commits" });
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "false");
await user.click(screen.getByRole("button", { name: "Previous commits" }));
await user.click(screen.getByRole("button", { name: "Relevant commits" }));
await waitFor(() => {
expect(screen.getByRole("menu")).toBeVisible();
});
Expand All @@ -181,6 +192,9 @@ describe("previous commits", () => {
expect(
screen.getByRole("menuitem", { name: "Go to last executed version" }),
).toHaveAttribute("href", "/task/last_executed_task");
expect(
screen.getByRole("menuitem", { name: "Go to breaking commit" }),
).toHaveAttribute("aria-disabled", "true");
});
});

Expand All @@ -206,6 +220,7 @@ const getPatchTaskWithSuccessfulBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -246,6 +261,7 @@ const getPatchTaskWithRunningBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "started",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -286,6 +302,7 @@ const getPatchTaskWithFailingBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "failed",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -326,6 +343,7 @@ const getPatchTaskWithNoBaseVersion: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: null,
id: "versionMetadataId",
Expand All @@ -339,6 +357,54 @@ const getPatchTaskWithNoBaseVersion: ApolloMock<
},
};

const getBreakingCommit: ApolloMock<
LastMainlineCommitQuery,
LastMainlineCommitQueryVariables
> = {
request: {
query: LAST_MAINLINE_COMMIT,
variables: {
projectIdentifier: "evergreen",
skipOrderNumber: 3676,
buildVariantOptions: {
tasks: ["^lint-agent$"],
variants: ["^lint$"],
statuses: ["failed"],
},
},
},
result: {
data: {
mainlineCommits: {
versions: [
{
version: {
id: "evergreen_44110b57c6977bf3557009193628c9389772163f2",
buildVariants: [
{
tasks: [
{
id: "breaking_commit",
execution: 0,
order: 3676,
status: "failed",
__typename: "Task",
},
],
__typename: "GroupedBuildVariant",
},
],
__typename: "Version",
},
__typename: "MainlineCommitVersion",
},
],
__typename: "MainlineCommits",
},
},
},
};

const getLastPassingVersion: ApolloMock<
LastMainlineCommitQuery,
LastMainlineCommitQueryVariables
Expand Down Expand Up @@ -368,6 +434,7 @@ const getLastPassingVersion: ApolloMock<
{
id: "last_passing_task",
execution: 0,
order: 3674,
status: "success",
__typename: "Task",
},
Expand Down Expand Up @@ -425,6 +492,7 @@ const getLastExecutedVersion: ApolloMock<
{
id: "last_executed_task",
execution: 0,
order: 3676,
status: "failed",
__typename: "Task",
},
Expand Down Expand Up @@ -462,6 +530,7 @@ const getPatchTaskWithNoBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -498,6 +567,7 @@ const getMainlineTaskWithBaseVersion: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down
Loading

0 comments on commit d43ca82

Please sign in to comment.