2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-14 14:38:25 +00:00
iconify/packages/utils/tests/calc-size-test.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-04-28 09:47:35 +00:00
import 'mocha';
import { expect } from 'chai';
import { calculateSize } from '../lib/svg/size';
2020-04-28 09:47:35 +00:00
describe('Testing calcSize', () => {
it('Simple size', () => {
const width = 36;
const height = 48;
// Get width from height and height from width
expect(calculateSize('48', width / height)).to.be.equal('36');
expect(calculateSize('36', height / width)).to.be.equal('48');
2020-04-28 09:47:35 +00:00
expect(calculateSize(48, width / height)).to.be.equal(36);
expect(calculateSize(36, height / width)).to.be.equal(48);
2020-04-28 09:47:35 +00:00
});
it('Numbers', () => {
const width = 36;
const height = 48;
// Simple numbers
expect(calculateSize(24, width / height)).to.be.equal(18);
expect(calculateSize(30, width / height)).to.be.equal(22.5);
expect(calculateSize(99, width / height)).to.be.equal(74.25);
2020-04-28 09:47:35 +00:00
// Rounding numbers
expect(calculateSize(100 / 3, height / width)).to.be.equal(44.45);
expect(calculateSize(11.1111111, width / height)).to.be.equal(8.34);
expect(calculateSize(11.1111111, width / height, 1000)).to.be.equal(
8.334
);
2020-04-28 09:47:35 +00:00
});
it('Strings', () => {
const width = 36;
const height = 48;
// Simple units
expect(calculateSize('48px', width / height)).to.be.equal('36px');
expect(calculateSize('24%', width / height)).to.be.equal('18%');
expect(calculateSize('1em', width / height)).to.be.equal('0.75em');
2020-04-28 09:47:35 +00:00
// Add space
expect(calculateSize('24 Pixels', width / height)).to.be.equal(
'18 Pixels'
);
2020-04-28 09:47:35 +00:00
// Multiple sets of numbers
expect(calculateSize('48% + 5em', width / height)).to.be.equal(
2020-04-28 09:47:35 +00:00
'36% + 3.75em'
);
expect(calculateSize('calc(1em + 8px)', height / width)).to.be.equal(
2020-04-28 09:47:35 +00:00
'calc(1.34em + 10.67px)'
);
expect(
calculateSize('-webkit-calc(1em + 8px)', width / height)
).to.be.equal('-webkit-calc(0.75em + 6px)');
2020-04-28 09:47:35 +00:00
// Invalid strings
expect(calculateSize('-.', width / height)).to.be.equal('-.');
expect(calculateSize('@foo', width / height)).to.be.equal('@foo');
2020-04-28 09:47:35 +00:00
});
});