Skip to content

Commit

Permalink
Merge pull request #197 from BoomTech-LLC/staging
Browse files Browse the repository at this point in the history
Staging -> main
  • Loading branch information
Tigran0199 authored Sep 17, 2024
2 parents 727ad62 + 1808acc commit 053f592
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- name: Install dependencies
run: npm install

- name: Checking test cases
run: npm run test

- name: Build
run: npm run build

Expand Down
3 changes: 2 additions & 1 deletion src/Body/Fields/MultipleChoice/Item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const Item = ({ id, options, option, quantity, payment, classnameprefix }) => {
label +
formatPrice({
payment,
price
price,
shouldFormat: true
})
}}
></span>
Expand Down
2 changes: 1 addition & 1 deletion src/Body/Fields/Phone/DropDown/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const List = ({
<div
className='country_code_item_img'
style={{
backgroundImage: `url(https://cdn.boomte.ch/images/flags/${key.toLowerCase()}.svg)`,
backgroundImage: `url(https://form.boomte.ch/images/flags/${key.toLowerCase()}.svg)`,
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat'
}}
Expand Down
3 changes: 2 additions & 1 deletion src/Body/Fields/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const DropDown = ({
newOptions.map((option) => {
if (option.label)
option.label =
option.label + formatPrice({ payment, price: option.price })
option.label +
formatPrice({ payment, price: option.price, shouldFormat: true })
})

set_Options(newOptions)
Expand Down
12 changes: 9 additions & 3 deletions src/Body/Fields/Signature/Signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import React, { useState, useEffect, useCallback, Fragment, useRef } from 'react
import SignatureCanvas from 'react-signature-canvas'
import { Custom, Input } from 'boomform'

const Signature = (props) => {
const { id, initial, validation, clearBtnContent = 'Clear' } = props
const Signature = props => {
const {
id,
initial,
validation,
clearBtnContent = 'Clear',
classnameprefix
} = props
const [sigPadRef, setSigPadRef] = useState(null)
const canvasContainerRef = useRef(null)
const [canvasWidth, setCanvasWidth] = useState(0)
Expand All @@ -21,7 +27,7 @@ const Signature = (props) => {
return () => {
window.removeEventListener('resize', getParentWidth)
}
}, [])
}, [classnameprefix])

useEffect(() => {
if (initial && sigPadRef) sigPadRef.fromData(initial.data)
Expand Down
3 changes: 2 additions & 1 deletion src/Body/Fields/SingleChoice/Item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const Item = ({ id, option, payment, classnameprefix, validation }) => {
label +
formatPrice({
payment,
price
price,
shouldFormat: true
})
}}
></span>
Expand Down
20 changes: 18 additions & 2 deletions src/Helpers/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@ export const currencys = {
NZD: 'NZ$'
}

export const formatPrice = ({ payment, price }) => {
export const formatPrice = ({ payment, price, shouldFormat }) => {
const { showPrices, currency, format, numberFormat } = payment

if (shouldFormat) {
if (
showPrices &&
price !== '' &&
price !== null &&
Number(price) !== NaN &&
price > 0
) {
return (
' ' +
format
.toString()
.replace('100', price)
.replace('$', currencys[currency])
)
} else return ''
}
if (
showPrices &&
price !== '' &&
Expand Down
85 changes: 73 additions & 12 deletions src/__tests/payment.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatPrice, getTotalPrice } from '../Helpers/payment';
import { formatPrice, getTotalPrice } from '../Helpers/payment'

describe('formatPrice({ payment, price })', () => {
it('should return formatted string when valid values are passed ', () => {
Expand All @@ -11,7 +11,7 @@ describe('formatPrice({ payment, price })', () => {
},
price: 15
})
).toBe(' 15€');
).toBe(' 15€')
expect(
formatPrice({
payment: {
Expand All @@ -21,7 +21,7 @@ describe('formatPrice({ payment, price })', () => {
},
price: 15
})
).toBe(' 15$');
).toBe(' 15$')
expect(
formatPrice({
payment: {
Expand All @@ -31,8 +31,8 @@ describe('formatPrice({ payment, price })', () => {
},
price: 15
})
).toBe(' 15HK$');
});
).toBe(' 15HK$')
})
it('should return an empty string or non-correct values when invalid values are passed', () => {
expect(
formatPrice({
Expand All @@ -43,7 +43,7 @@ describe('formatPrice({ payment, price })', () => {
},
price: 20
})
).toBe('');
).toBe('')
expect(
formatPrice({
payment: {
Expand All @@ -53,7 +53,7 @@ describe('formatPrice({ payment, price })', () => {
},
price: 20
})
).toBe(' 20undefined');
).toBe(' 20undefined')
expect(
formatPrice({
payment: {
Expand All @@ -63,7 +63,7 @@ describe('formatPrice({ payment, price })', () => {
},
price: 20
})
).toBe(' 20');
).toBe(' 20')
expect(
formatPrice({
payment: {
Expand All @@ -73,7 +73,7 @@ describe('formatPrice({ payment, price })', () => {
},
price: 20
})
).toBe(' 10CA$');
).toBe(' 10CA$')
expect(
formatPrice({
payment: {
Expand All @@ -83,6 +83,67 @@ describe('formatPrice({ payment, price })', () => {
},
price: 0
})
).toBe('');
});
});
).toBe('')
})
it('should return correctly formatted prices based on numberFormat', () => {
expect(
formatPrice({
payment: {
showPrices: true,
currency: 'USD',
format: '100$',
numberFormat: '10,000.00'
},
price: 12345.67
})
).toBe(' 12,345.67$')

expect(
formatPrice({
payment: {
showPrices: true,
currency: 'EUR',
format: '100$',
numberFormat: '10 000'
},
price: 12345
})
).toBe(' 12 345€')

expect(
formatPrice({
payment: {
showPrices: true,
currency: 'GBP',
format: '100$',
numberFormat: '10.000'
},
price: 12345
})
).toBe(' 12.345£')

expect(
formatPrice({
payment: {
showPrices: true,
currency: 'USD',
format: '100$',
numberFormat: '10K'
},
price: 12345
})
).toBe(' 12K$')

expect(
formatPrice({
payment: {
showPrices: true,
currency: 'USD',
format: '100$',
numberFormat: '10k'
},
price: 12345
})
).toBe(' 12k$')
})
})

0 comments on commit 053f592

Please sign in to comment.