Files
shields/lib/make-badge.spec.js
Pyves bf13792633 Optimisation of makeBadge key width computation (#1298)
* Added cache to text width for badge keys.
2017-11-30 22:25:08 -05:00

42 lines
1.5 KiB
JavaScript

'use strict';
const assert = require('assert');
const makeBadge = require('./make-badge');
const {
_badgeKeyWidthCache
} = require('./make-badge');
const isSvg = require('is-svg');
describe('The badge generator', function () {
beforeEach(function () {
_badgeKeyWidthCache.clear();
});
it('should produce SVG', function () {
const svg = makeBadge({ text: ['cactus', 'grown'], format: 'svg' });
assert.ok(isSvg(svg));
assert(svg.includes('cactus'), 'cactus');
assert(svg.includes('grown'), 'grown');
});
it('should cache width of badge key', function () {
makeBadge({ text: ['cached', 'not-cached'], format: 'svg' });
assert.deepEqual([..._badgeKeyWidthCache.cache.keys()], ['cached']);
});
});
describe('"for-the-badge" template badge generation', function () {
// https://github.com/badges/shields/issues/1280
it('numbers should produce a string', function () {
const svg = makeBadge({ text: [1998, 1999], format: 'svg', template: 'for-the-badge' });
assert(svg.includes('1998'), `${svg} does not contain '1998'`);
assert(svg.includes('1999'), `${svg} does not contain '1999'`);
});
it('lowercase/mixedcase string should produce uppercase string', function () {
const svg = makeBadge({ text: ["Label", "1 string"], format: 'svg', template: 'for-the-badge' });
assert(svg.includes('LABEL'), `${svg} does not contain 'LABEL'`);
assert(svg.includes('1 STRING'), `${svg} does not contain '1 TEST'`);
});
});