-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2240 from exadel-inc/refactor/esl-popup-position
ESL Popup position: tests and refactoring
- Loading branch information
Showing
8 changed files
with
688 additions
and
89 deletions.
There are no files selected for viewing
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
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
94 changes: 94 additions & 0 deletions
94
src/modules/esl-popup/test/esl-popup-position.behaviour-fit-major.test.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,94 @@ | ||
import {calcPopupPosition} from '../core/esl-popup-position'; | ||
import {Rect} from '../../esl-utils/dom'; | ||
|
||
import type {PopupPositionConfig, PopupPositionValue} from '../core/esl-popup-position'; | ||
|
||
describe('ESLPopup position: calcPopupPosition(): behavior set to fit-major', () => { | ||
const arrow = new Rect(0, 0, 30, 30); | ||
const popup = new Rect(0, 0, 300, 200); | ||
const trigger = new Rect(500, 500, 20, 20); | ||
const container = new Rect(0, 0, 1000, 1000); | ||
const intersectionRatio = {top: 0, left: 0, right: 0, bottom: 0}; | ||
const cfgRef = { | ||
behavior: 'fit-major', | ||
position: 'top', | ||
marginArrow: 7, | ||
offsetArrowRatio: 0, | ||
intersectionRatio, | ||
arrow, | ||
element: popup, | ||
inner: trigger.grow(10), | ||
outer: container, | ||
trigger | ||
} as PopupPositionConfig; | ||
|
||
const expectedRef = { | ||
arrow: {x: 7, y: 7}, | ||
placedAt: 'top', | ||
popup | ||
}; | ||
|
||
describe('should flip to the opposite position:', () => { | ||
test('when there is a lack of space at the top', () => { | ||
const cfg = {...cfgRef, position: 'top', outer: container.shift(0, 400)} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(488, 530); | ||
expected.placedAt = 'bottom'; | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
|
||
test('when there is a lack of space at the left', () => { | ||
const cfg = {...cfgRef, position: 'left', outer: container.shift(400, 0)} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(530, 488); | ||
expected.placedAt = 'right'; | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
|
||
test('when there is a lack of space at the bottom', () => { | ||
const cfg = {...cfgRef, position: 'bottom', outer: container.shift(0, -400)} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(488, 290); | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
|
||
test('when there is a lack of space at the right', () => { | ||
const cfg = {...cfgRef, position: 'right', outer: container.shift(-400, 0)} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(190, 488); | ||
expected.placedAt = 'left'; | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
|
||
test('when the activator is crossing the top edge of the container', () => { | ||
const cfg = {...cfgRef, position: 'top', intersectionRatio: {top: 0.5, left: 0, right: 0, bottom: 0}} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(488, 530); | ||
expected.placedAt = 'bottom'; | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
|
||
test('when the activator is crossing the left edge of the container', () => { | ||
const cfg = {...cfgRef, position: 'left', intersectionRatio: {top: 0, left: 0.5, right: 0, bottom: 0}} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(530, 488); | ||
expected.placedAt = 'right'; | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
|
||
test('when the activator is crossing the bottom edge of the container', () => { | ||
const cfg = {...cfgRef, position: 'bottom', intersectionRatio: {top: 0, left: 0, right: 0, bottom: 0.5}} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(488, 290); | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
|
||
test('when the activator is crossing the right edge of the container', () => { | ||
const cfg = {...cfgRef, position: 'right', intersectionRatio: {top: 0, left: 0, right: 0.5, bottom: 0}} as PopupPositionConfig; | ||
const expected = Object.assign({}, expectedRef) as PopupPositionValue; | ||
expected.popup = popup.shift(190, 488); | ||
expected.placedAt = 'left'; | ||
expect(calcPopupPosition(cfg)).toEqual(expected); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.