UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

104 lines (103 loc) 4.87 kB
import React from 'react'; import assert from 'assert'; import { common } from '../../util/generic-tests'; import { shallow } from 'enzyme'; import Point from './Point'; describe('Point', function () { common(Point); describe('props', function () { describe('x', function () { it('should transform accordingly', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { x: 10 })); assert.equal(wrapper.find('path').prop('transform'), 'translate(4, -6) scale(1)'); }); }); describe('y', function () { it('should transform accordingly', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { y: 100 })); assert.equal(wrapper.find('path').prop('transform'), 'translate(-6, 94) scale(1)'); }); }); describe('kind', function () { it('should have the correct path and transform for type 0', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { kind: 0 })); assert.equal(wrapper.find('path').prop('d'), 'M6,12 C2.686,12 0,9.314 0,6 C0,2.686 2.686,0 6,0 C9.314,-0 12,2.686 12,6 C12,9.314 9.314,12 6,12 z'); assert.equal(wrapper.find('path').prop('transform'), 'translate(-6, -6) scale(1)'); }); it('should have the correct path and transform for type 1', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { kind: 1 })); assert.equal(wrapper.find('path').prop('d'), 'M6,12 C0,12 0,12 0,6 C0,0 -0,0 6,0 C12,0 12,0 12,6 C12,12 12,12 6,12 z'); assert.equal(wrapper.find('path').prop('transform'), 'translate(-6, -6) scale(1)'); }); it('should have the correct path and transform for type 2', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { kind: 2 })); assert.equal(wrapper.find('path').prop('d'), 'M6.034,1.656 C7,0 7,0 7.966,1.656 L13.034,10.344 C14,12 13,12 12,12 L2,12 C1,12 0,12 0.966,10.344 L6.034,1.656 z'); assert.equal(wrapper.find('path').prop('transform'), 'translate(-7, -6) scale(1)'); }); it('should have the correct path and transform for type 3', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { kind: 3 })); assert.equal(wrapper.find('path').prop('d'), 'M7.966,10.344 C7,12 7,12 6.034,10.344 L0.966,1.656 C-0,0 1,0 2,0 L12,0 C13,0 14,0 13.034,1.656 L7.966,10.344 z'); assert.equal(wrapper.find('path').prop('transform'), 'translate(-7, -6) scale(1)'); }); it('should have the correct path and transform for type 4', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { kind: 4 })); assert.equal(wrapper.find('path').prop('d'), 'M2.594,9.406 C-0.812,6 -0.812,6 2.594,2.594 C6,-0.812 6,-0.812 9.406,2.594 C12.812,6 12.812,6 9.406,9.406 C6,12.812 6,12.812 2.594,9.406 z'); assert.equal(wrapper.find('path').prop('transform'), 'translate(-6, -6) scale(1)'); }); // Loops back to the first point kind it('should have the correct path and transform for type 5', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { kind: 5 })); assert.equal(wrapper.find('path').prop('d'), 'M6,12 C2.686,12 0,9.314 0,6 C0,2.686 2.686,0 6,0 C9.314,-0 12,2.686 12,6 C12,9.314 9.314,12 6,12 z'); assert.equal(wrapper.find('path').prop('transform'), 'translate(-6, -6) scale(1)'); }); }); describe('scale', function () { it('should adjust the transform accordingly', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { kind: 0, scale: 5 })); assert.equal(wrapper.find('path').prop('transform'), 'translate(-30, -30) scale(5)'); }); }); describe('color', function () { it('should apply color strings as a class', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { color: "yolo" })); assert(wrapper.find('path').hasClass('lucid-Point-yolo'), 'missing color class'); }); it('should apply custom colors to `style`', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { color: "#F00" })); assert.deepEqual(wrapper.find('path').prop('style'), { fill: '#F00' }); }); }); describe('hasStroke', function () { it('should apply the correct class', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Point, { hasStroke: true })); assert(wrapper.find('path').hasClass('lucid-Point-has-stroke')); }); }); }); });