/* Copyright (c) Microsoft Corporation. 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 type { TestCaseSummary, TestFileSummary } from './types'; import * as React from 'react'; import { hashStringToInt, msToString } from './utils'; import { Chip } from './chip'; import { filterWithToken } from './filter'; import { generateTraceUrl, Link, navigate, ProjectLink, SearchParamsContext, testResultHref } from './links'; import { statusIcon } from './statusIcon'; import './testFileView.css'; import { video, image, trace } from './icons'; import { clsx } from '@web/uiUtils'; export const TestFileView: React.FC boolean; setFileExpanded: (fileId: string, expanded: boolean) => void; }>> = ({ file, projectNames, isFileExpanded, setFileExpanded }) => { const searchParams = React.useContext(SearchParamsContext); const filterParam = searchParams.has('q') ? '&q=' + searchParams.get('q') : ''; return setFileExpanded(file.fileId, expanded))} header={ {file.fileName} }> {file.tests.map(test =>
{statusIcon(test.outcome)} {[...test.path, test.title].join(' › ')} {projectNames.length > 1 && !!test.projectName && }
{msToString(test.duration)}
{test.location.file}:{test.location.line} {imageDiffBadge(test)} {videoBadge(test)} {traceBadge(test)}
)}
; }; function imageDiffBadge(test: TestCaseSummary): JSX.Element | undefined { for (const result of test.results) { for (const attachment of result.attachments) { if (attachment.contentType.startsWith('image/') && !!attachment.name.match(/-(expected|actual|diff)/)) return {image()}; } } } function videoBadge(test: TestCaseSummary): JSX.Element | undefined { const resultWithVideo = test.results.find(result => result.attachments.some(attachment => attachment.name === 'video')); return resultWithVideo ? {video()} : undefined; } function traceBadge(test: TestCaseSummary): JSX.Element | undefined { const firstTraces = test.results.map(result => result.attachments.filter(attachment => attachment.name === 'trace')).filter(traces => traces.length > 0)[0]; return firstTraces ? {trace()} : undefined; } const LabelsClickView: React.FC> = ({ labels }) => { const searchParams = React.useContext(SearchParamsContext); const onClickHandle = (e: React.MouseEvent, label: string) => { e.preventDefault(); const q = searchParams.get('q')?.toString() || ''; const tokens = q.split(' '); navigate(filterWithToken(tokens, label, e.metaKey || e.ctrlKey)); }; return labels.length > 0 ? ( <> {labels.map(label => ( onClickHandle(e, label)}> {label.slice(1)} ))} ) : null; };