ldx-widgets
Version:
widgets
414 lines (302 loc) • 12.3 kB
text/coffeescript
describe 'PVR', ->
React = require 'react'
PVR = React.createFactory require('../../src/components/pvr')
_ = require 'lodash'
TestUtils = require 'react-addons-test-utils'
ReactDOM = require 'react-dom'
#--------------------------------------------------------------------- Default Props
it 'Should have default props', ->
pvr = TestUtils.renderIntoDocument PVR {}
defaultProps = pvr.props
expect(defaultProps.height).to.equal(100)
expect(defaultProps.width).to.equal(200)
expect(defaultProps.styleMixin).to.be.a('object')
expect(defaultProps.Adjust).to.equal(0)
expect(defaultProps.hAdjust).to.equal(0)
expect(defaultProps.hSlide).to.equal(0)
expect(defaultProps.anchor).to.be.a('object')
expect(defaultProps.element).to.equal(null)
expect(defaultProps.direction).to.equal('auto')
expect(defaultProps.nibColor).to.equal('auto')
expect(defaultProps.borderColor).to.equal('rgb(235,235,235)')
expect(defaultProps.updateOnKeys).to.be.a('array')
expect(defaultProps.closeOnAnchorLeave).to.equal(yes)
#--------------------------------------------------------------------- Click handling
it 'Should stop propagation when onClick of pvr is called', ->
pvr = TestUtils.renderIntoDocument PVR {}
el = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
e =
stopPropagation: sinon.spy()
TestUtils.Simulate.click el, e
expect(e.stopPropagation.called).to.equal(true)
#--------------------------------------------------------------------- Position No Direction
#--------------------------------------------------------------------- expects window size 300 X 400
it 'Should have class of below if no direction is set and there is room for the menu on the bottom', ->
pvr = TestUtils.renderIntoDocument PVR {
anchor: {
getBoundingClientRect: ->
top: 10
bottom: 20
left: 10
right: 10
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('below')
it 'Should have class of above if no direction is set, there is no room on the bottom and there is room for the menu on the top', ->
pvr = TestUtils.renderIntoDocument PVR {
anchor: {
getBoundingClientRect: ->
top: 300
bottom: 350
left: 10
right: 10
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('above')
it 'Should have class of right if no direction is set, there is no room on the bottom, no room on the top and there is room for the menu on the right', ->
pvr = TestUtils.renderIntoDocument PVR {
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 100
right: 200
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('right')
it 'Should have class of left if no direction is set, there is no room on the bottom, no room on the top, no room on right and there is room for the menu on the left', ->
pvr = TestUtils.renderIntoDocument PVR {
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 400
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('left')
it 'Should have class of below if no direction is set and default positions are set', ->
pvr = TestUtils.renderIntoDocument PVR {}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('below')
#--------------------------------------------------------------------- Position with Direction Above
#--------------------------------------------------------------------- expects window size 300 X 400
it 'Should have class of above if direction is set to above and there is room for the menu above ', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'above'
anchor: {
getBoundingClientRect: ->
top: 300
bottom: 350
left: 10
right: 10
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('above')
it 'Should have class of below if direction is set to above, there is no room above and there is room for the menu below', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'above'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 55
left: 50
right: 200
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('below')
it 'Should have class of right if direction is set to above, there is no room above, no room below and there is room for the menu to the right', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'above'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 100
right: 200
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('right')
it 'Should have class of left if direction is set to above, there is no room above, no room below, no room to the right and there is room for the menu to the left', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'above'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 400
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('left')
#--------------------------------------------------------------------- Position with Direction Right
#--------------------------------------------------------------------- expects window size 300 X 400
it 'Should have class of right if the direction is set to the right and there is room for the menu to the right', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'right'
anchor: {
getBoundingClientRect: ->
top: 300
bottom: 350
left: 10
right: 10
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('right')
it 'Should have class of left if the direction is set to right, there is no room to the right and there is room for the menu to the left', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'right'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 400
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('left')
it 'Should have class of below if the direction is set to right, there is no room to the right, no room to the left and there is room for the menu below', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'right'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 55
left: 100
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('below')
it 'Should have class of above if the direction is set to right, there is no room to right, no room to the left, no room below and there is room for the menu above', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'right'
anchor: {
getBoundingClientRect: ->
top: 150
bottom: 355
left: 50
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('above')
#--------------------------------------------------------------------- Position with Direction Right
#--------------------------------------------------------------------- expects window size 300 X 400
it 'Should have class of left if direction is set to left and there is room for the menu to the left', ->
pvr = TestUtils.renderIntoDocument PVR {
width: 20
direction: 'left'
anchor: {
getBoundingClientRect: ->
top: 200
bottom: 250
left: 210
right: 250
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('left')
it 'Should have class of right if direction is set to left, there is no room to the left and there is room for the menu to the right', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'left'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 40
right: 50
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('right')
it 'Should have class of below if direction is set to left, there is no room to the right, no room to the left and there is room for the menu to below', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'left'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 55
left: 100
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('below')
it 'Should have class of above if direction is set to left, there is no room to the right, no room to the left, no room below and there is room for the menu to above', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'left'
anchor: {
getBoundingClientRect: ->
top: 150
bottom: 355
left: 50
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('above')
#--------------------------------------------------------------------- Position with Direction Above
#--------------------------------------------------------------------- expects window size 300 X 400
it 'Should have class of below if direction is set to below and there is room for the menu below', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'below'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 55
left: 10
right: 10
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('below')
it 'Should have class of above if direction is set to below, there is no room below and there is room for the menu above', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'below'
anchor: {
getBoundingClientRect: ->
top: 250
bottom: 300
left: 50
right: 200
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('above')
it 'Should have class of right if direction is set to below, there is no room above, no room below and there is room for the menu to the right', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'below'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 100
right: 200
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('right')
it 'Should have class of left if direction is set to below, there is no room above, no room below, no room to the right and there is room for the menu to the left', ->
pvr = TestUtils.renderIntoDocument PVR {
direction: 'below'
anchor: {
getBoundingClientRect: ->
top: 50
bottom: 200
left: 400
right: 500
}
}
pvrMenu = TestUtils.findRenderedDOMComponentWithClass pvr, 'pvr'
expect(pvrMenu.className).to.contain('left')