]>
git.r.bdr.sh - rbdr/forum/blob - src/utils/glyph_hash.test.js
eada78adb8a9c41d11b68ee8f3067b96b581c8a3
1 import { getGlyphHash
} from './glyph_hash';
4 describe('Glyph Hash utility', () => {
6 test('it throws an exception if the string is too short', () => {
10 getGlyphHash('short');
15 getGlyphHash('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
20 getGlyphHash('abcdefghijklmnopqrstuvwxyzABCDEF');
24 test('it treats UUIDs with hyphens the same as those without', () => {
26 const uuidWithHyphens
= 'f7722355-2285-46c0-a55f-3483a826f3a6';
27 const uuidWithoutHyphens
= 'f7722355228546c0a55f3483a826f3a6';
29 expect(getGlyphHash(uuidWithHyphens
)).toEqual(getGlyphHash(uuidWithoutHyphens
));
32 describe('it generates four sets of glyphs and colors', () => {
38 state
.glyphHash
= getGlyphHash('f7722355-2285-46c0-a55f-3483a826f3a6');
41 test('there should be four glyph fragments', () => {
43 expect(state
.glyphHash
.length
).toBe(4);
46 test('each fragment should have a single character glyph', () => {
48 for (const glyphHashFragment
of state
.glyphHash
) {
49 expect(typeof glyphHashFragment
.glyph
).toBe('string');
50 expect(glyphHashFragment
.glyph
.length
).toBe(1);
54 test('each fragment should have a hexadecimal color', () => {
56 for (const glyphHashFragment
of state
.glyphHash
) {
57 expect(typeof glyphHashFragment
.color
).toBe('string');
58 expect(glyphHashFragment
.color
.length
).toBe(7);
59 expect(glyphHashFragment
.color
).toEqual(expect
.stringMatching(/#[0-9a-f]{6}/));