/* * 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 { Link, useHistory } from "react-router-dom"; import tw, { styled } from "twin.macro"; import { useQueryParams, useCloseModal, Modal, Cells, Skeleton, Icons, VirtualizedTable, Stub, CopyButton, Tooltip, removeQueryParamsFromPath, } from "@drill4j/ui-kit"; import { AssociatedTests } from "types/associated-tests"; import { useFilteredData, useNavigation, useTestToCodeRouteParams } from "hooks"; import { concatTestPath, concatTestName } from "utils/transform-tests"; export const AssociatedTestModal = () => { const { push } = useHistory(); const { scopeId, buildVersion } = useTestToCodeRouteParams(); const params = useQueryParams<{testId?: string; treeLevel?: number; testsCount?: string }>(); const associatedTests = useFilteredData(`${scopeId ? `/build/scopes/${scopeId}` : "/build"}/tests/associatedWith/${ params?.testId}`) || {}; const { getPagePath } = useNavigation(); const isSkeleton = Object.keys(associatedTests).length === 0; const { tests = [], packageName = "", className: testClassName = "", methodName = "", } = associatedTests; const closeModal = useCloseModal(["testId", "treeLevel"]); const clearVirtualTableState = () => { push(removeQueryParamsFromPath(["virtualTableState"])); }; return ( { clearVirtualTableState(); closeModal(); }}>
Associated Tests {Number(params.testsCount)}
Package Class Method {isSkeleton ? "" : packageName || "-"} {isSkeleton ? "" : testClassName || "-"} {isSkeleton ? "" : methodName || "-"}
(
tests
{`Displaying ${currentCount} of ${Number(params.testsCount)} rows`}
)} gridTemplateColumns="1fr 1fr 120px" data={tests.map((test) => ({ ...test, details: { ...test.details, testName: concatTestName(test?.details?.testName, test?.details?.params?.methodParams), path: concatTestPath(test?.details?.path, test?.details?.params?.classParams), }, }))} listItemSize={40} initialRowsCount={Number(params.testsCount)} stub={( } title="No results found" message="Try adjusting your search or filter to find what you are looking for." /> )} columns={ [ { Header: "Name", accessor: "details.testName", textAlign: "left", filterable: true, isCustomCell: true, width: "100%", Cell: ({ value = "", state, row }: any) => (value ? ( } link={( { const queryParams = { activeTab: "tests", tableState: JSON.stringify({ filters: [ { id: "overview.details.name", value: row.original.details.testName, }, { id: "overview.details.path", value: row.original.details.path, }], }), }; return scopeId ? getPagePath({ name: "scope", params: { scopeId, buildVersion }, queryParams }) : getPagePath({ name: "overview", params: { buildVersion }, queryParams }); }} tw="max-w-280px text-monochrome-black text-14 text-ellipsis link" title={value} target="_blank" > Navigate to Application tests
)} > )} >
filter.value)} data-test="associated-tests:test:name" />
) : ), }, { Header: "Path", accessor: "details.path", textAlign: "left", filterable: true, isCustomCell: true, width: "100%", Cell: ({ value = "-", state }: any) => (value ? ( filter.value)} data-test="associated-tests:test:path" /> ) : ), }, { Header: "Type", Cell: ({ value = "" }) => (value ? {value} : ), accessor: "type", textAlign: "left", width: "100%", }, ] } />
); }; const MethodInfoLabel = styled.div(tw`min-w-32px text-left text-14 leading-32 font-bold text-monochrome-black`); const MethodInfoValue = styled.div(({ skeleton }: { skeleton?: boolean }) => [ tw`text-monochrome-default text-14 leading-20 break-all text-ellipsis`, skeleton && tw`h-4 animate-pulse w-full bg-monochrome-medium-tint rounded`, ]);