]> git.r.bdr.sh - rbdr/forum/blob - src/utils/glyph_hash.test.js
Add gitlab CI config
[rbdr/forum] / src / utils / glyph_hash.test.js
1 import { getGlyphHash } from './glyph_hash';
2
3
4 describe('Glyph Hash utility', () => {
5
6 test('it throws an exception if the string is too short', () => {
7
8 expect(() => {
9
10 getGlyphHash('short');
11 }).toThrow();
12
13 expect(() => {
14
15 getGlyphHash('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
16 }).toThrow();
17
18 expect(() => {
19
20 getGlyphHash('abcdefghijklmnopqrstuvwxyzABCDEF');
21 }).not.toThrow();
22 });
23
24 test('it treats UUIDs with hyphens the same as those without', () => {
25
26 const uuidWithHyphens = 'f7722355-2285-46c0-a55f-3483a826f3a6';
27 const uuidWithoutHyphens = 'f7722355228546c0a55f3483a826f3a6';
28
29 expect(getGlyphHash(uuidWithHyphens)).toEqual(getGlyphHash(uuidWithoutHyphens));
30 });
31
32 describe('it generates four sets of glyphs and colors', () => {
33
34 const state = {};
35
36 beforeEach(() => {
37
38 state.glyphHash = getGlyphHash('f7722355-2285-46c0-a55f-3483a826f3a6');
39 });
40
41 test('there should be four glyph fragments', () => {
42
43 expect(state.glyphHash.length).toBe(4);
44 });
45
46 test('each fragment should have a single character glyph', () => {
47
48 for (const glyphHashFragment of state.glyphHash) {
49 expect(typeof glyphHashFragment.glyph).toBe('string');
50 expect(glyphHashFragment.glyph.length).toBe(1);
51 }
52 });
53
54 test('each fragment should have a hexadecimal color', () => {
55
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}/));
60 }
61 });
62 });
63 });