Skip to content

Commit

Permalink
test(kit): refactored unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanslav Zaytsev committed Mar 5, 2024
1 parent 4fdce96 commit ac55a1f
Showing 1 changed file with 33 additions and 43 deletions.
76 changes: 33 additions & 43 deletions projects/kit/src/lib/masks/number/tests/number-mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`);
});
});
});
});
});
Expand Down

0 comments on commit ac55a1f

Please sign in to comment.