2014-10-17 04:32:24 +04:00
|
|
|
Panel = require '../src/panel'
|
|
|
|
PanelElement = require '../src/panel-element'
|
|
|
|
|
|
|
|
describe "PanelElement", ->
|
2014-12-01 00:47:51 +03:00
|
|
|
[jasmineContent, element, panel] = []
|
2014-10-17 04:32:24 +04:00
|
|
|
|
|
|
|
class TestPanelItem
|
|
|
|
constructior: ->
|
|
|
|
|
|
|
|
class TestPanelItemElement extends HTMLElement
|
|
|
|
createdCallback: ->
|
|
|
|
@classList.add('test-root')
|
2014-12-02 04:17:13 +03:00
|
|
|
initialize: (@model) ->
|
|
|
|
this
|
|
|
|
|
2014-10-17 04:32:24 +04:00
|
|
|
TestPanelItemElement = document.registerElement 'atom-test-item-element', prototype: TestPanelItemElement.prototype
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
jasmineContent = document.body.querySelector('#jasmine-content')
|
|
|
|
|
2015-10-05 12:50:33 +03:00
|
|
|
atom.views.addViewProvider Panel, (model, env) ->
|
|
|
|
new PanelElement().initialize(model, env)
|
2014-12-02 04:53:03 +03:00
|
|
|
atom.views.addViewProvider TestPanelItem, (model) ->
|
|
|
|
new TestPanelItemElement().initialize(model)
|
2014-10-17 04:32:24 +04:00
|
|
|
|
|
|
|
it 'removes the element when the panel is destroyed', ->
|
2014-12-01 00:47:51 +03:00
|
|
|
panel = new Panel({item: new TestPanelItem})
|
|
|
|
element = atom.views.getView(panel)
|
2014-10-17 04:32:24 +04:00
|
|
|
jasmineContent.appendChild(element)
|
|
|
|
|
|
|
|
expect(element.parentNode).toBe jasmineContent
|
|
|
|
panel.destroy()
|
|
|
|
expect(element.parentNode).not.toBe jasmineContent
|
|
|
|
|
|
|
|
describe "changing panel visibility", ->
|
|
|
|
it 'initially renders panel created with visibile: false', ->
|
2014-12-01 00:47:51 +03:00
|
|
|
panel = new Panel({visible: false, item: new TestPanelItem})
|
|
|
|
element = atom.views.getView(panel)
|
2014-10-17 04:32:24 +04:00
|
|
|
jasmineContent.appendChild(element)
|
|
|
|
|
2014-10-20 23:12:21 +04:00
|
|
|
expect(element.style.display).toBe 'none'
|
2014-10-17 04:32:24 +04:00
|
|
|
|
|
|
|
it 'hides and shows the panel element when Panel::hide() and Panel::show() are called', ->
|
2014-12-01 00:47:51 +03:00
|
|
|
panel = new Panel({item: new TestPanelItem})
|
|
|
|
element = atom.views.getView(panel)
|
2014-10-17 04:32:24 +04:00
|
|
|
jasmineContent.appendChild(element)
|
|
|
|
|
2014-10-20 23:12:21 +04:00
|
|
|
expect(element.style.display).not.toBe 'none'
|
2014-10-17 04:32:24 +04:00
|
|
|
|
|
|
|
panel.hide()
|
2014-10-20 23:12:21 +04:00
|
|
|
expect(element.style.display).toBe 'none'
|
2014-10-17 04:32:24 +04:00
|
|
|
|
|
|
|
panel.show()
|
2014-10-20 23:12:21 +04:00
|
|
|
expect(element.style.display).not.toBe 'none'
|
2014-11-04 22:43:51 +03:00
|
|
|
|
|
|
|
describe "when a class name is specified", ->
|
|
|
|
it 'initially renders panel created with visibile: false', ->
|
2014-12-01 00:47:51 +03:00
|
|
|
panel = new Panel({className: 'some classes', item: new TestPanelItem})
|
|
|
|
element = atom.views.getView(panel)
|
2014-11-04 22:43:51 +03:00
|
|
|
jasmineContent.appendChild(element)
|
|
|
|
|
|
|
|
expect(element).toHaveClass 'some'
|
|
|
|
expect(element).toHaveClass 'classes'
|