Check font style and weight in addition to family

This commit is contained in:
ahocevar
2019-07-04 16:12:35 +02:00
parent ab2d97d49b
commit 4b48997a0b
4 changed files with 77 additions and 47 deletions
+19 -7
View File
@@ -1,44 +1,56 @@
import {getFontFamilies} from '../../../src/ol/css.js';
import {getFontParameters} from '../../../src/ol/css.js';
describe('ol.css', function() {
describe('getFontFamilies()', function() {
describe('getFontParameters()', function() {
const cases = [{
font: '2em "Open Sans"',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"']
}, {
font: '2em \'Open Sans\'',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"']
}, {
font: '2em "Open Sans", sans-serif',
style: 'normal',
weight: 'normal',
families: ['"Open Sans"', 'sans-serif']
}, {
font: 'italic small-caps bolder 16px/3 cursive',
style: 'italic',
weight: 'bolder',
families: ['cursive']
}, {
font: 'garbage 2px input',
families: null
}, {
font: '100% fantasy',
style: 'normal',
weight: 'normal',
families: ['fantasy']
}];
cases.forEach(function(c, i) {
it('works for ' + c.font, function() {
const families = getFontFamilies(c.font);
const font = getFontParameters(c.font);
if (c.families === null) {
expect(families).to.be(null);
expect(font).to.be(null);
return;
}
families.forEach(function(family, j) {
font.families.forEach(function(family, j) {
// Safari uses single quotes for font families, so we have to do extra work
if (family.charAt(0) === '\'') {
// we wouldn't want to do this in the lib since it doesn't properly escape quotes
// but we know that our test cases don't include quotes in font names
families[j] = '"' + family.slice(1, -1) + '"';
font.families[j] = '"' + family.slice(1, -1) + '"';
}
});
expect(families).to.eql(c.families);
expect(font.style).to.eql(c.style);
expect(font.weight).to.eql(c.weight);
expect(font.families).to.eql(c.families);
});
});