123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import {
- getOrientation,
- getMid
- } from 'lib/layout/LayoutUtil';
- function rect(x, y, width, height) {
- return { x: x, y: y, width: width, height: height };
- }
- describe('layout/LayoutUtil', function() {
- describe('#getMid', function() {
- it('should return rectangle mid point', function() {
- // given
- var r = rect(100, 100, 100, 200);
- // then
- expect(getMid(r)).to.eql({ x: 150, y: 200 });
- });
- it('should return point mid point', function() {
- // given
- var point = { x: 100, y: 100 };
- // then
- expect(getMid(point)).to.eql(point);
- });
- });
- describe('#getOrientation', function() {
- // a rectangle 100,100 -> 200,200
- var a = rect(100, 100, 100, 100);
- it('should detect top', function() {
- // given
- var b = rect(100, 0, 100, 100);
- expect(getOrientation(b, a)).to.equal('top');
- });
- it('should detect top-right', function() {
- // given
- var b = rect(200, 0, 100, 100);
- expect(getOrientation(b, a)).to.equal('top-right');
- });
- it('should detect right', function() {
- // given
- var b = rect(200, 100, 100, 100);
- expect(getOrientation(b, a)).to.equal('right');
- });
- it('should detect bottom-right', function() {
- // given
- var b = rect(200, 200, 100, 100);
- expect(getOrientation(b, a)).to.equal('bottom-right');
- });
- it('should detect bottom', function() {
- // given
- var b = rect(100, 200, 100, 100);
- expect(getOrientation(b, a)).to.equal('bottom');
- });
- it('should detect bottom-left', function() {
- // given
- var b = rect(0, 200, 100, 100);
- expect(getOrientation(b, a)).to.equal('bottom-left');
- });
- it('should detect left', function() {
- // given
- var b = rect(0, 100, 100, 100);
- expect(getOrientation(b, a)).to.equal('left');
- });
- it('should detect top-left', function() {
- // given
- var b = rect(0, 0, 100, 100);
- expect(getOrientation(b, a)).to.equal('top-left');
- });
- it('should detect intersect', function() {
- // given
- var b = rect(120, 120, 100, 100);
- expect(getOrientation(b, a)).to.equal('intersect');
- });
- });
- });
|