2015-04-04 22:17:22 +03:00
|
|
|
CustomGutterComponent = require '../src/custom-gutter-component'
|
|
|
|
Gutter = require '../src/gutter'
|
|
|
|
|
|
|
|
describe "CustomGutterComponent", ->
|
2015-04-19 05:00:02 +03:00
|
|
|
[gutterComponent, gutter] = []
|
2015-04-04 22:17:22 +03:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
mockGutterContainer = {}
|
|
|
|
gutter = new Gutter(mockGutterContainer, {name: 'test-gutter'})
|
2015-10-06 15:43:41 +03:00
|
|
|
gutterComponent = new CustomGutterComponent({gutter, views: atom.views})
|
2015-04-04 22:17:22 +03:00
|
|
|
|
|
|
|
it "creates a gutter DOM node with only an empty 'custom-decorations' child node when it is initialized", ->
|
2015-04-19 05:00:02 +03:00
|
|
|
expect(gutterComponent.getDomNode().classList.contains('gutter')).toBe true
|
|
|
|
expect(gutterComponent.getDomNode().getAttribute('gutter-name')).toBe 'test-gutter'
|
|
|
|
expect(gutterComponent.getDomNode().children.length).toBe 1
|
|
|
|
decorationsWrapperNode = gutterComponent.getDomNode().children.item(0)
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(decorationsWrapperNode.classList.contains('custom-decorations')).toBe true
|
|
|
|
|
|
|
|
it "makes its view accessible from the view registry", ->
|
2015-04-19 05:00:02 +03:00
|
|
|
expect(gutterComponent.getDomNode()).toBe atom.views.getView(gutter)
|
2015-04-04 22:17:22 +03:00
|
|
|
|
|
|
|
it "hides its DOM node when ::hideNode is called, and shows its DOM node when ::showNode is called", ->
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.hideNode()
|
|
|
|
expect(gutterComponent.getDomNode().style.display).toBe 'none'
|
|
|
|
gutterComponent.showNode()
|
|
|
|
expect(gutterComponent.getDomNode().style.display).toBe ''
|
2015-04-04 22:17:22 +03:00
|
|
|
|
|
|
|
describe "::updateSync", ->
|
|
|
|
decorationItem1 = document.createElement('div')
|
|
|
|
|
|
|
|
buildTestState = (customDecorations) ->
|
|
|
|
mockTestState =
|
2015-05-13 20:52:25 +03:00
|
|
|
content: if customDecorations then customDecorations else {}
|
|
|
|
styles:
|
2015-04-04 22:17:22 +03:00
|
|
|
scrollHeight: 100
|
|
|
|
scrollTop: 10
|
|
|
|
backgroundColor: 'black'
|
2015-05-13 20:52:25 +03:00
|
|
|
|
2015-04-04 22:17:22 +03:00
|
|
|
mockTestState
|
|
|
|
|
|
|
|
it "sets the custom-decoration wrapper's scrollHeight, scrollTop, and background color", ->
|
2015-04-19 05:00:02 +03:00
|
|
|
decorationsWrapperNode = gutterComponent.getDomNode().children.item(0)
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(decorationsWrapperNode.style.height).toBe ''
|
|
|
|
expect(decorationsWrapperNode.style['-webkit-transform']).toBe ''
|
|
|
|
expect(decorationsWrapperNode.style.backgroundColor).toBe ''
|
|
|
|
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.updateSync(buildTestState({}))
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(decorationsWrapperNode.style.height).not.toBe ''
|
|
|
|
expect(decorationsWrapperNode.style['-webkit-transform']).not.toBe ''
|
|
|
|
expect(decorationsWrapperNode.style.backgroundColor).not.toBe ''
|
|
|
|
|
|
|
|
it "creates a new DOM node for a new decoration and adds it to the gutter at the right place", ->
|
2015-05-13 20:52:25 +03:00
|
|
|
customDecorations =
|
2015-04-04 22:17:22 +03:00
|
|
|
'decoration-id-1':
|
|
|
|
top: 0
|
|
|
|
height: 10
|
|
|
|
item: decorationItem1
|
|
|
|
class: 'test-class-1'
|
|
|
|
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.updateSync(buildTestState(customDecorations))
|
|
|
|
decorationsWrapperNode = gutterComponent.getDomNode().children.item(0)
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(decorationsWrapperNode.children.length).toBe 1
|
|
|
|
|
|
|
|
decorationNode = decorationsWrapperNode.children.item(0)
|
|
|
|
expect(decorationNode.style.top).toBe '0px'
|
|
|
|
expect(decorationNode.style.height).toBe '10px'
|
|
|
|
expect(decorationNode.classList.contains('test-class-1')).toBe true
|
|
|
|
expect(decorationNode.classList.contains('decoration')).toBe true
|
|
|
|
expect(decorationNode.children.length).toBe 1
|
|
|
|
|
|
|
|
decorationItem = decorationNode.children.item(0)
|
|
|
|
expect(decorationItem).toBe decorationItem1
|
|
|
|
|
|
|
|
it "updates the existing DOM node for a decoration that existed but has new properties", ->
|
2015-05-13 20:52:25 +03:00
|
|
|
initialCustomDecorations =
|
2015-04-04 22:17:22 +03:00
|
|
|
'decoration-id-1':
|
|
|
|
top: 0
|
|
|
|
height: 10
|
|
|
|
item: decorationItem1
|
|
|
|
class: 'test-class-1'
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.updateSync(buildTestState(initialCustomDecorations))
|
|
|
|
initialDecorationNode = gutterComponent.getDomNode().children.item(0).children.item(0)
|
2015-04-04 22:17:22 +03:00
|
|
|
|
|
|
|
# Change the dimensions and item, remove the class.
|
|
|
|
decorationItem2 = document.createElement('div')
|
2015-05-13 20:52:25 +03:00
|
|
|
changedCustomDecorations =
|
2015-04-04 22:17:22 +03:00
|
|
|
'decoration-id-1':
|
|
|
|
top: 10
|
|
|
|
height: 20
|
|
|
|
item: decorationItem2
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.updateSync(buildTestState(changedCustomDecorations))
|
|
|
|
changedDecorationNode = gutterComponent.getDomNode().children.item(0).children.item(0)
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(changedDecorationNode).toBe initialDecorationNode
|
|
|
|
expect(changedDecorationNode.style.top).toBe '10px'
|
|
|
|
expect(changedDecorationNode.style.height).toBe '20px'
|
|
|
|
expect(changedDecorationNode.classList.contains('test-class-1')).toBe false
|
|
|
|
expect(changedDecorationNode.classList.contains('decoration')).toBe true
|
|
|
|
expect(changedDecorationNode.children.length).toBe 1
|
|
|
|
decorationItem = changedDecorationNode.children.item(0)
|
|
|
|
expect(decorationItem).toBe decorationItem2
|
|
|
|
|
|
|
|
# Remove the item, add a class.
|
2015-05-13 20:52:25 +03:00
|
|
|
changedCustomDecorations =
|
2015-04-04 22:17:22 +03:00
|
|
|
'decoration-id-1':
|
|
|
|
top: 10
|
|
|
|
height: 20
|
|
|
|
class: 'test-class-2'
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.updateSync(buildTestState(changedCustomDecorations))
|
|
|
|
changedDecorationNode = gutterComponent.getDomNode().children.item(0).children.item(0)
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(changedDecorationNode).toBe initialDecorationNode
|
|
|
|
expect(changedDecorationNode.style.top).toBe '10px'
|
|
|
|
expect(changedDecorationNode.style.height).toBe '20px'
|
|
|
|
expect(changedDecorationNode.classList.contains('test-class-2')).toBe true
|
|
|
|
expect(changedDecorationNode.classList.contains('decoration')).toBe true
|
|
|
|
expect(changedDecorationNode.children.length).toBe 0
|
|
|
|
|
|
|
|
it "removes any decorations that existed previously but aren't in the latest update", ->
|
2015-05-13 20:52:25 +03:00
|
|
|
customDecorations =
|
2015-04-04 22:17:22 +03:00
|
|
|
'decoration-id-1':
|
|
|
|
top: 0
|
|
|
|
height: 10
|
|
|
|
class: 'test-class-1'
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.updateSync(buildTestState(customDecorations))
|
|
|
|
decorationsWrapperNode = gutterComponent.getDomNode().children.item(0)
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(decorationsWrapperNode.children.length).toBe 1
|
|
|
|
|
2015-05-13 20:52:25 +03:00
|
|
|
emptyCustomDecorations = {}
|
2015-04-19 05:00:02 +03:00
|
|
|
gutterComponent.updateSync(buildTestState(emptyCustomDecorations))
|
2015-04-04 22:17:22 +03:00
|
|
|
expect(decorationsWrapperNode.children.length).toBe 0
|