mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add specs from the text-editor-component
This commit is contained in:
@@ -1488,11 +1488,11 @@ describe "TextEditorPresenter", ->
|
||||
}
|
||||
|
||||
describe ".overlays", ->
|
||||
[item] = []
|
||||
stateForOverlay = (presenter, decoration) ->
|
||||
presenter.getState().content.overlays[decoration.id]
|
||||
|
||||
it "contains state for overlay decorations both initially and when their markers move", ->
|
||||
item = {}
|
||||
marker = editor.markBufferPosition([2, 13], invalidate: 'touch')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
presenter = buildPresenter(explicitHeight: 30, scrollTop: 20)
|
||||
@@ -1540,7 +1540,6 @@ describe "TextEditorPresenter", ->
|
||||
}
|
||||
|
||||
it "updates when ::baseCharacterWidth changes", ->
|
||||
item = {}
|
||||
scrollTop = 20
|
||||
marker = editor.markBufferPosition([2, 13], invalidate: 'touch')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
@@ -1559,7 +1558,6 @@ describe "TextEditorPresenter", ->
|
||||
}
|
||||
|
||||
it "updates when ::lineHeight changes", ->
|
||||
item = {}
|
||||
scrollTop = 20
|
||||
marker = editor.markBufferPosition([2, 13], invalidate: 'touch')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
@@ -1578,7 +1576,6 @@ describe "TextEditorPresenter", ->
|
||||
}
|
||||
|
||||
it "honors the 'position' option on overlay decorations", ->
|
||||
item = {}
|
||||
scrollTop = 20
|
||||
marker = editor.markBufferRange([[2, 13], [4, 14]], invalidate: 'touch')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', position: 'tail', item})
|
||||
@@ -1589,7 +1586,6 @@ describe "TextEditorPresenter", ->
|
||||
}
|
||||
|
||||
it "is empty until all of the required measurements are assigned", ->
|
||||
item = {}
|
||||
marker = editor.markBufferRange([[2, 13], [4, 14]], invalidate: 'touch')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', position: 'tail', item})
|
||||
|
||||
@@ -1608,6 +1604,169 @@ describe "TextEditorPresenter", ->
|
||||
presenter.setBoundingClientRect({top: 0, left: 0, height: 100, width: 500})
|
||||
expect(presenter.getState().content.overlays).not.toEqual({})
|
||||
|
||||
describe "when the overlay has been measured", ->
|
||||
[gutterWidth, windowWidth, windowHeight, itemWidth, itemHeight, contentMargin, boundingClientRect, contentFrameWidth] = []
|
||||
beforeEach ->
|
||||
item = {}
|
||||
gutterWidth = 5 * 10 # 5 chars wide
|
||||
contentFrameWidth = 30 * 10
|
||||
windowWidth = gutterWidth + contentFrameWidth
|
||||
windowHeight = 9 * 10
|
||||
|
||||
itemWidth = 4 * 10
|
||||
itemHeight = 4 * 10
|
||||
contentMargin = 0
|
||||
|
||||
boundingClientRect =
|
||||
top: 0
|
||||
left: 0,
|
||||
width: windowWidth
|
||||
height: windowHeight
|
||||
|
||||
it "slides horizontally left when near the right edge", ->
|
||||
scrollLeft = 20
|
||||
marker = editor.markBufferPosition([0, 26], invalidate: 'never')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
|
||||
presenter = buildPresenter({scrollLeft, windowWidth, windowHeight, contentFrameWidth, boundingClientRect})
|
||||
expectStateUpdate presenter, ->
|
||||
presenter.setOverlayDimensions(decoration.id, itemWidth, itemHeight, contentMargin)
|
||||
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 1 * 10, left: 26 * 10 + gutterWidth - scrollLeft}
|
||||
}
|
||||
|
||||
expectStateUpdate presenter, -> editor.insertText('a')
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 1 * 10, left: windowWidth - itemWidth}
|
||||
}
|
||||
|
||||
expectStateUpdate presenter, -> editor.insertText('b')
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 1 * 10, left: windowWidth - itemWidth}
|
||||
}
|
||||
|
||||
it "flips vertically when near the bottom edge", ->
|
||||
scrollTop = 10
|
||||
marker = editor.markBufferPosition([5, 0], invalidate: 'never')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
|
||||
presenter = buildPresenter({scrollTop, windowWidth, windowHeight, contentFrameWidth, boundingClientRect})
|
||||
expectStateUpdate presenter, ->
|
||||
presenter.setOverlayDimensions(decoration.id, itemWidth, itemHeight, contentMargin)
|
||||
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 6 * 10 - scrollTop, left: gutterWidth}
|
||||
}
|
||||
|
||||
expectStateUpdate presenter, ->
|
||||
editor.insertNewline()
|
||||
editor.setScrollTop(scrollTop) # I'm fighting the editor
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 6 * 10 - scrollTop - itemHeight, left: gutterWidth}
|
||||
}
|
||||
|
||||
describe "when the overlay item has a margin", ->
|
||||
beforeEach ->
|
||||
itemWidth = 12 * 10
|
||||
contentMargin = -(gutterWidth + 2 * 10)
|
||||
|
||||
it "slides horizontally right when near the left edge with margin", ->
|
||||
editor.setCursorBufferPosition([0, 3])
|
||||
cursor = editor.getLastCursor()
|
||||
marker = cursor.marker
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
|
||||
presenter = buildPresenter({windowWidth, windowHeight, contentFrameWidth, boundingClientRect})
|
||||
expectStateUpdate presenter, ->
|
||||
presenter.setOverlayDimensions(decoration.id, itemWidth, itemHeight, contentMargin)
|
||||
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 1 * 10, left: 3 * 10 + gutterWidth}
|
||||
}
|
||||
|
||||
expectStateUpdate presenter, -> cursor.moveLeft()
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 1 * 10, left: -contentMargin}
|
||||
}
|
||||
|
||||
expectStateUpdate presenter, -> cursor.moveLeft()
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 1 * 10, left: -contentMargin}
|
||||
}
|
||||
|
||||
describe "when the editor is very small", ->
|
||||
beforeEach ->
|
||||
windowWidth = gutterWidth + 6 * 10
|
||||
windowHeight = 6 * 10
|
||||
contentFrameWidth = windowWidth - gutterWidth
|
||||
boundingClientRect.width = windowWidth
|
||||
boundingClientRect.height = windowHeight
|
||||
|
||||
it "does not flip vertically and force the overlay to have a negative top", ->
|
||||
marker = editor.markBufferPosition([1, 0], invalidate: 'never')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
|
||||
presenter = buildPresenter({windowWidth, windowHeight, contentFrameWidth, boundingClientRect})
|
||||
expectStateUpdate presenter, ->
|
||||
presenter.setOverlayDimensions(decoration.id, itemWidth, itemHeight, contentMargin)
|
||||
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 2 * 10, left: 0 * 10 + gutterWidth}
|
||||
}
|
||||
|
||||
expectStateUpdate presenter, -> editor.insertNewline()
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 3 * 10, left: gutterWidth}
|
||||
}
|
||||
|
||||
it "does not adjust horizontally and force the overlay to have a negative left", ->
|
||||
itemWidth = 6 * 10
|
||||
|
||||
marker = editor.markBufferPosition([0, 0], invalidate: 'never')
|
||||
decoration = editor.decorateMarker(marker, {type: 'overlay', item})
|
||||
|
||||
presenter = buildPresenter({windowWidth, windowHeight, contentFrameWidth, boundingClientRect})
|
||||
expectStateUpdate presenter, ->
|
||||
presenter.setOverlayDimensions(decoration.id, itemWidth, itemHeight, contentMargin)
|
||||
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 10, left: gutterWidth}
|
||||
}
|
||||
|
||||
windowWidth = gutterWidth + 5 * 10
|
||||
expectStateUpdate presenter, -> presenter.setWindowSize(windowWidth, windowHeight)
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 10, left: windowWidth - itemWidth}
|
||||
}
|
||||
|
||||
windowWidth = gutterWidth + 1 * 10
|
||||
expectStateUpdate presenter, -> presenter.setWindowSize(windowWidth, windowHeight)
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 10, left: 0}
|
||||
}
|
||||
|
||||
windowWidth = gutterWidth
|
||||
expectStateUpdate presenter, -> presenter.setWindowSize(windowWidth, windowHeight)
|
||||
expectValues stateForOverlay(presenter, decoration), {
|
||||
item: item
|
||||
pixelPosition: {top: 10, left: 0}
|
||||
}
|
||||
|
||||
|
||||
describe ".gutter", ->
|
||||
describe ".scrollHeight", ->
|
||||
it "is initialized based on ::lineHeight, the number of lines, and ::explicitHeight", ->
|
||||
|
||||
Reference in New Issue
Block a user