diff --git a/src/utils/helpers/buildMapper.ts b/src/utils/helpers/buildMapper.ts index 9b058601..bdd8da40 100644 --- a/src/utils/helpers/buildMapper.ts +++ b/src/utils/helpers/buildMapper.ts @@ -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) => { + 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`; @@ -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 }); } } }; diff --git a/test/metadata/BuildDropdown.test.tsx b/test/metadata/BuildDropdown.test.tsx index d14d7450..709b192c 100644 --- a/test/metadata/BuildDropdown.test.tsx +++ b/test/metadata/BuildDropdown.test.tsx @@ -33,15 +33,19 @@ describe("", () => { }); 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(); }); });