Skip to content

Commit

Permalink
fix: add playwright visual checks results to correct steps in new ui
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Nov 23, 2024
1 parent 3be381f commit b33ed87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {createSelector} from 'reselect';
import {AssertViewResult, Attachment, ErrorInfo, Step, StepType} from './types';
import {Action, AssertViewResult, Attachment, ErrorInfo, Step, StepType} from './types';
import {TestStepCompressed, TestStepKey} from '@/types';
import {unstable_ListTreeItemType as ListTreeItemType} from '@gravity-ui/uikit/unstable';
import {TestStatus} from '@/constants';
import {TestStatus, ToolName} from '@/constants';
import {isAssertViewError, isImageDiffError, mergeSnippetIntoErrorStack} from '@/common-utils';
import {traverseTree} from '@/static/new-ui/features/suites/components/TestSteps/utils';
import {ImageEntityError} from '@/static/new-ui/types/store';
Expand All @@ -11,10 +11,11 @@ import {
getCurrentResultImages,
getExpandedStepsById
} from '@/static/new-ui/features/suites/selectors';
import {getToolName} from '@/static/new-ui/store/selectors';

export const getTestSteps = createSelector(
[getCurrentResult, getCurrentResultImages],
(result, images): ListTreeItemType<Step>[] => {
[getToolName, getCurrentResult, getCurrentResultImages],
(toolName, result, images): ListTreeItemType<Step>[] => {
if (!result || !result.history) {
return [];
}
Expand Down Expand Up @@ -95,7 +96,19 @@ export const getTestSteps = createSelector(
let matchedStep: ListTreeItemType<Step> | undefined;

traverseTree(steps, step => {
if (step.data.type === StepType.Action && step.data.title === 'assertView' && step.data.args[0] === image.stateName) {
if (step.data.type !== StepType.Action) {
return;
}
if (toolName === ToolName.Playwright) {
if (
// Built-in playwright screenshot assertion
(step.data.title.includes('toHaveScreenshot') && step.data.title.includes(image.stateName ?? '')) ||
// Assertions provided by gemini-testing playwright-utils
(step.data.title.includes('toMatchScreenshot')) && (step.children?.[0]?.data as Action)?.title?.includes(image.stateName ?? '')
) {
matchedStep = step;
}
} else if (step.data.title === 'assertView' && step.data.args[0] === image.stateName) {
matchedStep = step;
}
});
Expand Down Expand Up @@ -125,7 +138,7 @@ export const getTestSteps = createSelector(
data: {
type: StepType.ErrorInfo,
name: image.error.name,
stack: image.error.stack
stack: image.error.stack || image.error.message
}
};
const errorAttachment = {
Expand Down
1 change: 1 addition & 0 deletions lib/static/new-ui/store/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@/static/new-ui/types/store';
import {EditScreensFeature, RunTestsFeature} from '@/constants';

export const getToolName = (state: State): string => state.apiValues.toolName;
export const getAllRootSuiteIds = (state: State): string[] => state.tree.suites.allRootIds;
export const getAllRootGroupIds = (state: State): string[] => state.tree.groups.allRootIds;
export const getGroups = (state: State): Record<string, GroupEntity> => state.tree.groups.byId;
Expand Down

0 comments on commit b33ed87

Please sign in to comment.