All files / src/validation glyphInputValidation.spec.ts

100% Statements 38/38
100% Branches 10/10
100% Functions 0/0
100% Lines 38/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 431x   1x     1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { describe, expect, test } from 'vitest';
 
import { GlyphCodeInputValidator, GlyphInputValidator } from './glyphInputValidation';
import type { GlyphInput } from '@/types/glyphTypes';
 
describe('Glyph Input Validation', () => {
  describe('general input validation', () => {
    test('nothing provided is invalid', () => {
      const inputProps: GlyphInput = {};
      expect(GlyphInputValidator(inputProps).isValid).toBeFalsy();
    });
  });
 
  describe('glyph code validation', () => {
    test('null code is not valid', () => {
      const code: any = null;
      expect(GlyphCodeInputValidator(code).isValid).toBeFalsy();
    });
    test('empty string code is not valid', () => {
      const code = '';
      expect(GlyphCodeInputValidator(code).isValid).toBeFalsy();
    });
    test('too short code is not valid', () => {
      const code = '1234';
      expect(GlyphCodeInputValidator(code).isValid).toBeFalsy();
    });
    test('too long code is not valid', () => {
      const code = '12345678901234567890';
      expect(GlyphCodeInputValidator(code).isValid).toBeFalsy();
    });
    test('correct code length is valid', () => {
      const code = '123456789012';
      const result = GlyphCodeInputValidator(code);
      expect(result.isValid).toBeTruthy();
    });
    test('has invalid characters', () => {
      const code = '12345test012';
      const result = GlyphCodeInputValidator(code);
      expect(result.isValid).toBeFalsy();
    });
  });
});