/* * Copyright 2020 EPAM Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React from "react"; import { Button } from "@drill4j/ui-kit"; import { convertToPercentage, getDuration, percentFormatter } from "@drill4j/common-utils"; import { useHistory } from "react-router-dom"; import "twin.macro"; import { FilterInfoAlert, PageHeader } from "components"; import { TestsToRunSummary } from "types/tests-to-run-summary"; import { getModalPath } from "common"; import { useAdminConnection } from "hooks"; import { AnalyticsInfo } from "types"; import { KEY_METRICS_EVENT_NAMES, sendKeyMetricsEvent } from "common/analytic"; import { SavedTimeSection } from "./saved-time-section"; interface AgentInfo { agentType: string; buildVersion: string; previousBuildVersion: string; activeBuildVersion: string; } interface Props { agentInfo: AgentInfo; previousBuildAutoTestsCount: number; previousBuildTestsDuration: number; summaryTestsToRun: TestsToRunSummary; } export const TestsToRunHeader = ({ agentInfo, previousBuildAutoTestsCount, previousBuildTestsDuration, summaryTestsToRun, }: Props) => { const { push } = useHistory(); const { stats: { duration: currentDuration = 0, parentDuration = 0, total: totalTestsToRun = 0, } = {}, statsByType: { AUTO: { total: totalAutoTestsToRun = 0, completed: completedAutoTestsToRun = 0 } = {}, } = {}, } = summaryTestsToRun; const { buildVersion, activeBuildVersion, } = agentInfo; const totalDuration = getDuration(previousBuildTestsDuration); const estimatedTimeSaved = getDuration(previousBuildTestsDuration - parentDuration); const totalTimeSaved = getDuration( previousBuildTestsDuration - currentDuration > 0 ? previousBuildTestsDuration - currentDuration : 0, ); const { isAnalyticsDisabled } = useAdminConnection("/api/analytics/info") || {}; return (
Recommended Tests
{activeBuildVersion === buildVersion && ( )} {totalDuration.hours}:{totalDuration.minutes}:{totalDuration.seconds} {totalAutoTestsToRun ? `${estimatedTimeSaved.hours}:${estimatedTimeSaved.minutes}:${estimatedTimeSaved.seconds}` : "––:––:––"} {totalAutoTestsToRun && totalAutoTestsToRun === completedAutoTestsToRun ? `${totalTimeSaved.hours}:${totalTimeSaved.minutes}:${totalTimeSaved.seconds}` : "––:––:––"}
); }; function getTotalDurationTooltipMessage(previousBuildAutoTestsCount: number) { return previousBuildAutoTestsCount ? ( Auto Tests total duration in the parent build ) : ( No data about Auto Tests duration in the parent build ); } function getEstimatedTimeSavedTooltipMessage(autoTestsCount: number) { return autoTestsCount ? ( Potentially saved time after running only
the suggested Auto Tests
) : ( No Auto Tests suggested to run in current build ); } function getTotalSavedTimeTooltipMessage(autoTestsToRunCount: number) { return autoTestsToRunCount ? ( Data about saved time will be displayed
when all Auto Tests will have the state done{" "}
) : null; }