Skip to content

Commit c104cb7

Browse files
committed
ignore area concat added
1 parent 6e8ce25 commit c104cb7

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/test-runs/test-runs.service.spec.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ describe('TestRunsService', () => {
491491
baseline,
492492
image,
493493
testRun.diffTollerancePercent,
494-
testVariation.ignoreAreas
494+
JSON.parse(testVariation.ignoreAreas)
495495
);
496496
expect(getImageMock).toHaveBeenNthCalledWith(1, testVariation.baselineName);
497497
expect(getImageMock).toHaveBeenNthCalledWith(2, imageName);
@@ -523,7 +523,12 @@ describe('TestRunsService', () => {
523523
status: TestStatus.new,
524524
},
525525
});
526-
expect(getDiffMock).toHaveBeenCalledWith(baseline, image, testRun.diffTollerancePercent, testRun.ignoreAreas);
526+
expect(getDiffMock).toHaveBeenCalledWith(
527+
baseline,
528+
image,
529+
testRun.diffTollerancePercent,
530+
JSON.parse(testRun.ignoreAreas)
531+
);
527532
expect(saveDiffResultMock).toHaveBeenCalledWith(testRun.id, diffResult);
528533
expect(eventTestRunCreatedMock).toHaveBeenCalledWith(testRunWithResult);
529534
expect(result).toBe(testRunWithResult);
@@ -538,7 +543,7 @@ describe('TestRunsService', () => {
538543
});
539544
service = await initService({});
540545

541-
const result = service.getDiff(baseline, image, 0, '[]');
546+
const result = service.getDiff(baseline, image, 0, []);
542547

543548
expect(result).toStrictEqual({
544549
status: undefined,
@@ -560,7 +565,7 @@ describe('TestRunsService', () => {
560565
});
561566
service = await initService({});
562567

563-
const result = service.getDiff(baseline, image, 0, '[]');
568+
const result = service.getDiff(baseline, image, 0, []);
564569

565570
expect(result).toStrictEqual({
566571
status: TestStatus.unresolved,
@@ -583,7 +588,7 @@ describe('TestRunsService', () => {
583588
service = await initService({});
584589
mocked(Pixelmatch).mockReturnValueOnce(0);
585590

586-
const result = service.getDiff(baseline, image, 0, '[]');
591+
const result = service.getDiff(baseline, image, 0, []);
587592

588593
expect(result).toStrictEqual({
589594
status: TestStatus.ok,
@@ -608,7 +613,7 @@ describe('TestRunsService', () => {
608613
const pixelMisMatchCount = 150;
609614
mocked(Pixelmatch).mockReturnValueOnce(pixelMisMatchCount);
610615

611-
const result = service.getDiff(baseline, image, 1.5, '[]');
616+
const result = service.getDiff(baseline, image, 1.5, []);
612617

613618
expect(saveImageMock).toHaveBeenCalledTimes(0);
614619
expect(result).toStrictEqual({
@@ -637,7 +642,7 @@ describe('TestRunsService', () => {
637642
saveImageMock,
638643
});
639644

640-
const result = service.getDiff(baseline, image, 1, '[]');
645+
const result = service.getDiff(baseline, image, 1, []);
641646

642647
expect(saveImageMock).toHaveBeenCalledTimes(1);
643648
expect(result).toStrictEqual({
@@ -689,7 +694,7 @@ describe('TestRunsService', () => {
689694
baselineMock,
690695
imageeMock,
691696
testRun.diffTollerancePercent,
692-
testRun.ignoreAreas
697+
JSON.parse(testRun.ignoreAreas)
693698
);
694699
expect(service.emitUpdateBuildEvent).toBeCalledWith(testRun.buildId);
695700
});

src/test-runs/test-runs.service.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class TestRunsService {
184184
const image = this.staticService.getImage(testRun.imageName);
185185
await this.staticService.deleteImage(testRun.diffName);
186186

187-
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testRun.ignoreAreas);
187+
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, JSON.parse(testRun.ignoreAreas));
188188
const updatedTestRun = await this.saveDiffResult(id, diffResult);
189189
this.emitUpdateBuildEvent(testRun.buildId);
190190
return updatedTestRun;
@@ -227,7 +227,14 @@ export class TestRunsService {
227227
const baseline = this.staticService.getImage(testRun.baselineName);
228228
const image = this.staticService.getImage(imageName);
229229

230-
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testVariation.ignoreAreas);
230+
let ignoreAreas: IgnoreAreaDto[] = [];
231+
if (!!testVariation.ignoreAreas) {
232+
ignoreAreas = ignoreAreas.concat(JSON.parse(testVariation.ignoreAreas));
233+
}
234+
if (createTestRequestDto.ignoreAreas?.length > 0) {
235+
ignoreAreas = ignoreAreas.concat(createTestRequestDto.ignoreAreas);
236+
}
237+
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, ignoreAreas);
231238

232239
const testRunWithResult = await this.saveDiffResult(testRun.id, diffResult);
233240
this.eventsGateway.testRunCreated(testRunWithResult);
@@ -267,7 +274,7 @@ export class TestRunsService {
267274
});
268275
}
269276

270-
getDiff(baseline: PNG, image: PNG, diffTollerancePercent: number, ignoreAreas: string): DiffResult {
277+
getDiff(baseline: PNG, image: PNG, diffTollerancePercent: number, ignoreAreas: IgnoreAreaDto[]): DiffResult {
271278
const result: DiffResult = {
272279
status: undefined,
273280
diffName: null,
@@ -287,8 +294,8 @@ export class TestRunsService {
287294

288295
// compare
289296
result.pixelMisMatchCount = Pixelmatch(
290-
this.applyIgnoreAreas(baseline, JSON.parse(ignoreAreas)),
291-
this.applyIgnoreAreas(image, JSON.parse(ignoreAreas)),
297+
this.applyIgnoreAreas(baseline, ignoreAreas),
298+
this.applyIgnoreAreas(image, ignoreAreas),
292299
diff.data,
293300
baseline.width,
294301
baseline.height,

src/test-variations/test-variations.service.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,15 @@ describe('TestVariationsService', () => {
454454
imageBase64: PNG.sync.write(image).toString('base64'),
455455
diffTollerancePercent: 0,
456456
merge: true,
457+
ignoreAreas: JSON.parse(testVariation.ignoreAreas),
457458
});
458459
expect(testRunCreateMock).toHaveBeenNthCalledWith(2, testVariationMainBranch, {
459460
...testVariationSecond,
460461
buildId: build.id,
461462
imageBase64: PNG.sync.write(image).toString('base64'),
462463
diffTollerancePercent: 0,
463464
merge: true,
465+
ignoreAreas: JSON.parse(testVariationSecond.ignoreAreas),
464466
});
465467
expect(testRunCreateMock).toHaveBeenCalledTimes(2);
466468
expect(buildStopMock).toHaveBeenCalledWith(build.id);

0 commit comments

Comments
 (0)