2021-11-08 12:55:47 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const iconsDir = path.resolve(process.cwd(), 'icons');
|
2021-11-29 10:44:36 +02:00
|
|
|
const { suite } = require('uvu');
|
|
|
|
const assert = require('uvu/assert');
|
2021-11-08 12:55:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if icon data matches a subject icon.
|
|
|
|
* @param {import('..').SimpleIcon} icon Icon data
|
|
|
|
* @param {import('..').SimpleIcon} subject Icon to check against icon data
|
|
|
|
* @param {String} slug Icon data slug
|
|
|
|
*/
|
|
|
|
const testIcon = (icon, subject, slug) => {
|
2021-11-29 10:44:36 +02:00
|
|
|
const test = suite(icon.title);
|
|
|
|
const svgPath = path.resolve(iconsDir, `${slug}.svg`);
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test('has the correct "title"', () => {
|
|
|
|
assert.is(subject.title, icon.title);
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test('has the correct "slug"', () => {
|
|
|
|
assert.is(subject.slug, slug);
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test('has the correct "hex" value', () => {
|
|
|
|
assert.is(subject.hex, icon.hex);
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test('has the correct "source"', () => {
|
|
|
|
assert.is(subject.source, icon.source);
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test('has an "svg" value', () => {
|
|
|
|
assert.type(subject.svg, 'string');
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test('has a valid "path" value', () => {
|
|
|
|
assert.match(subject.path, /^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g);
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test(`has ${icon.guidelines ? 'the correct' : 'no'} "guidelines"`, () => {
|
|
|
|
if (icon.guidelines) {
|
|
|
|
assert.is(subject.guidelines, icon.guidelines);
|
|
|
|
} else {
|
|
|
|
assert.is(subject.guidelines, undefined);
|
|
|
|
}
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test(`has ${icon.license ? 'the correct' : 'no'} "license"`, () => {
|
|
|
|
if (icon.license) {
|
|
|
|
assert.is(subject.license.type, icon.license.type);
|
|
|
|
if (icon.license.type === 'custom') {
|
|
|
|
assert.is(subject.license.url, icon.license.url);
|
2021-11-08 12:55:47 +02:00
|
|
|
} else {
|
2021-11-29 10:44:36 +02:00
|
|
|
assert.match(subject.license.url, /^https?:\/\/[^\s]+$/);
|
2021-11-08 12:55:47 +02:00
|
|
|
}
|
2021-11-29 10:44:36 +02:00
|
|
|
} else {
|
|
|
|
assert.is(subject.license, undefined);
|
|
|
|
}
|
|
|
|
});
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
test('has a valid svg value', () => {
|
|
|
|
const svgFileContents = fs
|
|
|
|
.readFileSync(svgPath, 'utf8')
|
|
|
|
.replace(/\r?\n/, '');
|
2021-11-08 12:55:47 +02:00
|
|
|
|
2021-11-29 10:44:36 +02:00
|
|
|
assert.is(
|
|
|
|
subject.svg.substring(subject.svg.indexOf('<title>')),
|
|
|
|
svgFileContents.substring(svgFileContents.indexOf('<title>')),
|
|
|
|
);
|
2021-11-08 12:55:47 +02:00
|
|
|
});
|
2021-11-29 10:44:36 +02:00
|
|
|
|
|
|
|
test.run();
|
2021-11-08 12:55:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = testIcon;
|