Skip to content

Commit

Permalink
more refaction
Browse files Browse the repository at this point in the history
  • Loading branch information
gabalafou committed Mar 14, 2024
1 parent 30d7ffa commit c03078f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
23 changes: 14 additions & 9 deletions src/utils/helpers/buildMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ const STATUS_OPTIONS: { [key: string]: string } = {

const TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;

const isCompleted = (status: string, duration: number) => {
const isCompleted = ({
status,
ended_on,
scheduled_on
}: Pick<Build, "status" | "ended_on" | "scheduled_on">) => {
let duration = 0;
if (ended_on && scheduled_on) {
const startTime = new Date(scheduled_on);
const endTime = new Date(ended_on);
duration = (endTime.valueOf() - startTime.valueOf()) / 60000;
duration = Math.round(duration);
}

if (status === "COMPLETED") {
if (duration > 0) {
return `Completed in ${duration} min`;
Expand Down Expand Up @@ -57,14 +69,7 @@ export const buildStatus = ({
case "QUEUED":
return "Building";
default: {
let duration = 0;
if (ended_on && scheduled_on) {
const startTime = new Date(scheduled_on);
const endTime = new Date(ended_on);
duration = (endTime.valueOf() - startTime.valueOf()) / 60000;
duration = Math.round(duration);
}
return isCompleted(status, duration);
return isCompleted({ status, ended_on, scheduled_on });
}
}
};
10 changes: 7 additions & 3 deletions test/metadata/BuildDropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ describe("<BuildDropdown />", () => {
});

it("should display builds in the dropdown", async () => {
const buildOptionName = buildDatetimeStatus(mockBuilds[1], currentBuildId);
// This is what the dropdown should display for the build
const dropdownOptionName = buildDatetimeStatus(
mockBuilds[1],
currentBuildId
);
const [dropdownButton] = screen.getAllByRole("button");
userEvent.click(dropdownButton);
const dropdownItem = await screen.findByRole("option", {
name: buildOptionName
name: dropdownOptionName
});
userEvent.click(dropdownItem);

const buildName = await screen.findByText(buildOptionName);
const buildName = await screen.findByText(dropdownOptionName);
expect(buildName).toBeInTheDocument();
});
});

0 comments on commit c03078f

Please sign in to comment.