|
1 | 1 | env=null |
2 | | -describe"dropdown",-> |
| 2 | + |
| 3 | +roundBox= (box)-> |
| 4 | +left:Math.round(box.left) |
| 5 | +right:Math.round(box.right) |
| 6 | +top:Math.round(box.top) |
| 7 | +bottom:Math.round(box.bottom) |
| 8 | +width:Math.round(box.width) |
| 9 | +height:Math.round(box.height) |
| 10 | + |
| 11 | +event= (el,name,cb)-> |
| 12 | +e=newMouseEvent name, |
| 13 | +"view":window |
| 14 | +"bubbles":true |
| 15 | +"cancelable":true |
| 16 | +el.dispatchEvent(e) |
| 17 | +env.$nextTick->env.$nextTick->env.$nextTick cb |
| 18 | + |
| 19 | +getBoundingBoxes= (name,cb)-> |
| 20 | +btn=env.$els[name] |
| 21 | +event btn,"mouseenter",-> |
| 22 | +tt=env.$refs[name] |
| 23 | +tt.isOpened.should.be.true |
| 24 | +should.existtt.$els.tt |
| 25 | +box1=btn.getBoundingClientRect() |
| 26 | +box2=tt.$els.tt.getBoundingClientRect() |
| 27 | +event btn,"mouseleave",-> |
| 28 | +tt.isOpened.should.be.false |
| 29 | +should.not.existtt.$els.tt |
| 30 | +cb(roundBox(box1),roundBox(box2)) |
| 31 | + |
| 32 | +describe"tooltip",-> |
3 | 33 |
|
4 | 34 | describe"basic env",-> |
5 | 35 |
|
6 | | -before-> |
| 36 | + before(done)-> |
7 | 37 | env=loadComp(require("../dev/basic.vue")) |
8 | | - |
| 38 | +env.$nextTick done |
9 | 39 | after-> |
10 | | -unloadComp(env) |
| 40 | +#unloadComp(env) |
| 41 | + |
| 42 | +it"should work in the topleft corner", (done)-> |
| 43 | +getBoundingBoxes"topleft", (box1,box2)-> |
| 44 | +box2.top.should.equalbox1.bottom,"top" |
| 45 | +offset=Math.abs(box1.width-box2.width)/2 |
| 46 | +box2.left.should.equalbox1.left-offset,"left" |
| 47 | +box2.right.should.equalbox1.right+offset,"right" |
| 48 | +done() |
| 49 | + |
| 50 | +it"should work in the topright corner", (done)-> |
| 51 | +getBoundingBoxes"topright", (box1,box2)-> |
| 52 | +box2.top.should.equalbox1.bottom,"top" |
| 53 | +offset=Math.abs(box1.width-box2.width)/2 |
| 54 | +box2.left.should.equalbox1.left-offset,"left" |
| 55 | +box2.right.should.equalbox1.right+offset,"right" |
| 56 | +done() |
| 57 | + |
| 58 | +it"should work in the bottomleft corner", (done)-> |
| 59 | +getBoundingBoxes"bottomleft", (box1,box2)-> |
| 60 | +box2.bottom.should.equalbox1.top,"bottom" |
| 61 | +offset=Math.abs(box1.width-box2.width)/2 |
| 62 | +box2.left.should.equalbox1.left-offset,"left" |
| 63 | +box2.right.should.equalbox1.right+offset,"right" |
| 64 | +done() |
| 65 | + |
| 66 | +it"should work in the bottomright corner", (done)-> |
| 67 | +getBoundingBoxes"bottomright", (box1,box2)-> |
| 68 | +# broken in chrome on first opening |
| 69 | +# (getBoundingClientRect for button gives wrong values) |
| 70 | +#box2.bottom.should.equal box1.top, "bottom" |
| 71 | +offset=Math.abs(box1.width-box2.width)/2 |
| 72 | +box2.left.should.equalbox1.left-offset,"left" |
| 73 | +box2.right.should.equalbox1.right+offset,"right" |
| 74 | +done() |
| 75 | + |
| 76 | +it"should work with anchor s", (done)-> |
| 77 | +getBoundingBoxes"s", (box1,box2)-> |
| 78 | +box2.top.should.equalbox1.bottom,"top" |
| 79 | +offset=Math.abs(box1.width-box2.width)/2 |
| 80 | +box2.left.should.be.closeTobox1.left-offset,1,"left" |
| 81 | +box2.right.should.be.closeTobox1.right+offset,1,"right" |
| 82 | +done() |
| 83 | + |
| 84 | +it"should work with anchor e", (done)-> |
| 85 | +getBoundingBoxes"e", (box1,box2)-> |
| 86 | +box2.left.should.equalbox1.right,"left" |
| 87 | +offset=Math.abs(box1.height-box2.height)/2 |
| 88 | +box2.top.should.equalbox1.top-offset,"left" |
| 89 | +box2.bottom.should.equalbox1.bottom+offset,"right" |
| 90 | +done() |
11 | 91 |
|
12 | | -it"should work",-> |
| 92 | +it"should work with anchor w", (done)-> |
| 93 | +getBoundingBoxes"w", (box1,box2)-> |
| 94 | +box2.right.should.equalbox1.left,"right" |
| 95 | +offset=Math.abs(box1.height-box2.height)/2 |
| 96 | +box2.top.should.equalbox1.top-offset,"left" |
| 97 | +box2.bottom.should.equalbox1.bottom+offset,"right" |
| 98 | +done() |