Skip to content

Commit 6e30368

Browse files
devversionandrewseguin
authored andcommitted
test: ignore test failures in popover-edit due to minor subpixel deviations
A small set of popover-edit tests relies on the bounding client rect. Assertions that the panel stretches over the first and last cell are correct but require an exact equality. This is not reliable as in some situations, browsers handle subpixels differently, resulting in small deviations in the bounding client rect positions. These differences are only noticeable less significant decimal places, but the overall assertion matches full pixels. This is sufficient for these tests so we just round all measurements/comparisons to full pixels.
1 parent d2f7195 commit 6e30368

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

src/cdk-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
683683
});
684684

685685
describe('edit lens', () => {
686+
function expectPixelsToEqual(actual: number, expected: number) {
687+
expect(Math.round(actual)).toBe(Math.round(expected));
688+
}
689+
686690
it('shows a lens with the value from the table', fakeAsync(() => {
687691
component.openLens();
688692

@@ -697,9 +701,9 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
697701
const paneRect = component.getEditPane()!.getBoundingClientRect();
698702
const cellRect = component.getEditCell().getBoundingClientRect();
699703

700-
expect(paneRect.width).toBe(cellRect.width);
701-
expect(paneRect.left).toBe(cellRect.left);
702-
expect(paneRect.top).toBe(cellRect.top);
704+
expectPixelsToEqual(paneRect.width, cellRect.width);
705+
expectPixelsToEqual(paneRect.left, cellRect.left);
706+
expectPixelsToEqual(paneRect.top, cellRect.top);
703707
clearLeftoverTimers();
704708
}));
705709

@@ -713,25 +717,25 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
713717
component.openLens();
714718

715719
let paneRect = component.getEditPane()!.getBoundingClientRect();
716-
expect(paneRect.top).toBe(cellRects[0].top);
717-
expect(paneRect.left).toBe(cellRects[0].left);
718-
expect(paneRect.right).toBe(cellRects[1].right);
720+
expectPixelsToEqual(paneRect.top, cellRects[0].top);
721+
expectPixelsToEqual(paneRect.left, cellRects[0].left);
722+
expectPixelsToEqual(paneRect.right, cellRects[1].right);
719723

720724
component.colspan = {after: 1};
721725
fixture.detectChanges();
722726

723727
paneRect = component.getEditPane()!.getBoundingClientRect();
724-
expect(paneRect.top).toBe(cellRects[1].top);
725-
expect(paneRect.left).toBe(cellRects[1].left);
726-
expect(paneRect.right).toBe(cellRects[2].right);
728+
expectPixelsToEqual(paneRect.top, cellRects[1].top);
729+
expectPixelsToEqual(paneRect.left, cellRects[1].left);
730+
expectPixelsToEqual(paneRect.right, cellRects[2].right);
727731

728732
component.colspan = {before: 1, after: 1};
729733
fixture.detectChanges();
730734

731735
paneRect = component.getEditPane()!.getBoundingClientRect();
732-
expect(paneRect.top).toBe(cellRects[0].top);
733-
expect(paneRect.left).toBe(cellRects[0].left);
734-
expect(paneRect.right).toBe(cellRects[2].right);
736+
expectPixelsToEqual(paneRect.top, cellRects[0].top);
737+
expectPixelsToEqual(paneRect.left, cellRects[0].left);
738+
expectPixelsToEqual(paneRect.right, cellRects[2].right);
735739
clearLeftoverTimers();
736740
}));
737741

src/material-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {DataSource} from '@angular/cdk/collections';
1+
import {DataSource} from '@angular/cdk/collections';
22
import {LEFT_ARROW, UP_ARROW, RIGHT_ARROW, DOWN_ARROW, TAB} from '@angular/cdk/keycodes';
33
import {MatTableModule} from '@angular/material/table';
44
import {dispatchKeyboardEvent} from '@angular/cdk/testing/private';
@@ -564,6 +564,10 @@ matPopoverEditTabOut`, fakeAsync(() => {
564564
});
565565

566566
describe('edit lens', () => {
567+
function expectPixelsToEqual(actual: number, expected: number) {
568+
expect(Math.round(actual)).toBe(Math.round(expected));
569+
}
570+
567571
it('shows a lens with the value from the table', fakeAsync(() => {
568572
component.openLens();
569573

@@ -578,9 +582,9 @@ matPopoverEditTabOut`, fakeAsync(() => {
578582
const paneRect = component.getEditPane()!.getBoundingClientRect();
579583
const cellRect = component.getEditCell().getBoundingClientRect();
580584

581-
expect(paneRect.width).toBe(cellRect.width);
582-
expect(paneRect.left).toBe(cellRect.left);
583-
expect(paneRect.top).toBe(cellRect.top);
585+
expectPixelsToEqual(paneRect.width, cellRect.width);
586+
expectPixelsToEqual(paneRect.left, cellRect.left);
587+
expectPixelsToEqual(paneRect.top, cellRect.top);
584588
clearLeftoverTimers();
585589
}));
586590

@@ -594,25 +598,25 @@ matPopoverEditTabOut`, fakeAsync(() => {
594598
component.openLens();
595599

596600
let paneRect = component.getEditPane()!.getBoundingClientRect();
597-
expect(paneRect.top).toBe(cellRects[0].top);
598-
expect(paneRect.left).toBe(cellRects[0].left);
599-
expect(paneRect.right).toBe(cellRects[1].right);
601+
expectPixelsToEqual(paneRect.top, cellRects[0].top);
602+
expectPixelsToEqual(paneRect.left, cellRects[0].left);
603+
expectPixelsToEqual(paneRect.right, cellRects[1].right);
600604

601605
component.colspan = {after: 1};
602606
fixture.detectChanges();
603607

604608
paneRect = component.getEditPane()!.getBoundingClientRect();
605-
expect(paneRect.top).toBe(cellRects[1].top);
606-
expect(paneRect.left).toBe(cellRects[1].left);
607-
expect(paneRect.right).toBe(cellRects[2].right);
609+
expectPixelsToEqual(paneRect.top, cellRects[1].top);
610+
expectPixelsToEqual(paneRect.left, cellRects[1].left);
611+
expectPixelsToEqual(paneRect.right, cellRects[2].right);
608612

609613
component.colspan = {before: 1, after: 1};
610614
fixture.detectChanges();
611615

612616
paneRect = component.getEditPane()!.getBoundingClientRect();
613-
expect(paneRect.top).toBe(cellRects[0].top);
614-
expect(paneRect.left).toBe(cellRects[0].left);
615-
expect(paneRect.right).toBe(cellRects[2].right);
617+
expectPixelsToEqual(paneRect.top, cellRects[0].top);
618+
expectPixelsToEqual(paneRect.left, cellRects[0].left);
619+
expectPixelsToEqual(paneRect.right, cellRects[2].right);
616620
clearLeftoverTimers();
617621
}));
618622

0 commit comments

Comments
 (0)