forked from hfg-gmuend/openmoji
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-format.js
More file actions
93 lines (81 loc) · 3.52 KB
/
Copy pathfile-format.js
File metadata and controls
93 lines (81 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const path = require('path');
const { filter } = require('lodash');
const { expect } = require('chai');
const argv = require('optimist').default('openmoji-data-json', path.join(__dirname, '../data/openmoji.json')).argv;
const openmojiDataJson = argv['openmoji-data-json'];
const openmojis = require(openmojiDataJson);
const { createDoc, readSVG, isValidXML } = require('./utils/utils');
describe('OpenMoji file format', function() {
const emojis = filter(openmojis, (e) => { return e.skintone == '' });
describe('SVG is valid XML syntax?', function () {
emojis.forEach(emoji => {
it(`${emoji.emoji} ${emoji.hexcode}.svg should be valid XML syntax`, function () {
const doc = readSVG(emoji);
expect( isValidXML(doc) ).to.be.true;
});
it(`${emoji.emoji} ${emoji.hexcode}.svg elements should not have duplicate attributes`, function () {
const doc = readSVG(emoji);
const elements = doc.match(/<\w.*>/g);
elements.forEach(element => {
const attrs = element.match(/((\w|-)+)=/g);
const dedupeAttrs = new Set(attrs);
if (attrs) expect(attrs.length).to.equal(dedupeAttrs.size);
});
});
});
});
describe('SVG element viewBox (canvas) size is correct?', function() {
emojis.forEach(emoji => {
it(`${emoji.emoji} ${emoji.hexcode}.svg SVG element should have a viewBox attribute of 72 × 72 px`, function(){
const doc = createDoc(emoji);
const svg = doc.querySelector('svg');
expect( svg.getAttribute('viewBox') ).to.equal('0 0 72 72');
});
});
});
describe('SVG element id is named "emoji"?', function() {
emojis.forEach(emoji => {
it(`${emoji.emoji} ${emoji.hexcode}.svg SVG element should have an id named "emoji"`, function(){
const doc = createDoc(emoji);
const svg = doc.querySelector('svg');
expect( svg.getAttribute('id') ).to.equal('emoji');
});
});
});
describe('SVG is styled without a global css style element?', function() {
emojis.forEach(emoji => {
it(`${emoji.emoji} ${emoji.hexcode}.svg should not use global style sheets`, function(){
const doc = createDoc(emoji);
expect( doc.querySelector('style') ).to.not.exist;
});
});
});
describe('All basic shapes (rect, circle, line etc) without a style attribute?', function() {
emojis.forEach(emoji => {
it(`${emoji.emoji} ${emoji.hexcode}.svg should not contain basic shapes with a style attribute`, function(){
const doc = createDoc(emoji);
const elementsWithStyleAttribute = doc.querySelectorAll(':not(#grid) > [style]');
expect( elementsWithStyleAttribute.length ).to.equal(0);
});
});
});
describe('SVG is without any masks elements?', function() {
emojis.forEach(emoji => {
it(`${emoji.emoji} ${emoji.hexcode}.svg should not use mask elements`, function(){
const doc = createDoc(emoji);
expect( doc.querySelector('mask') ).to.not.exist;
});
});
});
describe('SVG has only <g> elements (layers) at top level?', function() {
emojis.forEach(emoji => {
it(`${emoji.emoji} ${emoji.hexcode}.svg should only have <g> elements at top level and no other elements`, function(){
const doc = createDoc(emoji);
const layers = doc.querySelectorAll('svg > g, svg > title');
const notLayers = doc.querySelectorAll('svg > :not(g):not(title)');
expect( layers.length ).to.be.at.least(3);
expect( notLayers.length ).to.equal(0);
});
});
});
});