Skip to content

Commit

Permalink
test(demo-integrations): refactored tests for custom minus sign in nu…
Browse files Browse the repository at this point in the history
…mber
  • Loading branch information
Stanslav Zaytsev committed Mar 6, 2024
1 parent ac55a1f commit b7dac00
Showing 1 changed file with 38 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,59 +1,45 @@
import {CHAR_EN_DASH, CHAR_HYPHEN, CHAR_JP_HYPHEN} from 'projects/kit/src/lib/constants';
import {
CHAR_EM_DASH,
CHAR_EN_DASH,
CHAR_HYPHEN,
CHAR_JP_HYPHEN,
CHAR_MINUS,
} from 'projects/kit/src/lib/constants';

import {openNumberPage} from './utils';

describe('Properly using custom minus sign', () => {
describe(`correctly applies ${CHAR_HYPHEN} as minus sign`, () => {
beforeEach(() => {
openNumberPage(`minusSign=${CHAR_HYPHEN}&thousandSeparator=_`);
});

it(`-32412 => ${CHAR_HYPHEN}32_412`, () => {
cy.get('@input').type('-32412').should('have.value', `${CHAR_HYPHEN}32_412`);
});

it(`${CHAR_HYPHEN}32412 => ${CHAR_HYPHEN}32_412`, () => {
cy.get('@input').type('-32412').should('have.value', `${CHAR_HYPHEN}32_412`);
});

it(`${CHAR_JP_HYPHEN}32412 => ${CHAR_HYPHEN}32_412`, () => {
cy.get('@input')
.type(`${CHAR_JP_HYPHEN}32412`)
.should('have.value', `${CHAR_HYPHEN}32_412`);
});

it(`${CHAR_EN_DASH}32412 => ${CHAR_HYPHEN}32_412`, () => {
cy.get('@input')
.type(`${CHAR_EN_DASH}32412`)
.should('have.value', `${CHAR_HYPHEN}32_412`);
});
});

describe('correctly works with decimal, and minus sign is i', () => {
beforeEach(() => {
openNumberPage('minusSign=i&precision=Infinity&thousandSeparator=_');
});

it('-324,12 => i_324.12', () => {
cy.get('@input').type('-324,12').should('have.value', 'i_324.12');
});

it(`${CHAR_HYPHEN}324,12 => i_324.12`, () => {
cy.get('@input')
.type(`${CHAR_HYPHEN}324,12`)
.should('have.value', 'i_324.12');
});

it(`${CHAR_JP_HYPHEN}324,12 => i_324.12`, () => {
cy.get('@input')
.type(`${CHAR_JP_HYPHEN}324,12`)
.should('have.value', 'i_324.12');
});

it(`${CHAR_EN_DASH}324,12 => i_324.12`, () => {
cy.get('@input')
.type(`${CHAR_EN_DASH}324,12`)
.should('have.value', 'i_324.12');
const minuses: Array<{value: string; name: string; asQueryParam: string}> = [
{value: CHAR_HYPHEN, name: 'hyphen', asQueryParam: '-'},
{value: 'i', name: 'i', asQueryParam: 'i'},
];

const numbers = ['321', '2_432'];

const pseudoMinuses: Array<{value: string; name: string}> = [
{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 => {
if (minus.value === 'i') {
pseudoMinuses.push(minus);
}

pseudoMinuses.forEach(pseudoMinus => {
numbers.forEach(number => {
it(`transforms ${pseudoMinus.name} into ${minus.name}`, () => {
openNumberPage(
`precision=Infinity&thousandSeparator=_&minusSign=${minus.asQueryParam}`,
);
cy.get('@input')
.type(`${pseudoMinus.value}${number}`)
.should('have.value', `${minus.value}${number}`);
});
});
});
});
});

0 comments on commit b7dac00

Please sign in to comment.