Files
atom/spec/editor-component-spec.coffee
Nathan Sobo a134a60ce8 Render the entire editor with React. Handle vertical scrolling.
The space-pen view is now a simple wrapper around the entire React
component to integrate it cleanly into our existing system. React
components can't adopt existing DOM nodes, otherwise I would just have
the react component take over the entire view instead of wrapping.
2014-04-22 17:09:02 -06:00

40 lines
1.4 KiB
CoffeeScript

{React} = require 'reactionary'
EditorComponent = require '../src/editor-component'
describe "EditorComponent", ->
[editor, component, node, lineHeight] = []
beforeEach ->
editor = atom.project.openSync('sample.js')
container = document.querySelector('#jasmine-content')
component = React.renderComponent(EditorComponent({editor}), container)
node = component.getDOMNode()
fontSize = 20
lineHeight = 1.3 * fontSize
node.style.lineHeight = 1.3
node.style.fontSize = fontSize + 'px'
it "renders only the currently-visible lines", ->
node.style.height = 4.5 * lineHeight + 'px'
component.updateAllDimensions()
lines = node.querySelectorAll('.line')
expect(lines.length).toBe 5
expect(lines[0].textContent).toBe editor.lineForScreenRow(0).text
expect(lines[4].textContent).toBe editor.lineForScreenRow(4).text
node.querySelector('.vertical-scrollbar').scrollTop = 2.5 * lineHeight
component.onVerticalScroll()
expect(node.querySelector('.lines').offsetTop).toBe -2.5 * lineHeight
lines = node.querySelectorAll('.line')
expect(lines.length).toBe 5
expect(lines[0].textContent).toBe editor.lineForScreenRow(2).text
expect(lines[4].textContent).toBe editor.lineForScreenRow(6).text
spacers = node.querySelectorAll('.spacer')
expect(spacers[0].offsetHeight).toBe 2 * lineHeight
expect(spacers[1].offsetHeight).toBe (editor.getScreenLineCount() - 7) * lineHeight