2021-12-12 14:56:12 -08:00
|
|
|
|
/*
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-04-23 05:16:58 -07:00
|
|
|
|
import type { TestAnnotation } from '@playwright/test';
|
|
|
|
|
import type { TestCase, TestCaseSummary } from './types';
|
2021-12-12 14:56:12 -08:00
|
|
|
|
import * as React from 'react';
|
|
|
|
|
import { TabbedPane } from './tabbedPane';
|
2021-12-14 19:25:07 -08:00
|
|
|
|
import { AutoChip } from './chip';
|
2021-12-12 14:56:12 -08:00
|
|
|
|
import './common.css';
|
2024-12-16 15:25:32 +01:00
|
|
|
|
import { Link, ProjectLink, SearchParamsContext, testResultHref } from './links';
|
2021-12-12 14:56:12 -08:00
|
|
|
|
import { statusIcon } from './statusIcon';
|
|
|
|
|
import './testCaseView.css';
|
|
|
|
|
import { TestResultView } from './testResultView';
|
2024-08-01 03:43:29 -07:00
|
|
|
|
import { linkifyText } from '@web/renderUtils';
|
2024-07-15 12:20:22 -07:00
|
|
|
|
import { hashStringToInt, msToString } from './utils';
|
2024-07-31 12:12:06 +02:00
|
|
|
|
import { clsx } from '@web/uiUtils';
|
2024-09-17 00:57:11 +10:00
|
|
|
|
import { CopyToClipboardContainer } from './copyToClipboard';
|
2025-05-05 11:40:09 -07:00
|
|
|
|
import { HeaderView } from './headerView';
|
2025-05-30 15:43:55 +02:00
|
|
|
|
import type { MetadataWithCommitInfo } from '@playwright/isomorphic/types';
|
2021-12-12 14:56:12 -08:00
|
|
|
|
|
|
|
|
|
export const TestCaseView: React.FC<{
|
2021-12-14 19:25:07 -08:00
|
|
|
|
projectNames: string[],
|
2025-04-22 08:29:47 -07:00
|
|
|
|
test: TestCase,
|
2025-05-30 15:43:55 +02:00
|
|
|
|
testRunMetadata: MetadataWithCommitInfo | undefined,
|
2024-10-29 18:29:07 -07:00
|
|
|
|
next: TestCaseSummary | undefined,
|
|
|
|
|
prev: TestCaseSummary | undefined,
|
2022-07-11 19:47:15 -07:00
|
|
|
|
run: number,
|
2025-05-30 15:43:55 +02:00
|
|
|
|
}> = ({ projectNames, test, testRunMetadata, run, next, prev }) => {
|
2022-07-11 19:47:15 -07:00
|
|
|
|
const [selectedResultIndex, setSelectedResultIndex] = React.useState(run);
|
2024-10-29 18:29:07 -07:00
|
|
|
|
const searchParams = React.useContext(SearchParamsContext);
|
2023-03-10 15:26:02 -08:00
|
|
|
|
|
2025-04-22 08:29:47 -07:00
|
|
|
|
const filterParam = searchParams.has('q') ? '&q=' + searchParams.get('q') : '';
|
|
|
|
|
const labels = React.useMemo(() => test.tags, [test]);
|
|
|
|
|
const visibleTestAnnotations = test.annotations.filter(a => !a.type.startsWith('_')) ?? [];
|
2024-07-03 03:46:24 +04:00
|
|
|
|
|
2025-04-22 08:29:47 -07:00
|
|
|
|
return <>
|
2025-05-05 11:40:09 -07:00
|
|
|
|
<HeaderView
|
|
|
|
|
title={test.title}
|
|
|
|
|
leftSuperHeader={<div className='test-case-path'>{test.path.join(' › ')}</div>}
|
|
|
|
|
rightSuperHeader={<>
|
|
|
|
|
<div className={clsx(!prev && 'hidden')}><Link href={testResultHref({ test: prev }) + filterParam}>« previous</Link></div>
|
|
|
|
|
<div style={{ width: 10 }}></div>
|
|
|
|
|
<div className={clsx(!next && 'hidden')}><Link href={testResultHref({ test: next }) + filterParam}>next »</Link></div>
|
|
|
|
|
</>}
|
|
|
|
|
/>
|
2025-04-22 08:29:47 -07:00
|
|
|
|
<div className='hbox'>
|
2024-09-17 15:54:22 +02:00
|
|
|
|
<div className='test-case-location'>
|
2025-04-22 08:29:47 -07:00
|
|
|
|
<CopyToClipboardContainer value={`${test.location.file}:${test.location.line}`}>
|
2024-09-17 15:54:22 +02:00
|
|
|
|
{test.location.file}:{test.location.line}
|
|
|
|
|
</CopyToClipboardContainer>
|
|
|
|
|
</div>
|
2023-05-16 12:47:37 -07:00
|
|
|
|
<div style={{ flex: 'auto' }}></div>
|
|
|
|
|
<div className='test-case-duration'>{msToString(test.duration)}</div>
|
2025-04-22 08:29:47 -07:00
|
|
|
|
</div>
|
|
|
|
|
{(!!test.projectName || labels) && <div className='test-case-project-labels-row'>
|
|
|
|
|
{!!test.projectName && <ProjectLink projectNames={projectNames} projectName={test.projectName}></ProjectLink>}
|
2023-03-23 00:35:58 +03:00
|
|
|
|
{labels && <LabelsLinkView labels={labels} />}
|
|
|
|
|
</div>}
|
2025-04-22 08:29:47 -07:00
|
|
|
|
{test.results.length === 0 && visibleTestAnnotations.length !== 0 && <AutoChip header='Annotations' dataTestId='test-case-annotations'>
|
2025-04-15 09:07:42 +02:00
|
|
|
|
{visibleTestAnnotations.map((annotation, index) => <TestCaseAnnotationView key={index} annotation={annotation} />)}
|
2021-12-14 19:25:07 -08:00
|
|
|
|
</AutoChip>}
|
2025-04-22 08:29:47 -07:00
|
|
|
|
<TabbedPane tabs={
|
2021-12-12 14:56:12 -08:00
|
|
|
|
test.results.map((result, index) => ({
|
|
|
|
|
id: String(index),
|
2025-02-06 13:30:25 -08:00
|
|
|
|
title: <div style={{ display: 'flex', alignItems: 'center' }}>
|
|
|
|
|
{statusIcon(result.status)} {retryLabel(index)}
|
|
|
|
|
{(test.results.length > 1) && <span className='test-case-run-duration'>{msToString(result.duration)}</span>}
|
|
|
|
|
</div>,
|
2025-04-15 09:07:42 +02:00
|
|
|
|
render: () => {
|
|
|
|
|
const visibleAnnotations = result.annotations.filter(annotation => !annotation.type.startsWith('_'));
|
|
|
|
|
return <>
|
|
|
|
|
{!!visibleAnnotations.length && <AutoChip header='Annotations' dataTestId='test-case-annotations'>
|
|
|
|
|
{visibleAnnotations.map((annotation, index) => <TestCaseAnnotationView key={index} annotation={annotation} />)}
|
|
|
|
|
</AutoChip>}
|
2025-05-30 15:43:55 +02:00
|
|
|
|
<TestResultView test={test!} result={result} testRunMetadata={testRunMetadata} />
|
2025-04-15 09:07:42 +02:00
|
|
|
|
</>;
|
|
|
|
|
},
|
2025-04-22 08:29:47 -07:00
|
|
|
|
})) || []} selectedTab={String(selectedResultIndex)} setSelectedTab={id => setSelectedResultIndex(+id)} />
|
|
|
|
|
</>;
|
2021-12-12 14:56:12 -08:00
|
|
|
|
};
|
|
|
|
|
|
2025-03-26 11:33:18 +01:00
|
|
|
|
function TestCaseAnnotationView({ annotation: { type, description } }: { annotation: TestAnnotation }) {
|
2023-02-23 21:57:02 +01:00
|
|
|
|
return (
|
|
|
|
|
<div className='test-case-annotation'>
|
|
|
|
|
<span style={{ fontWeight: 'bold' }}>{type}</span>
|
2024-09-17 00:57:11 +10:00
|
|
|
|
{description && <CopyToClipboardContainer value={description}>: {linkifyText(description)}</CopyToClipboardContainer>}
|
2023-02-23 21:57:02 +01:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-12 14:56:12 -08:00
|
|
|
|
function retryLabel(index: number) {
|
|
|
|
|
if (!index)
|
|
|
|
|
return 'Run';
|
|
|
|
|
return `Retry #${index}`;
|
|
|
|
|
}
|
2023-03-23 00:35:58 +03:00
|
|
|
|
|
|
|
|
|
const LabelsLinkView: React.FC<React.PropsWithChildren<{
|
|
|
|
|
labels: string[],
|
|
|
|
|
}>> = ({ labels }) => {
|
|
|
|
|
return labels.length > 0 ? (
|
|
|
|
|
<>
|
2023-08-07 13:38:09 -07:00
|
|
|
|
{labels.map(label => (
|
|
|
|
|
<a key={label} style={{ textDecoration: 'none', color: 'var(--color-fg-default)' }} href={`#?q=${label}`} >
|
2024-07-31 12:12:06 +02:00
|
|
|
|
<span style={{ margin: '6px 0 0 6px', cursor: 'pointer' }} className={clsx('label', 'label-color-' + hashStringToInt(label))}>
|
feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
2024-02-07 16:31:25 -08:00
|
|
|
|
{label.slice(1)}
|
2023-03-23 00:35:58 +03:00
|
|
|
|
</span>
|
|
|
|
|
</a>
|
|
|
|
|
))}
|
|
|
|
|
</>
|
|
|
|
|
) : null;
|
|
|
|
|
};
|