normalize-string.spec.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { describe, expect, it } from 'vitest';
  2. import { normalizeString } from './normalize-string';
  3. describe('normalizeString()', () => {
  4. it('lowercases the string', () => {
  5. expect(normalizeString('FOO')).toBe('foo');
  6. expect(normalizeString('Foo Bar')).toBe('foo bar');
  7. });
  8. it('replaces diacritical marks with plain equivalents', () => {
  9. expect(normalizeString('thé')).toBe('the');
  10. expect(normalizeString('curaçao')).toBe('curacao');
  11. expect(normalizeString('dấu hỏi')).toBe('dau hoi');
  12. expect(normalizeString('el niño')).toBe('el nino');
  13. expect(normalizeString('genkō yōshi')).toBe('genko yoshi');
  14. expect(normalizeString('việt nam')).toBe('viet nam');
  15. });
  16. it('replaces spaces with the spaceReplacer', () => {
  17. expect(normalizeString('old man', '_')).toBe('old_man');
  18. expect(normalizeString('old man', '_')).toBe('old_man');
  19. });
  20. it('strips non-alphanumeric characters', () => {
  21. expect(normalizeString('hi!!!')).toBe('hi');
  22. expect(normalizeString('who? me?')).toBe('who me');
  23. expect(normalizeString('!"£$%^&*()+[]{};:@#~?/,|\\><`¬\'=©®™')).toBe('');
  24. });
  25. it('allows a subset of non-alphanumeric characters to pass through', () => {
  26. expect(normalizeString('-_.')).toBe('-_.');
  27. });
  28. // https://github.com/vendure-ecommerce/vendure/issues/679
  29. it('replaces single quotation marks', () => {
  30. expect(normalizeString('Capture d’écran')).toBe('capture decran');
  31. expect(normalizeString('Capture d‘écran')).toBe('capture decran');
  32. });
  33. });