Files
shields/lib/badge-data.spec.js
Paul Melnikow 7ca2e97155 Use sazerac for our data-driven tests (#1228)
Sazerac is a library for data-driven tests, where a series of tests asserts that the return value of a function matches the expected value. It provides nice syntax for tightening this up.

https://hackernoon.com/sazerac-data-driven-testing-for-javascript-e3408ac29d8c

This converts our tests to use it, and replaces some similar home-grown code.

I fixed one bug I encountered along the way: mikec/sazerac#12.
2017-11-01 20:15:19 -04:00

88 lines
2.1 KiB
JavaScript

'use strict';
const assert = require('assert');
const { test, given, forCases } = require('sazerac');
const {
isDataUri,
hasPrefix,
isValidStyle,
isSixHex,
makeLabel,
makeLogo,
makeBadgeData,
} = require('./badge-data');
describe('Badge data helpers', function() {
test(hasPrefix, () => {
forCases([
given('data:image/svg+xml;base64,PHN2ZyB4bWxu', 'data:'),
given('data:foobar', 'data:'),
]).expect(true);
given('foobar', 'data:').expect(false);
});
test(isDataUri, () => {
given('data:image/svg+xml;base64,PHN2ZyB4bWxu').expect(true);
forCases([
given('data:foobar'),
given('foobar'),
]).expect(false);
});
test(isValidStyle, () => {
given('flat').expect(true);
forCases([
given('flattery'),
given(''),
given(undefined),
]).expect(false);
});
test(isSixHex, () => {
given('f00bae').expect(true);
forCases([
given('f00bar'),
given(''),
given(undefined),
]).expect(false);
});
test(makeLabel, () => {
given('my badge', {}).expect('my badge');
given('my badge', { label: 'no, my badge' }).expect('no, my badge');
});
test(makeLogo, () => {
forCases([
given('gratipay', { logo: 'image/svg+xml;base64,PHN2ZyB4bWxu' }),
given('gratipay', { logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu' }),
]).expect('data:image/svg+xml;base64,PHN2ZyB4bWxu');
forCases([
given('gratipay', { logo: '' }),
given(undefined, {}),
]).expect(undefined);
given('gratipay', {}).assert('should be truthy', assert.ok);
});
test(makeBadgeData, () => {
given('my badge', {
label: 'no, my badge',
style: 'flat-square',
logo: 'image/svg+xml;base64,PHN2ZyB4bWxu',
logoWidth: '25',
link: 'https://example.com/',
colorA: 'blue',
colorB: 'f00bae',
}).expect({
text: ['no, my badge', 'n/a'],
colorscheme: 'lightgrey',
template: 'flat-square',
logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
logoWidth: 25,
links: ['https://example.com/'],
colorA: 'blue',
colorB: '#f00bae',
});
});
});