Check font style and weight in addition to family
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('ol.render.canvas', function() {
|
||||
const spy = sinon.spy();
|
||||
listen(render.labelCache, 'clear', spy);
|
||||
const interval = setInterval(function() {
|
||||
if (render.checkedFonts['foo'] == retries && render.checkedFonts['sans-serif'] == retries) {
|
||||
if (render.checkedFonts['normal\nnormal\nfoo'] == retries && render.checkedFonts['normal\nnormal\nsans-serif'] == retries) {
|
||||
clearInterval(interval);
|
||||
unlisten(render.labelCache, 'clear', spy);
|
||||
expect(spy.callCount).to.be(0);
|
||||
@@ -39,7 +39,7 @@ describe('ol.render.canvas', function() {
|
||||
const spy = sinon.spy();
|
||||
listen(render.labelCache, 'clear', spy);
|
||||
const interval = setInterval(function() {
|
||||
if (render.checkedFonts['sans-serif'] == retries) {
|
||||
if (render.checkedFonts['normal\nnormal\nsans-serif'] == retries) {
|
||||
clearInterval(interval);
|
||||
unlisten(render.labelCache, 'clear', spy);
|
||||
expect(spy.callCount).to.be(0);
|
||||
@@ -54,7 +54,7 @@ describe('ol.render.canvas', function() {
|
||||
const spy = sinon.spy();
|
||||
listen(render.labelCache, 'clear', spy);
|
||||
const interval = setInterval(function() {
|
||||
if (render.checkedFonts['monospace'] == retries) {
|
||||
if (render.checkedFonts['normal\nnormal\nmonospace'] == retries) {
|
||||
clearInterval(interval);
|
||||
unlisten(render.labelCache, 'clear', spy);
|
||||
expect(spy.callCount).to.be(0);
|
||||
@@ -67,6 +67,7 @@ describe('ol.render.canvas', function() {
|
||||
|
||||
it('clears label cache and measurements for fonts that become available', function(done) {
|
||||
head.appendChild(font);
|
||||
render.labelCache.set('dummy', {});
|
||||
listen(render.labelCache, 'clear', function() {
|
||||
expect(render.textHeights).to.eql({});
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user