From ac55a1f323ad599da2fe81c21a9f035a2ed7cd4f Mon Sep 17 00:00:00 2001 From: Stanslav Zaytsev Date: Tue, 5 Mar 2024 17:58:26 +0300 Subject: [PATCH] test(kit): refactored unit tests --- .../masks/number/tests/number-mask.spec.ts | 76 ++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts b/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts index 25955a3c0..79bb8f1b8 100644 --- a/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts +++ b/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts @@ -2,8 +2,11 @@ import {MASKITO_DEFAULT_OPTIONS, MaskitoOptions, maskitoTransform} from '@maskit import {maskitoParseNumber} from '@maskito/kit'; import { + CHAR_EM_DASH, CHAR_EN_DASH, CHAR_HYPHEN, + CHAR_JP_HYPHEN, + CHAR_MINUS, CHAR_NO_BREAK_SPACE, CHAR_ZERO_WIDTH_SPACE, } from '../../../constants'; @@ -325,49 +328,36 @@ describe('Number (maskitoTransform)', () => { }); describe('applies `minusSign` property correctly', () => { - let options = MASKITO_DEFAULT_OPTIONS; - - describe('correctly applies ⁻ as minus sign', () => { - beforeEach(() => { - options = maskitoNumberOptionsGenerator({minusSign: '⁻'}); - }); - - it('-32412 => ⁻32 412', () => { - expect(maskitoTransform('-32412', options)).toBe('⁻32 412'); - }); - - it(`${CHAR_HYPHEN}32413 => ⁻32 413`, () => { - expect(maskitoTransform(`${CHAR_HYPHEN}32413`, options)).toBe('⁻32 413'); - }); - - it('-32411 => ⁻32 411', () => { - expect(maskitoTransform('-32411', options)).toBe('⁻32 411'); - }); - - it(`${CHAR_EN_DASH}32411 => ⁻32 411`, () => { - expect(maskitoTransform(`${CHAR_EN_DASH}32411`, options)).toBe('⁻32 411'); - }); - }); - - describe('correctly applies i as minus sign', () => { - beforeEach(() => { - options = maskitoNumberOptionsGenerator({minusSign: 'i'}); - }); - - it('-32412 => i32 412', () => { - expect(maskitoTransform('-32412', options)).toBe('i32 412'); - }); - - it(`${CHAR_HYPHEN}32413 => i32 413`, () => { - expect(maskitoTransform(`${CHAR_HYPHEN}32413`, options)).toBe('i32 413'); - }); - - it('-32411 => i32 411', () => { - expect(maskitoTransform('-32411', options)).toBe('i32 411'); - }); - - it(`${CHAR_EN_DASH}32411 => i32 411`, () => { - expect(maskitoTransform(`${CHAR_EN_DASH}32411`, options)).toBe('i32 411'); + const minuses = [ + {value: CHAR_HYPHEN, name: 'hyphen'}, + {value: CHAR_MINUS, name: 'unicode minus sign'}, + {value: 'i', name: 'i'}, + ]; + + const numbers = ['23', '321', '2 432']; + + const pseudoMinuses = [ + {value: CHAR_HYPHEN, name: 'hyphen'}, + {value: CHAR_EN_DASH, name: 'en-dash'}, + {value: CHAR_EM_DASH, name: 'em-dash'}, + {value: CHAR_JP_HYPHEN, name: 'japanese prolonged sound mark'}, + {value: CHAR_MINUS, name: 'unicode minus sign'}, + ]; + + minuses.forEach(minus => { + const options = maskitoNumberOptionsGenerator({ + minusSign: minus.value, + thousandSeparator: ' ', + }); + + pseudoMinuses.forEach(pseudoMinus => { + numbers.forEach(number => { + it(`transforms ${pseudoMinus.name} into ${minus.name}`, () => { + expect( + maskitoTransform(`${pseudoMinus.value}${number}`, options), + ).toBe(`${minus.value}${number}`); + }); + }); }); }); });