UNPKG

js-web-tools

Version:
64 lines (56 loc) 3.77 kB
"use strict"; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } var _domUtils = require("../domUtils"); var _domElementStyle = _interopRequireWildcard(require("../domElementStyle")); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } describe('Style tests', function () { beforeEach(function () { document.head.innerHTML = "\n <style type=\"text/css\">\n html {\n font-size: 16px;\n }\n\n #container {\n padding-right: 20px;\n margin-left: 1rem;\n }\n </style>\n "; document.body.innerHTML = "\n <div id=\"container\"></div>\n <div id=\"styledContainer\" style=\"margin-left: 12px;\"></div>\n "; }); afterEach(function () { document.body.innerHTML = ''; }); it('convertStyle', function () { var styles = (0, _domElementStyle.convertStyle)({ width: '100%', height: '100%', color: '#aabbcc' }); expect(styles).toEqual('width:100%;height:100%;color:#aabbcc;'); }); it('should get computed style', function () { var container = document.getElementById('container'); var eleStyle = (0, _domUtils.getComputedStyle)(container); expect(eleStyle.getPropertyValue('margin-left')).toEqual('1rem'); // TODO: 16px? expect(eleStyle.getPropertyValue('padding-right')).toEqual('20px'); }); it('should get style', function () { var ele = document.getElementById('container'); expect((0, _domElementStyle["default"])(ele, 'margin-left')).toEqual('1rem'); // TODO: 16px? expect((0, _domElementStyle["default"])(ele, 'paddingRight')).toEqual('20px'); expect((0, _domElementStyle["default"])(ele, 'padding-right')).toEqual('20px'); }); it('should set styles', function () { var ele = document.getElementById('styledContainer'); (0, _domElementStyle["default"])(ele, { 'margin-left': undefined, // remove this style 'padding-right': '4px', scale: 0.4 }); var eleStyle = (0, _domUtils.getComputedStyle)(ele); expect(eleStyle.getPropertyValue('margin-left')).toEqual(''); expect(eleStyle.getPropertyValue('transform')).toEqual('scale(0.4)'); expect(eleStyle.getPropertyValue('padding-right')).toEqual('4px'); }); it('should run coverage codes', function () { var ele = document.getElementById('styledContainer'); (0, _domElementStyle["default"])(ele, { 'margin-bottom': '24px' }); var eleStyle = (0, _domUtils.getComputedStyle)(ele); expect(eleStyle.getPropertyValue('margin-bottom')).toEqual('24px'); }); });