-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(popover): add missing start and end positions to positions mapping (
- Loading branch information
Showing
2 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/framework/theme/components/cdk/overlay/overlay-position.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { Component, NgModule } from '@angular/core'; | ||
import { | ||
NbThemeModule, | ||
NbOverlayModule, | ||
NbPositionBuilderService, | ||
NbOverlayService, | ||
NbComponentPortal, | ||
NbLayoutModule, NbLayoutComponent, | ||
} from '@nebular/theme'; | ||
import { | ||
NbAdjustableConnectedPositionStrategy, | ||
NbPosition, | ||
NbAdjustment, | ||
} from '@nebular/theme/components/cdk/overlay/overlay-position'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
@Component({ | ||
template: `portal-component`, | ||
}) | ||
export class PortalComponent {} | ||
|
||
@NgModule({ | ||
declarations: [ PortalComponent ], | ||
exports: [ PortalComponent ], | ||
entryComponents: [ PortalComponent ], | ||
}) | ||
export class PortalModule {} | ||
|
||
describe('NbAdjustableConnectedPositionStrategy', () => { | ||
let strategy: NbAdjustableConnectedPositionStrategy; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NbThemeModule.forRoot(), | ||
NbOverlayModule.forRoot(), | ||
NbLayoutModule, | ||
PortalModule, | ||
RouterTestingModule.withRoutes([]), | ||
], | ||
}); | ||
|
||
// Have to create layout component as it's required for scroll service to work properly. | ||
// Also it registers overlay container so we don't have to create it manually. | ||
TestBed.createComponent(NbLayoutComponent); | ||
|
||
const hostElement = document.createElement('div'); | ||
hostElement.style.width = '10px'; | ||
hostElement.style.height = '10px'; | ||
hostElement.style.backgroundColor = 'red'; | ||
document.body.appendChild(hostElement); | ||
|
||
const positionBuilderService: NbPositionBuilderService = TestBed.get(NbPositionBuilderService); | ||
strategy = positionBuilderService.connectedTo({ nativeElement: hostElement }); | ||
}); | ||
|
||
it('should create strategy with position start and adjustment noop', () => { | ||
const withPositionsSpy = spyOn(strategy, 'withPositions').and.callThrough(); | ||
|
||
strategy.position(NbPosition.START).adjustment(NbAdjustment.NOOP); | ||
|
||
const overlayService: NbOverlayService = TestBed.get(NbOverlayService); | ||
const overlayRef = overlayService.create({ positionStrategy: strategy }); | ||
overlayRef.attach(new NbComponentPortal(PortalComponent)); | ||
|
||
expect(withPositionsSpy).toHaveBeenCalledTimes(1); | ||
expect(withPositionsSpy).toHaveBeenCalledWith(jasmine.objectContaining([{ | ||
originX: 'start', | ||
originY: 'center', | ||
overlayX: 'end', | ||
overlayY: 'center', | ||
offsetX: -15, | ||
}])); | ||
}); | ||
|
||
it('should create strategy with position end and adjustment noop', () => { | ||
const withPositionsSpy = spyOn(strategy, 'withPositions').and.callThrough(); | ||
|
||
strategy.position(NbPosition.END).adjustment(NbAdjustment.NOOP); | ||
|
||
const overlayService: NbOverlayService = TestBed.get(NbOverlayService); | ||
const overlayRef = overlayService.create({ positionStrategy: strategy }); | ||
overlayRef.attach(new NbComponentPortal(PortalComponent)); | ||
|
||
expect(withPositionsSpy).toHaveBeenCalledTimes(1); | ||
expect(withPositionsSpy).toHaveBeenCalledWith(jasmine.objectContaining([{ | ||
originX: 'end', | ||
originY: 'center', | ||
overlayX: 'start', | ||
overlayY: 'center', | ||
offsetX: 15, | ||
}])); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters