fix failing test

This commit is contained in:
Justin Ratner
2017-10-20 15:46:27 -06:00
parent d0bdbb861b
commit 089717cbd3
2 changed files with 26 additions and 5 deletions

View File

@@ -1896,6 +1896,9 @@ describe('TextEditorComponent', () => {
const decoration = editor.decorateMarker(marker, {type: 'overlay', item: overlayElement, class: 'a'})
await component.getNextUpdatePromise()
let overlayComponent
component.overlayComponents.forEach(c => overlayComponent = c)
const overlayWrapper = overlayElement.parentElement
expect(overlayWrapper.classList.contains('a')).toBe(true)
expect(overlayWrapper.getBoundingClientRect().top).toBe(clientTopForLine(component, 5))
@@ -1926,12 +1929,12 @@ describe('TextEditorComponent', () => {
await setScrollTop(component, 20)
expect(overlayWrapper.getBoundingClientRect().top).toBe(clientTopForLine(component, 5))
overlayElement.style.height = 60 + 'px'
await component.getNextUpdatePromise()
await overlayComponent.getNextUpdatePromise()
expect(overlayWrapper.getBoundingClientRect().bottom).toBe(clientTopForLine(component, 4))
// Does not flip the overlay vertically if it would overflow the top of the window
overlayElement.style.height = 80 + 'px'
await component.getNextUpdatePromise()
await overlayComponent.getNextUpdatePromise()
expect(overlayWrapper.getBoundingClientRect().top).toBe(clientTopForLine(component, 5))
// Can update overlay wrapper class

View File

@@ -806,9 +806,12 @@ class TextEditorComponent {
measuredDimensions: this.overlayDimensionsByElement.get(overlayProps.element),
didResize: (overlayComponent) => {
this.updateOverlayToRender(overlayProps)
overlayComponent.update({
measuredDimensions: this.overlayDimensionsByElement.get(overlayProps.element)
})
overlayComponent.update(Object.assign(
{
measuredDimensions: this.overlayDimensionsByElement.get(overlayProps.element)
},
overlayProps
))
}
},
overlayProps
@@ -4225,6 +4228,19 @@ class OverlayComponent {
this.didDetach()
}
getNextUpdatePromise () {
if (!this.nextUpdatePromise) {
this.nextUpdatePromise = new Promise((resolve) => {
this.resolveNextUpdatePromise = () => {
this.nextUpdatePromise = null
this.resolveNextUpdatePromise = null
resolve()
}
})
}
return this.nextUpdatePromise
}
update (newProps) {
const oldProps = this.props
this.props = Object.assign({}, oldProps, newProps)
@@ -4234,6 +4250,8 @@ class OverlayComponent {
if (oldProps.className != null) this.element.classList.remove(oldProps.className)
if (newProps.className != null) this.element.classList.add(newProps.className)
}
if (this.resolveNextUpdatePromise) this.resolveNextUpdatePromise()
}
didAttach () {