Skip to content

Commit

Permalink
Merge pull request #534 from gemini-testing/HERMIONE-1403.html_report…
Browse files Browse the repository at this point in the history
…er_diff

feat: display differentPixels, if available
  • Loading branch information
KuznetsovRoman authored Mar 4, 2024
2 parents f7a60d5 + aeb47d5 commit 316327c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 37 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
28 changes: 24 additions & 4 deletions lib/static/components/state/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,19 @@ class State extends Component {
);
}

_getStateTitle() {
_getDisplayedDiffPercentValue() {
const percent = this.props.image.diffRatio * 100;
const percentRounded = Math.ceil(percent * 100) / 100;
const percentThreshold = 0.01;

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

return String(percentRounded);
}

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

if (!image.stateName) {
Expand All @@ -138,15 +150,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();

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 +188,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
37 changes: 8 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"eslint-plugin-react": "^7.32.2",
"events": "^3.3.0",
"fork-ts-checker-webpack-plugin": "^9.0.0",
"hermione": "^8.0.5",
"hermione": "^8.2.1",
"hermione-global-hook": "^1.0.1",
"hermione-test-repeater": "^0.0.8",
"html-react-parser": "^0.4.0",
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,
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 316327c

Please sign in to comment.