Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Fixed dropdown positioning lag; bad unit test #1655

Merged
merged 1 commit into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/modules/dropdown/dropdown.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
async,
ComponentFixture,
fakeAsync,
TestBed,
Expand All @@ -23,19 +22,20 @@ describe('Dropdown component', () => {
let fixture: ComponentFixture<DropdownTestComponent>;
let component: DropdownTestComponent;

beforeEach(async(() => {
beforeEach(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is inconsequential; compileComponents() is not needed when running in AoT mode.

TestBed.configureTestingModule({
imports: [
SkyDropdownFixturesModule
]
}).compileComponents();
}));

beforeEach(() => {
});
fixture = TestBed.createComponent(DropdownTestComponent);
component = fixture.componentInstance;
});

afterEach(() => {
fixture.destroy();
});

function openPopoverWithButtonClick() {
tick();
fixture.detectChanges();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/dropdown/dropdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ export class SkyDropdownComponent implements OnInit, OnDestroy {
case SkyDropdownMessageType.Reposition:
// Only reposition the dropdown if it is already open.
if (this.isOpen) {
this.popover.reposition();
this.windowRef.getWindow().setTimeout(() => {
this.popover.reposition();
});
}
break;

Expand Down
5 changes: 2 additions & 3 deletions src/modules/popover/popover.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ describe('SkyPopoverComponent', () => {
}));

it('should expose a method to return the placement to the preferred placement', fakeAsync(() => {
spyOn(mockAdapterService, 'getPopoverPosition').and.returnValue({
const spy = spyOn(mockAdapterService, 'getPopoverPosition').and.returnValue({
top: 0,
left: 0,
arrowLeft: 0,
Expand All @@ -342,8 +342,7 @@ describe('SkyPopoverComponent', () => {
expect(component.placement).toEqual('right');

component.reposition();
expect(component.placement).toEqual('above');
tick();
expect(spy.calls.argsFor(1)[1]).toEqual('above');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a better way to write this test: checking which value is provided to getPopoverPosition().

}));

it('should hide the popover if its top or bottom boundaries leave its scrollable parent', fakeAsync(() => {
Expand Down
10 changes: 4 additions & 6 deletions src/modules/popover/popover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,11 @@ export class SkyPopoverComponent implements OnInit, OnDestroy {
this.placement = this.preferredPlacement;
this.changeDetector.markForCheck();

this.windowRef.getWindow().setTimeout(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line that was causing the lag; it's running a setTimeout during every reposition call (not good).

if (this.adapterService.isPopoverLargerThanParent(this.popoverContainer)) {
this.placement = 'fullscreen';
}
if (this.adapterService.isPopoverLargerThanParent(this.popoverContainer)) {
this.placement = 'fullscreen';
}

this.positionPopover();
});
this.positionPopover();
}

public close() {
Expand Down
5 changes: 3 additions & 2 deletions src/modules/timepicker/timepicker-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ describe('Timepicker', () => {
const closeButton = fixture.nativeElement.querySelector('.sky-timepicker-footer button');
closeButton.click();
tick();
fixture.detectChanges();
tick();
const dropdown = fixture.nativeElement.querySelector('.sky-popover-container') as HTMLElement;
expect(dropdown.classList.contains('sky-popover-hidden')).toEqual(false);
const hiddenPopover = fixture.nativeElement.querySelector('.sky-popover-hidden') as HTMLElement;
expect(hiddenPopover).not.toBeNull();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this bad test during my work on this bugfix. We were supposed to be checking if the popover had closed!

}));

it('should handle input change with a string with the expected timeFormat', fakeAsync(() => {
Expand Down