Skip to content

Commit

Permalink
feat: display differentPixels, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Mar 4, 2024
1 parent f7a60d5 commit 1e62faf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface ImageDiffError {
diffClusters: CoordBounds[];
diffBuffer?: ArrayBuffer;
diffImg?: ImageFile;
differentPixels?: number; // defined if hermione >= 8.2.0
diffRatio?: number; // defined if hermione >= 8.2.0
}

export interface NoRefImageError {
Expand Down
33 changes: 29 additions & 4 deletions lib/static/components/state/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,24 @@ class State extends Component {
);
}

_getStateTitle() {
_getDisplayedDiffPercentValue(ratio) {
console.log('inFunc');
const percent = ratio * 100;
const percentThreshold = 0.001;
const percentString = String(percent);

if (percent < percentThreshold) {
return `< ${percentThreshold}`
}

if (percent > 1) {
return percentString.slice(0, 4);
}

return percentString.slice(0, 5);
}

_getStateTitleWithDiffCount() {
const {image, shouldImageBeOpened} = this.props;

if (!image.stateName) {
Expand All @@ -138,15 +155,23 @@ class State extends Component {
`state-title_${image.status}`
);

return <div className={className} onClick={this.onToggleStateResult}>{image.stateName}</div>;
let displayedText = image.stateName;

if (image.differentPixels && image.diffRatio) {
const displayedDiffPercent = this._getDisplayedDiffPercentValue(image.diffRatio);

displayedText += ` (diff: ${image.differentPixels}px, ${displayedDiffPercent}%)`;
}

return <div className={className} onClick={this.onToggleStateResult}>{displayedText}</div>;
}

render() {
if (!this.props.shouldImageBeOpened) {
return (
<Fragment>
<hr className="tab__separator" />
{this._getStateTitle()}
{this._getStateTitleWithDiffCount()}
</Fragment>
);
}
Expand All @@ -168,7 +193,7 @@ class State extends Component {
return (
<Fragment>
<hr className="tab__separator"/>
{this._getStateTitle()}
{this._getStateTitleWithDiffCount()}
{this._drawFailImageControls()}
{this._drawUpdatedImageControls()}
{elem ? <div className='image-box__container'>{elem}</div> : null}
Expand Down
4 changes: 3 additions & 1 deletion lib/test-adapter/hermione.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export class HermioneTestAdapter implements ReporterTestResult {
...(diffImg ? {diffImg} : {}),
expectedImg: _.clone(assertResult.refImg),
diffClusters: assertResult.diffClusters,
diffOptions: assertResult.diffOpts
diffOptions: assertResult.diffOpts,
differentPixels: assertResult.differentPixels,
diffRatio: assertResult.diffRatio
} satisfies ImageInfoDiff;
} else if (isNoRefImageError(assertResult)) {
return {
Expand Down
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export interface ImageInfoDiff {
actualImg: ImageFile;
diffImg?: ImageFile | ImageBuffer;
diffOptions: DiffOptions;
differentPixels?: number; // defined if hermione >= 8.2.0
diffRatio?: number; // defined if hermione >= 8.2.0
}

interface AssertViewSuccess {
Expand Down
8 changes: 6 additions & 2 deletions test/unit/lib/test-adapter/hermione.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ describe('HermioneTestAdapter', () => {
name: 'ImageDiffError',
refImg: {path: 'ref-path', size: {width: 25, height: 15}},
stack: 'some-stack',
stateName: 'some-state'
stateName: 'some-state',
differentPixels: 100,

Check failure on line 241 in test/unit/lib/test-adapter/hermione.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Type '{ currImg: { path: string; size: { width: number; height: number; }; }; diffClusters: never[]; diffOpts: any; message: string; name: "ImageDiffError"; refImg: { path: string; size: { width: number; height: number; }; }; stack: string; stateName: string; differentPixels: number; diffRatio: number; }' is not assignable to type 'AssertViewResult'.

Check failure on line 241 in test/unit/lib/test-adapter/hermione.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Type '{ currImg: { path: string; size: { width: number; height: number; }; }; diffClusters: never[]; diffOpts: any; message: string; name: "ImageDiffError"; refImg: { path: string; size: { width: number; height: number; }; }; stack: string; stateName: string; differentPixels: number; diffRatio: number; }' is not assignable to type 'AssertViewResult'.

Check failure on line 241 in test/unit/lib/test-adapter/hermione.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Type '{ currImg: { path: string; size: { width: number; height: number; }; }; diffClusters: never[]; diffOpts: any; message: string; name: "ImageDiffError"; refImg: { path: string; size: { width: number; height: number; }; }; stack: string; stateName: string; differentPixels: number; diffRatio: number; }' is not assignable to type 'AssertViewResult'.
diffRatio: 0.01
}]
});

Expand All @@ -251,7 +253,9 @@ describe('HermioneTestAdapter', () => {
expectedImg: {path: 'ref-path', size: {height: 15, width: 25}},
refImg: {path: 'ref-path', size: {height: 15, width: 25}},
diffClusters: [],
diffOptions: {diffColor: '#000'} as any
diffOptions: {diffColor: '#000'} as any,
differentPixels: 100,
diffRatio: 0.01
}
]);
});
Expand Down

0 comments on commit 1e62faf

Please sign in to comment.