Add a new placeholder option and deprecate undefinedHTML

This commit is contained in:
Tim Schaub
2021-07-09 15:52:17 -06:00
parent 8585b067dc
commit 53156ab936
4 changed files with 118 additions and 37 deletions

View File

@@ -61,7 +61,75 @@ describe('ol/control/MousePosition', function () {
document.querySelector('div.ol-viewport').dispatchEvent(evt);
}
describe('undefinedHTML', function () {
describe('placeholder', function () {
it('renders placeholder when mouse moves out', function () {
const ctrl = new MousePosition({
placeholder: 'some text',
});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('some text');
simulateEvent(EventType.POINTERMOVE, 20, 30);
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('some text');
});
it('renders the last posisition if placeholder is false and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({placeholder: false});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be(' ');
target.dispatchEvent(new PointerEvent('pointermove'));
simulateEvent(EventType.POINTERMOVE, 20, 30);
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('20,-30');
});
it('renders an empty space if placehodler is set to the same and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({
placeholder: '',
});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('');
target.dispatchEvent(new PointerEvent('pointermove'));
simulateEvent(EventType.POINTERMOVE, 20, 30);
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('');
});
});
describe('undefinedHTML (deprecated)', function () {
it('renders undefinedHTML when mouse moves out', function () {
const ctrl = new MousePosition({
undefinedHTML: 'some text',
@@ -105,30 +173,7 @@ describe('ol/control/MousePosition', function () {
expect(element.innerHTML).to.be(' ');
});
it('retains the mouse position when undefinedHTML is false and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({
undefinedHTML: false,
});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('');
target.dispatchEvent(new PointerEvent('pointermove'));
simulateEvent(EventType.POINTERMOVE, 20, 30);
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('20,-30');
});
it('renders an empty string if undefinedHTML is an empty string and mouse moves outside the viewport', function () {
it('retains the mouse position when undefinedHTML is falsey and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({
undefinedHTML: '',
});
@@ -148,7 +193,7 @@ describe('ol/control/MousePosition', function () {
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('');
expect(element.innerHTML).to.be('20,-30');
});
});
});