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