Skip to content

Commit 3e112c9

Browse files
authored
fix(cost-calculator) - fix currency (#718)
* fix(cost-calculator) - fix currency * fix e2e test * fix spec * fix spaces * fix spacing * fix number * fix spacing
1 parent 2a4c116 commit 3e112c9

8 files changed

Lines changed: 79 additions & 54 deletions

File tree

example/e2e/annual-gross-salary.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test.describe('annual gross salary', () => {
2222

2323
// Using getByText for static text + regex for dynamic part
2424
const headerAmount = page.getByText(
25-
/Employee annual gross salary: kr\d+\.\d\d/,
25+
/Employee annual gross salary: SEK\s\d+\.\d\d/,
2626
);
2727
await expect(headerAmount).toBeVisible();
2828
});

example/e2e/hiring-budget.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test.describe('hiring budget', () => {
1919
});
2020

2121
const headerAmount = page.getByText(
22-
/Employee annual gross salary: kr\d{1,3}(,\d{3})*\.\d{2}/,
22+
/Employee annual gross salary: SEK\s\d{1,3}(,\d{3})*\.\d{2}/,
2323
);
2424

2525
await expect(headerAmount).toBeVisible();

src/flows/ContractorOnboarding/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export const useContractorSubscriptionSchemaField = (
287287
if (opts.price.amount) {
288288
formattedPrice = formatCurrency(
289289
opts.price.amount,
290-
opts.currency.symbol,
290+
opts.currency.code,
291291
);
292292
}
293293
const product = opts.product;

src/flows/CostCalculator/EstimationResults/EstimationResults.tsx

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ export const EstimationResults = ({
614614

615615
const formattedSalary = formatCurrency(
616616
estimation.regional_currency_costs.annual_gross_salary,
617-
estimation.regional_currency_costs.currency.symbol,
617+
estimation.regional_currency_costs.currency.code,
618618
);
619619

620620
return (
@@ -642,16 +642,16 @@ export const EstimationResults = ({
642642
? [
643643
formatCurrency(
644644
estimation.regional_currency_costs.monthly_total,
645-
estimation.regional_currency_costs.currency.symbol,
645+
estimation.regional_currency_costs.currency.code,
646646
),
647647
formatCurrency(
648648
estimation.employer_currency_costs.monthly_total,
649-
estimation.employer_currency_costs.currency.symbol,
649+
estimation.employer_currency_costs.currency.code,
650650
),
651651
]
652652
: formatCurrency(
653653
estimation.regional_currency_costs.monthly_total,
654-
estimation.regional_currency_costs.currency.symbol,
654+
estimation.regional_currency_costs.currency.code,
655655
)
656656
}
657657
>
@@ -661,11 +661,11 @@ export const EstimationResults = ({
661661
label: 'Gross monthly salary',
662662
regionalAmount: formatCurrency(
663663
estimation.regional_currency_costs.monthly_gross_salary,
664-
estimation.regional_currency_costs.currency.symbol,
664+
estimation.regional_currency_costs.currency.code,
665665
),
666666
employerAmount: formatCurrency(
667667
estimation.employer_currency_costs.monthly_gross_salary,
668-
estimation.employer_currency_costs.currency.symbol,
668+
estimation.employer_currency_costs.currency.code,
669669
),
670670
zendeskId: zendeskArticles.extraPayments.toString(),
671671
tooltip:
@@ -676,12 +676,12 @@ export const EstimationResults = ({
676676
regionalAmount: formatCurrency(
677677
estimation.regional_currency_costs
678678
.monthly_contributions_total,
679-
estimation.regional_currency_costs.currency.symbol,
679+
estimation.regional_currency_costs.currency.code,
680680
),
681681
employerAmount: formatCurrency(
682682
estimation.employer_currency_costs
683683
.monthly_contributions_total,
684-
estimation.employer_currency_costs.currency.symbol,
684+
estimation.employer_currency_costs.currency.code,
685685
),
686686
children:
687687
estimation.employer_currency_costs.monthly_contributions_breakdown?.map(
@@ -691,11 +691,11 @@ export const EstimationResults = ({
691691
regionalAmount: formatCurrency(
692692
estimation.regional_currency_costs
693693
.monthly_contributions_breakdown?.[index]?.amount,
694-
estimation.regional_currency_costs.currency.symbol,
694+
estimation.regional_currency_costs.currency.code,
695695
),
696696
employerAmount: formatCurrency(
697697
item.amount,
698-
estimation.employer_currency_costs.currency.symbol,
698+
estimation.employer_currency_costs.currency.code,
699699
),
700700
zendeskId: item.zendesk_article_id || undefined,
701701
tooltip: item.description || undefined,
@@ -707,11 +707,11 @@ export const EstimationResults = ({
707707
label: 'Benefits',
708708
regionalAmount: formatCurrency(
709709
estimation.regional_currency_costs.monthly_benefits_total,
710-
estimation.regional_currency_costs.currency.symbol,
710+
estimation.regional_currency_costs.currency.code,
711711
),
712712
employerAmount: formatCurrency(
713713
estimation.employer_currency_costs.monthly_benefits_total,
714-
estimation.employer_currency_costs.currency.symbol,
714+
estimation.employer_currency_costs.currency.code,
715715
),
716716
children:
717717
estimation.employer_currency_costs.monthly_benefits_breakdown?.map(
@@ -720,11 +720,11 @@ export const EstimationResults = ({
720720
regionalAmount: formatCurrency(
721721
estimation.regional_currency_costs
722722
.monthly_benefits_breakdown?.[index]?.amount,
723-
estimation.regional_currency_costs.currency.symbol,
723+
estimation.regional_currency_costs.currency.code,
724724
),
725725
employerAmount: formatCurrency(
726726
item.amount,
727-
estimation.employer_currency_costs.currency.symbol,
727+
estimation.employer_currency_costs.currency.code,
728728
),
729729
zendeskId: item.zendesk_article_id || undefined,
730730
tooltip: item.description || undefined,
@@ -738,12 +738,12 @@ export const EstimationResults = ({
738738
regionalAmount: formatCurrency(
739739
estimation.regional_currency_costs
740740
.monthly_management_fee,
741-
estimation.regional_currency_costs.currency.symbol,
741+
estimation.regional_currency_costs.currency.code,
742742
),
743743
employerAmount: formatCurrency(
744744
estimation.employer_currency_costs
745745
.monthly_management_fee,
746-
estimation.employer_currency_costs.currency.symbol,
746+
estimation.employer_currency_costs.currency.code,
747747
),
748748
tooltip:
749749
'Discounts may be available based on your commitment and team size. Speak to your account or customer success manager to learn more.',
@@ -763,16 +763,16 @@ export const EstimationResults = ({
763763
? [
764764
formatCurrency(
765765
estimation.regional_currency_costs.annual_total,
766-
estimation.regional_currency_costs.currency.symbol,
766+
estimation.regional_currency_costs.currency.code,
767767
),
768768
formatCurrency(
769769
estimation.employer_currency_costs.annual_total,
770-
estimation.employer_currency_costs.currency.symbol,
770+
estimation.employer_currency_costs.currency.code,
771771
),
772772
]
773773
: formatCurrency(
774774
estimation.regional_currency_costs.annual_total,
775-
estimation.regional_currency_costs.currency.symbol,
775+
estimation.regional_currency_costs.currency.code,
776776
)
777777
}
778778
>
@@ -783,22 +783,22 @@ export const EstimationResults = ({
783783
dataSelector: 'annual-gross-salary',
784784
regionalAmount: formatCurrency(
785785
estimation.regional_currency_costs.annual_gross_salary,
786-
estimation.regional_currency_costs.currency.symbol,
786+
estimation.regional_currency_costs.currency.code,
787787
),
788788
employerAmount: formatCurrency(
789789
estimation.employer_currency_costs.annual_gross_salary,
790-
estimation.employer_currency_costs.currency.symbol,
790+
estimation.employer_currency_costs.currency.code,
791791
),
792792
},
793793
{
794794
label: 'Mandatory employer costs',
795795
regionalAmount: formatCurrency(
796796
estimation.regional_currency_costs.annual_contributions_total,
797-
estimation.regional_currency_costs.currency.symbol,
797+
estimation.regional_currency_costs.currency.code,
798798
),
799799
employerAmount: formatCurrency(
800800
estimation.employer_currency_costs.annual_contributions_total,
801-
estimation.employer_currency_costs.currency.symbol,
801+
estimation.employer_currency_costs.currency.code,
802802
),
803803
children:
804804
estimation.employer_currency_costs.annual_contributions_breakdown?.map(
@@ -807,11 +807,11 @@ export const EstimationResults = ({
807807
regionalAmount: formatCurrency(
808808
estimation.regional_currency_costs
809809
.annual_contributions_breakdown?.[index]?.amount,
810-
estimation.regional_currency_costs.currency.symbol,
810+
estimation.regional_currency_costs.currency.code,
811811
),
812812
employerAmount: formatCurrency(
813813
item.amount,
814-
estimation.employer_currency_costs.currency.symbol,
814+
estimation.employer_currency_costs.currency.code,
815815
),
816816
zendeskId: item.zendesk_article_id || undefined,
817817
tooltip: item.description || undefined,
@@ -822,11 +822,11 @@ export const EstimationResults = ({
822822
label: 'Benefits',
823823
regionalAmount: formatCurrency(
824824
estimation.regional_currency_costs.annual_benefits_total,
825-
estimation.regional_currency_costs.currency.symbol,
825+
estimation.regional_currency_costs.currency.code,
826826
),
827827
employerAmount: formatCurrency(
828828
estimation.employer_currency_costs.annual_benefits_total,
829-
estimation.employer_currency_costs.currency.symbol,
829+
estimation.employer_currency_costs.currency.code,
830830
),
831831
children:
832832
estimation.employer_currency_costs.annual_benefits_breakdown?.map(
@@ -835,11 +835,11 @@ export const EstimationResults = ({
835835
regionalAmount: formatCurrency(
836836
estimation.regional_currency_costs
837837
.annual_benefits_breakdown?.[index]?.amount,
838-
estimation.regional_currency_costs.currency.symbol,
838+
estimation.regional_currency_costs.currency.code,
839839
),
840840
employerAmount: formatCurrency(
841841
item.amount,
842-
estimation.employer_currency_costs.currency.symbol,
842+
estimation.employer_currency_costs.currency.code,
843843
),
844844
zendeskId: item.zendesk_article_id || undefined,
845845
tooltip: item.description || undefined,
@@ -851,12 +851,12 @@ export const EstimationResults = ({
851851
regionalAmount: formatCurrency(
852852
estimation.regional_currency_costs
853853
.extra_statutory_payments_total,
854-
estimation.regional_currency_costs.currency.symbol,
854+
estimation.regional_currency_costs.currency.code,
855855
),
856856
employerAmount: formatCurrency(
857857
estimation.employer_currency_costs
858858
.extra_statutory_payments_total,
859-
estimation.employer_currency_costs.currency.symbol,
859+
estimation.employer_currency_costs.currency.code,
860860
),
861861
children:
862862
estimation.employer_currency_costs.extra_statutory_payments_breakdown?.map(
@@ -865,11 +865,11 @@ export const EstimationResults = ({
865865
regionalAmount: formatCurrency(
866866
estimation.regional_currency_costs
867867
.extra_statutory_payments_breakdown?.[index]?.amount,
868-
estimation.regional_currency_costs.currency.symbol,
868+
estimation.regional_currency_costs.currency.code,
869869
),
870870
employerAmount: formatCurrency(
871871
item.amount,
872-
estimation.employer_currency_costs.currency.symbol,
872+
estimation.employer_currency_costs.currency.code,
873873
),
874874
zendeskId: item.zendesk_article_id || undefined,
875875
tooltip: item.description || undefined,
@@ -883,12 +883,12 @@ export const EstimationResults = ({
883883
regionalAmount: formatCurrency(
884884
estimation.regional_currency_costs
885885
.annual_management_fee,
886-
estimation.regional_currency_costs.currency.symbol,
886+
estimation.regional_currency_costs.currency.code,
887887
),
888888
employerAmount: formatCurrency(
889889
estimation.employer_currency_costs
890890
.annual_management_fee,
891-
estimation.employer_currency_costs.currency.symbol,
891+
estimation.employer_currency_costs.currency.code,
892892
),
893893
tooltip:
894894
'Discounts may be available based on your commitment and team size. Speak to your account or customer success manager to learn more.',

src/flows/CostCalculator/SummaryResults/SummaryResults.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const useSummaryResults = (estimations: CostCalculatorEstimation[]) => {
4949
const groupedCostsPerCountry = Object.values(costsPerCountry).map(
5050
({ country, monthlyTotal, annualTotal }) => ({
5151
country,
52-
monthlyCost: formatCurrency(monthlyTotal, currency.symbol),
53-
annualCost: formatCurrency(annualTotal, currency.symbol),
52+
monthlyCost: formatCurrency(monthlyTotal, currency.code),
53+
annualCost: formatCurrency(annualTotal, currency.code),
5454
}),
5555
);
5656

@@ -59,13 +59,13 @@ const useSummaryResults = (estimations: CostCalculatorEstimation[]) => {
5959
estimations.reduce((acc, estimation) => {
6060
return acc + estimation.employer_currency_costs.monthly_total;
6161
}, 0),
62-
currency.symbol,
62+
currency.code,
6363
),
6464
annualTotal: formatCurrency(
6565
estimations.reduce((acc, estimation) => {
6666
return acc + estimation.employer_currency_costs.annual_total;
6767
}, 0),
68-
currency.symbol,
68+
currency.code,
6969
),
7070
};
7171
return { currency, costsPerCountry: groupedCostsPerCountry, employeesCost };

src/flows/CostCalculator/tests/EstimationResults.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('EstimationResults', () => {
159159
// Check if annual gross salary is rendered
160160
const formattedSalary = formatCurrency(
161161
mockEstimation.regional_currency_costs.annual_gross_salary,
162-
mockEstimation.regional_currency_costs.currency.symbol,
162+
mockEstimation.regional_currency_costs.currency.code,
163163
);
164164

165165
const salaryContainer = screen.getByTestId(
@@ -209,11 +209,11 @@ describe('EstimationResults', () => {
209209
// Check monthly total amounts
210210
const monthlyRegionalTotal = formatCurrency(
211211
mockEstimation.regional_currency_costs.monthly_total,
212-
mockEstimation.regional_currency_costs.currency.symbol,
212+
mockEstimation.regional_currency_costs.currency.code,
213213
);
214214
const monthlyEmployerTotal = formatCurrency(
215215
mockEstimation.employer_currency_costs.monthly_total,
216-
mockEstimation.employer_currency_costs.currency.symbol,
216+
mockEstimation.employer_currency_costs.currency.code,
217217
);
218218

219219
expect(screen.getByText(monthlyRegionalTotal)).toBeInTheDocument();
@@ -284,12 +284,12 @@ describe('EstimationResults', () => {
284284
const expectedRegionalAmount = formatCurrency(
285285
mockEstimation.regional_currency_costs.monthly_benefits_breakdown[0]
286286
.amount,
287-
mockEstimation.regional_currency_costs.currency.symbol,
287+
mockEstimation.regional_currency_costs.currency.code,
288288
);
289289
const expectedEmployerAmount = formatCurrency(
290290
mockEstimation.employer_currency_costs.monthly_benefits_breakdown[0]
291291
.amount,
292-
mockEstimation.employer_currency_costs.currency.symbol,
292+
mockEstimation.employer_currency_costs.currency.code,
293293
);
294294

295295
// Find the amounts in the document
@@ -299,11 +299,11 @@ describe('EstimationResults', () => {
299299
// Also verify the total core benefits
300300
const totalRegionalAmount = formatCurrency(
301301
mockEstimation.regional_currency_costs.monthly_benefits_total,
302-
mockEstimation.regional_currency_costs.currency.symbol,
302+
mockEstimation.regional_currency_costs.currency.code,
303303
);
304304
const totalEmployerAmount = formatCurrency(
305305
mockEstimation.employer_currency_costs.monthly_benefits_total,
306-
mockEstimation.employer_currency_costs.currency.symbol,
306+
mockEstimation.employer_currency_costs.currency.code,
307307
);
308308

309309
expect(screen.getByText(totalRegionalAmount)).toBeInTheDocument();

src/lib/__tests__/utils.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { JSFFields } from '@/src/types/remoteFlows';
22
import {
3+
formatCurrency,
34
prettifyFormValues,
45
sanitizeHtml,
56
sanitizeHtmlWithImageErrorHandling,
@@ -350,4 +351,27 @@ describe('utils lib', () => {
350351
});
351352
});
352353
});
354+
355+
describe('formatCurrency', () => {
356+
it('should return "-" for undefined or null amount', () => {
357+
expect(formatCurrency(null)).toBe('-');
358+
expect(formatCurrency(undefined)).toBe('-');
359+
});
360+
361+
it('should format amount in EUR by default', () => {
362+
expect(formatCurrency(5000)).toBe('€50.00');
363+
});
364+
365+
it('should format amount in specified currency', () => {
366+
expect(formatCurrency(10000, 'USD')).toBe('$100.00');
367+
});
368+
369+
it('should format amount with currency code', () => {
370+
expect(formatCurrency(10000, 'ARS')).toBe('ARS\u00A0100.00');
371+
});
372+
373+
it('should handle zero amount', () => {
374+
expect(formatCurrency(0, 'USD')).toBe('$0.00');
375+
});
376+
});
353377
});

0 commit comments

Comments
 (0)