1 import { getGlyphHash } from './glyph_hash';
2 import type { GlyphHash } from './glyph_hash';
9 describe('Glyph Hash utility', () => {
11 test('it throws an exception if the string is too short', () => {
15 getGlyphHash('short');
20 getGlyphHash('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
25 getGlyphHash('abcdefghijklmnopqrstuvwxyzABCDEF');
29 test('it treats UUIDs with hyphens the same as those without', () => {
31 const uuidWithHyphens = 'f7722355-2285-46c0-a55f-3483a826f3a6';
32 const uuidWithoutHyphens = 'f7722355228546c0a55f3483a826f3a6';
34 expect(getGlyphHash(uuidWithHyphens)).toEqual(getGlyphHash(uuidWithoutHyphens));
37 describe('it generates four sets of glyphs and colors', () => {
39 const state: TestState = {};
43 state.glyphHash = getGlyphHash('f7722355-2285-46c0-a55f-3483a826f3a6');
46 test('there should be four glyph fragments', () => {
48 expect(state.glyphHash.length).toBe(4);
51 test('each fragment should have a single character glyph', () => {
53 for (const glyphHashFragment of state.glyphHash) {
54 expect(typeof glyphHashFragment.glyph).toBe('string');
55 expect(glyphHashFragment.glyph.length).toBe(1);
59 test('each fragment should have a hexadecimal color', () => {
61 for (const glyphHashFragment of state.glyphHash) {
62 expect(typeof glyphHashFragment.color).toBe('string');
63 expect(glyphHashFragment.color.length).toBe(7);
64 expect(glyphHashFragment.color).toEqual(expect.stringMatching(/#[0-9a-f]{6}/));