Skip to content

Commit

Permalink
- fix regions copy from previous baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-silakov committed Sep 29, 2023
1 parent 0fb3ed5 commit 15ebe5f
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 1,112 deletions.
15 changes: 11 additions & 4 deletions mvc/controllers/api/api_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,19 +732,26 @@ async function createNewBaseline(params) {

const identFields = buildIdentObject(params);

const lastBaseline = await Baseline.findOne(identFields)
.exec();

const sameBaseline = await Baseline.findOne({ ...identFields, ...{ snapshootId: params.actualSnapshotId } })
.exec();

const baselineParams = lastBaseline?.ignoreRegions
? { ...identFields, ...{ ignoreRegions: lastBaseline.ignoreRegions } }
: identFields;

if (sameBaseline) {
log.debug(`the baseline with same ident and snapshot id: ${params.actualSnapshotId} already exist`, $this);
} else {
log.debug(`the baseline with same ident and snapshot id: ${params.actualSnapshotId} does not exist,
create new one, identFields: ${JSON.stringify(identFields)}`, $this);
create new one, baselineParams: ${JSON.stringify(baselineParams)}`, $this);
}

log.silly({ sameBaseline });

const resultedBaseline = sameBaseline || await Baseline.create(identFields);
const resultedBaseline = sameBaseline || await Baseline.create(baselineParams);

resultedBaseline.markedAs = params.markedAs;
resultedBaseline.markedById = params.markedById;
Expand All @@ -754,7 +761,7 @@ async function createNewBaseline(params) {
resultedBaseline.snapshootId = params.actualSnapshotId;

return resultedBaseline.save();
};
}

module.exports.createNewBaseline = createNewBaseline;

Expand Down Expand Up @@ -2132,7 +2139,7 @@ exports.task_test = async (req, res, next) => {
);

for (let i = 0; i < x; i += 1) {
await new Promise(r => setTimeout(() => r(), interval));
await new Promise((r) => setTimeout(() => r(), interval));
taskOutput(`- Task Output - '${i}'\n`, res);
if (isAborted) {
taskOutput(`the task was aborted\n`, res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import { log } from '../../../../../../../shared/utils/Logger';

/* eslint-disable dot-notation,no-underscore-dangle */
interface IRectParams {
name: any
fill: any
stroke: any
strokeWidth: any
top: any
left: any
width: any
height: any
name: any;
fill: any;
stroke: any;
strokeWidth: any;
top: any;
left: any;
width: any;
height: any;
}

interface Props {
canvasElementWidth: number
canvasElementHeight: number
canvasId: string
canvasElementWidth: number;
canvasElementHeight: number;
canvasId: string;
// url: string
actual: any
expectedImage: any
actualImage: any
diffImage: any
actual: any;
expectedImage: any;
actualImage: any;
diffImage: any;
}

export class MainView {
Expand Down Expand Up @@ -347,6 +347,13 @@ export class MainView {
r.bringToFront();
}

removeAllRegions() {
const regions = this.allRects;
regions.forEach((region) => {
this.canvas.remove(region);
});
}

get allRects() {
return this.canvas.getObjects()
.filter((r) => (r.name === 'ignore_rect') || (r.name === 'bound_rect'));
Expand Down Expand Up @@ -481,6 +488,7 @@ export class MainView {
}

async getSnapshotIgnoreRegionsDataAndDrawRegions(id: string) {
this.removeAllRegions();
const regionData = await MainView.getRegionsData(id);
this.drawRegions(regionData.ignoreRegions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function CheckDetails({ initCheckData, checkQuery, closeHandler }: Props)
const diffImgSrc = `${config.baseUri}/snapshoots/${currentCheck?.diffId?.filename}?diffImg`;
const diffImage = currentCheck?.diffId?.filename ? await imageFromUrl(diffImgSrc) : null;

await setMainView((prev) => {
setMainView((prev) => {
if (prev) return prev; // for dev mode, when components render twice
const MV = new MainView(
{
Expand Down Expand Up @@ -185,9 +185,9 @@ export function CheckDetails({ initCheckData, checkQuery, closeHandler }: Props)
mainView.getSnapshotIgnoreRegionsDataAndDrawRegions(baselineId);
}
}, [
baselineQuery.data?.timestamp,
// baselineQuery.data?.timestamp,
mainView?.toString(),
query.checkId,
// query.checkId,
]);

return (
Expand Down
Loading

0 comments on commit 15ebe5f

Please sign in to comment.