Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('and aligns content when ClrAxis is HORIZONTAL and there is LEFT ViewportViolation', function(this: TestContext) {
const leftViolation: ClrPopoverPosition = {
axis: ClrAxis.HORIZONTAL,
side: ClrSide.BEFORE,
anchor: ClrAlignment.START,
content: ClrAlignment.START,
};
// Test a LEFT violation
this.positionService.position = leftViolation;
popoverContent.style.width = '25px';
popoverContent.style.height = '25px';
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisOneViolationSpy.calls.count()).toEqual(1);
expect(handleVerticalAxisTwoViolationsSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisTwoViolationsSpy).not.toHaveBeenCalled();
});
it('and aligns content when Axis is VERTICAL and there are BOTTOM/RIGHT ViewportViolations', function(this: TestContext) {
const bottomRightViolation: ClrPopoverPosition = {
axis: ClrAxis.VERTICAL,
side: ClrSide.AFTER,
anchor: ClrAlignment.END,
content: ClrAlignment.START,
};
popoverContent.style.width = window.innerWidth + 'px';
popoverContent.style.height = window.innerHeight + 'px';
this.positionService.position = bottomRightViolation;
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleVerticalAxisTwoViolationsSpy.calls.count()).toEqual(1);
expect(handleHorizontalAxisTwoViolationsSpy).not.toHaveBeenCalled();
});
it('and aligns content when visibility is 🆗', function(this: TestContext) {
const goodPosition: ClrPopoverPosition = {
anchor: ClrAlignment.END,
axis: ClrAxis.HORIZONTAL,
content: ClrAlignment.START,
side: ClrSide.AFTER,
};
this.positionService.position = goodPosition;
popoverContent.style.width = '25px';
popoverContent.style.height = '25px';
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleVerticalAxisTwoViolationsSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisTwoViolationsSpy).not.toHaveBeenCalled();
});
it('and aligns content when Axis is VERTICAL and there is a RIGHT ViewportViolation', function(this: TestContext) {
const rightViolation: ClrPopoverPosition = {
axis: ClrAxis.VERTICAL,
side: ClrSide.AFTER,
anchor: ClrAlignment.START,
content: ClrAlignment.END,
};
popoverContent.style.width = window.innerWidth + 'px';
popoverContent.style.height = '5px';
this.positionService.position = rightViolation;
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy.calls.count()).toEqual(1);
expect(handleHorizontalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleVerticalAxisTwoViolationsSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisTwoViolationsSpy).not.toHaveBeenCalled();
});
it('and aligns content when Axis is HORIZONTAL and there are BOTTOM/LEFT ViewportViolations', function(this: TestContext) {
const bottomLeftViolation: ClrPopoverPosition = {
axis: ClrAxis.HORIZONTAL,
side: ClrSide.BEFORE,
anchor: ClrAlignment.END,
content: ClrAlignment.START,
};
popoverContent.style.height = window.innerHeight + 'px';
popoverContent.style.width = '25px';
this.positionService.position = bottomLeftViolation;
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleVerticalAxisTwoViolationsSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisTwoViolationsSpy.calls.count()).toEqual(1);
});
it('and aligns content when Axis is VERTICAL and there are BOTTOM/LEFT ViewportViolations', function(this: TestContext) {
const bottomLeftViolation: ClrPopoverPosition = {
axis: ClrAxis.VERTICAL,
side: ClrSide.AFTER,
anchor: ClrAlignment.START,
content: ClrAlignment.END,
};
popoverContent.style.width = '25px';
popoverContent.style.height = window.innerHeight + 'px';
this.positionService.position = bottomLeftViolation;
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleVerticalAxisTwoViolationsSpy.calls.count()).toEqual(1);
expect(handleHorizontalAxisTwoViolationsSpy).not.toHaveBeenCalled();
});
it('and aligns content when Axis is HORIZONTAL and there are BOTTOM/RIGHT ViewportViolations', function(this: TestContext) {
const bottomRightViolation: ClrPopoverPosition = {
axis: ClrAxis.HORIZONTAL,
side: ClrSide.AFTER,
anchor: ClrAlignment.END,
content: ClrAlignment.START,
};
popoverContent.style.height = window.innerHeight + 'px';
popoverContent.style.width = window.innerWidth + 'px';
this.positionService.position = bottomRightViolation;
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleVerticalAxisTwoViolationsSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisTwoViolationsSpy.calls.count()).toEqual(1);
});
});
it('and aligns content when visibility is 🆗', function(this: TestContext) {
const goodPosition: ClrPopoverPosition = {
anchor: ClrAlignment.END,
axis: ClrAxis.HORIZONTAL,
content: ClrAlignment.START,
side: ClrSide.AFTER,
};
this.positionService.position = goodPosition;
popoverContent.style.width = '25px';
popoverContent.style.height = '25px';
document.body.appendChild(popoverContent);
this.positionService.alignContent(popoverContent);
expect(handleVerticalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisOneViolationSpy).not.toHaveBeenCalled();
expect(handleVerticalAxisTwoViolationsSpy).not.toHaveBeenCalled();
expect(handleHorizontalAxisTwoViolationsSpy).not.toHaveBeenCalled();
});