* Fix currency number formating and add unit tests * Fix Input currency type cypress test * Fix currency number formating and add unit tests * Fix Input currency type cypress test * Add comments for utilities formatCurrencyNumber and limitDecimalValue * Fix currency number formating and add unit tests * Fix Input currency type cypress test * Fix Input currency type cypress test * Add comments for utilities formatCurrencyNumber and limitDecimalValue * Fix upstep and downstep button action for formated currency input * remove crendentials from cypress.json * Fix input currency test flakiness * Fix cypress test for currency input type Fix formatCurrencyNumber function and added more unit tests * Fix cypress test for currency input Handle group separator and decimal separator when formatting and deformatting input for currency type * remove console.log * Handle formatting changes for default text * Format input widget value for currency to handle default text * remove unused import * Add unit tests for getGroupSeparator and getDecimalSeparator functions * add function to get user locale * use preventDefault in input increment/decrement button click * Use getLocale function, use String function * use Number function for type conversion * fix number to string type * Handle 0 value for numbers Co-authored-by: Arpit Mohan <arpit@appsmith.com>
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import {
|
|
formatCurrencyNumber,
|
|
limitDecimalValue,
|
|
getDecimalSeparator,
|
|
getGroupSeparator,
|
|
} from "./utilities";
|
|
|
|
describe("currency Number formating", () => {
|
|
it("Without Decimal", () => {
|
|
const response = formatCurrencyNumber(undefined, "1234560", ".");
|
|
expect(response).toStrictEqual("1,234,560");
|
|
});
|
|
it("With Decimal", () => {
|
|
const response = formatCurrencyNumber(2, "1234560.90", ".");
|
|
expect(response).toStrictEqual("1,234,560.9");
|
|
});
|
|
it("With Decimal", () => {
|
|
const response = formatCurrencyNumber(2, "1234560.9", ".");
|
|
expect(response).toStrictEqual("1,234,560.9");
|
|
});
|
|
it("With Decimal", () => {
|
|
const response = formatCurrencyNumber(2, "1234560.981", ".");
|
|
expect(response).toStrictEqual("1,234,560.98");
|
|
});
|
|
});
|
|
|
|
describe("Limiting decimal Numbers ", () => {
|
|
it("Without Decimal", () => {
|
|
const response = limitDecimalValue(undefined, "1234560", ".", ",");
|
|
expect(response).toStrictEqual("1234560");
|
|
});
|
|
it("With Decimal more than the limit", () => {
|
|
const response = limitDecimalValue(2, "3456789.35444", ".", ",");
|
|
expect(response).toStrictEqual("3456789.35");
|
|
});
|
|
});
|
|
|
|
describe("Decimal separator test", () => {
|
|
it("For en-US locale", () => {
|
|
const response = getDecimalSeparator("en-US");
|
|
expect(response).toEqual(".");
|
|
});
|
|
it("For it (Italian) locale", () => {
|
|
const response = getDecimalSeparator("it");
|
|
expect(response).toEqual(",");
|
|
});
|
|
});
|
|
|
|
describe("Group separator test", () => {
|
|
it("For en-US locale", () => {
|
|
const response = getGroupSeparator("en-US");
|
|
expect(response).toEqual(",");
|
|
});
|
|
it("For it (Italian) locale", () => {
|
|
const response = getGroupSeparator("it");
|
|
expect(response).toEqual(".");
|
|
});
|
|
});
|