2018-05-15 15:16:28 +00:00
|
|
|
/* eslint-env qunit */
|
2018-05-18 03:25:45 +00:00
|
|
|
/* globals svgedit, equals */
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
// log function
|
|
|
|
QUnit.log = function (details) {
|
|
|
|
if (window.console && window.console.log) {
|
|
|
|
window.console.log(details.result + ' :: ' + details.message);
|
2018-05-18 04:12:27 +00:00
|
|
|
}
|
2018-05-18 03:25:45 +00:00
|
|
|
};
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
function setUp () {
|
|
|
|
svgedit.units.init({
|
|
|
|
getBaseUnit () { return 'cm'; },
|
|
|
|
getHeight () { return 600; },
|
|
|
|
getWidth () { return 800; },
|
|
|
|
getRoundDigits () { return 4; },
|
|
|
|
getElement (elementId) { return document.getElementById(elementId); }
|
2018-05-18 04:12:27 +00:00
|
|
|
});
|
2018-05-18 03:25:45 +00:00
|
|
|
}
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.units package', function () {
|
|
|
|
expect(2);
|
|
|
|
ok(svgedit.units);
|
|
|
|
equals(typeof svgedit.units, typeof {});
|
|
|
|
});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.units.shortFloat()', function () {
|
|
|
|
expect(7);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
setUp();
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
ok(svgedit.units.shortFloat);
|
|
|
|
equals(typeof svgedit.units.shortFloat, typeof function () {});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const {shortFloat} = svgedit.units;
|
|
|
|
equals(shortFloat(0.00000001), 0);
|
|
|
|
equals(shortFloat(1), 1);
|
|
|
|
equals(shortFloat(3.45678), 3.4568);
|
|
|
|
equals(shortFloat(1.23443), 1.2344);
|
|
|
|
equals(shortFloat(1.23455), 1.2346);
|
|
|
|
});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.units.isValidUnit()', function () {
|
|
|
|
expect(18);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
setUp();
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
ok(svgedit.units.isValidUnit);
|
|
|
|
equals(typeof svgedit.units.isValidUnit, typeof function () {});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const {isValidUnit} = svgedit.units;
|
|
|
|
ok(isValidUnit('0'));
|
|
|
|
ok(isValidUnit('1'));
|
|
|
|
ok(isValidUnit('1.1'));
|
|
|
|
ok(isValidUnit('-1.1'));
|
|
|
|
ok(isValidUnit('.6mm'));
|
|
|
|
ok(isValidUnit('-.6cm'));
|
|
|
|
ok(isValidUnit('6000in'));
|
|
|
|
ok(isValidUnit('6px'));
|
|
|
|
ok(isValidUnit('6.3pc'));
|
|
|
|
ok(isValidUnit('-0.4em'));
|
|
|
|
ok(isValidUnit('-0.ex'));
|
|
|
|
ok(isValidUnit('40.123%'));
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
equals(isValidUnit('id', 'uniqueId', document.getElementById('uniqueId')), true);
|
|
|
|
equals(isValidUnit('id', 'newId', document.getElementById('uniqueId')), true);
|
|
|
|
equals(isValidUnit('id', 'uniqueId'), false);
|
|
|
|
equals(isValidUnit('id', 'uniqueId', document.getElementById('nonUniqueId')), false);
|
|
|
|
});
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
test('Test svgedit.units.convertUnit()', function () {
|
|
|
|
expect(4);
|
2018-05-15 15:16:28 +00:00
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
setUp();
|
|
|
|
|
|
|
|
ok(svgedit.units.convertUnit);
|
|
|
|
equals(typeof svgedit.units.convertUnit, typeof function () {});
|
|
|
|
// cm in default setup
|
|
|
|
equals(svgedit.units.convertUnit(42), 1.1113);
|
|
|
|
equals(svgedit.units.convertUnit(42, 'px'), 42);
|
2018-05-15 15:16:28 +00:00
|
|
|
});
|