Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: implement tree w/o list #33169

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/playwright/src/matchers/toMatchAriaSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export async function toMatchAriaSnapshot(

const messagePrefix = matcherHint(this, receiver, matcherName, 'locator', undefined, matcherOptions, timedOut ? timeout : undefined);
const notFound = received === kNoElementsFoundError;
const escapedExpected = escapePrivateUsePoints(expected);
const escapedReceived = escapePrivateUsePoints(received);
const escapedExpected = unshift(escapePrivateUsePoints(expected));
const escapedReceived = unshift(escapePrivateUsePoints(received));
const message = () => {
if (pass) {
if (notFound)
Expand Down Expand Up @@ -79,3 +79,17 @@ export async function toMatchAriaSnapshot(
function escapePrivateUsePoints(str: string) {
return str.replace(/[\uE000-\uF8FF]/g, char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
}

function unshift(snapshot: string): string {
const lines = snapshot.split('\n');
let whitespacePrefixLength = 100;
for (const line of lines) {
if (!line.trim())
continue;
const match = line.match(/^(\s*)/);
if (match && match[1].length < whitespacePrefixLength)
whitespacePrefixLength = match[1].length;
break;
}
return lines.filter(t => t.trim()).map(line => line.substring(whitespacePrefixLength)).join('\n');
}
36 changes: 30 additions & 6 deletions packages/trace-viewer/src/ui/actionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ export const ActionList: React.FC<ActionListProps> = ({
return { selectedItem };
}, [itemMap, selectedAction]);

const isError = React.useCallback((item: ActionTreeItem) => {
return !!item.action?.error?.message;
}, []);

const onAccepted = React.useCallback((item: ActionTreeItem) => {
return setSelectedTime({ minimum: item.action!.startTime, maximum: item.action!.endTime });
}, [setSelectedTime]);

const render = React.useCallback((item: ActionTreeItem) => {
return renderAction(item.action!, { sdkLanguage, revealConsole, isLive, showDuration: true, showBadges: true });
}, [isLive, revealConsole, sdkLanguage]);

const isVisible = React.useCallback((item: ActionTreeItem) => {
return !selectedTime || !item.action || (item.action!.startTime <= selectedTime.maximum && item.action!.endTime >= selectedTime.minimum);
}, [selectedTime]);

const onSelectedAction = React.useCallback((item: ActionTreeItem) => {
onSelected?.(item.action!);
}, [onSelected]);

const onHighlightedAction = React.useCallback((item: ActionTreeItem | undefined) => {
onHighlighted?.(item?.action);
}, [onHighlighted]);

return <div className='vbox'>
{selectedTime && <div className='action-list-show-all' onClick={() => setSelectedTime(undefined)}><span className='codicon codicon-triangle-left'></span>Show all</div>}
<ActionTreeView
Expand All @@ -67,12 +91,12 @@ export const ActionList: React.FC<ActionListProps> = ({
treeState={treeState}
setTreeState={setTreeState}
selectedItem={selectedItem}
onSelected={item => onSelected?.(item.action!)}
onHighlighted={item => onHighlighted?.(item?.action)}
onAccepted={item => setSelectedTime({ minimum: item.action!.startTime, maximum: item.action!.endTime })}
isError={item => !!item.action?.error?.message}
isVisible={item => !selectedTime || (item.action!.startTime <= selectedTime.maximum && item.action!.endTime >= selectedTime.minimum)}
render={item => renderAction(item.action!, { sdkLanguage, revealConsole, isLive, showDuration: true, showBadges: true })}
onSelected={onSelectedAction}
onHighlighted={onHighlightedAction}
onAccepted={onAccepted}
isError={isError}
isVisible={isVisible}
render={render}
/>
</div>;
};
Expand Down
3 changes: 2 additions & 1 deletion packages/trace-viewer/src/ui/uiModeTestListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const TestListView: React.FC<{
render={treeItem => {
return <div className='hbox ui-mode-tree-item'>
<div className='ui-mode-tree-item-title'>
<span title={treeItem.title}>{treeItem.title}</span>
<span>{treeItem.title}</span>
{treeItem.kind === 'case' ? treeItem.tags.map(tag => <TagView key={tag} tag={tag.slice(1)} onClick={e => handleTagClick(e, tag)} />) : null}
</div>
{!!treeItem.duration && treeItem.status !== 'skipped' && <div className='ui-mode-tree-item-time'>{msToString(treeItem.duration)}</div>}
Expand All @@ -179,6 +179,7 @@ export const TestListView: React.FC<{
</div>;
}}
icon={treeItem => testStatusIcon(treeItem.status)}
title={treeItem => treeItem.title}
selectedItem={selectedTreeItem}
onAccepted={runTreeItem}
onSelected={treeItem => {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/toolbarButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const ToolbarButton: React.FC<React.PropsWithChildren<ToolbarButtonProps>
disabled={!!disabled}
style={style}
data-testid={testId}
aria-label={ariaLabel}
aria-label={ariaLabel || title}
>
{icon && <span className={`codicon codicon-${icon}`} style={children ? { marginRight: 5 } : {}}></span>}
{children}
Expand Down
Loading
Loading