Skip to content

Commit

Permalink
Merge branch 'fix-0-dollars-giving-options' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Sep 8, 2023
2 parents 0bf6765 + 4d72dc5 commit ffcb82d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ModalInstanceCtrl {
this.facebookPixelId = facebookPixelId

this.suggestedAmounts = transform(suggestedAmounts, (result, value, key) => {
if (key === 'jcr:primaryType') { return }
if (key === 'jcr:primaryType' || !value?.amount) return
result.push({
amount: Number(value.amount),
description: value.description,
Expand All @@ -23,9 +23,9 @@ class ModalInstanceCtrl {
}

transformSuggestedAmounts () {
return transform(this.suggestedAmounts, (result, value, i) => {
const filterOutZeroAmounts = this.suggestedAmounts.filter((amount) => amount?.amount)
return transform(filterOutZeroAmounts, (result, value, i) => {
delete value.order
value.amount = value.amount || 0
result[i + 1] = value
}, {})
}
Expand Down
24 changes: 23 additions & 1 deletion src/app/designationEditor/pageOptionsModal/pageOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('Designation Editor Page Options', function () {
facebookPixelId: '635334562464',
suggestedAmounts: { 'jcr:primaryType': 'nt:unstructured',
1: { 'jcr:primaryType': 'nt:unstructured', description: '1 Bible', amount: 100 },
2: { 'jcr:primaryType': 'nt:unstructured', description: '2 Bibles', amount: 200 } },
2: { 'jcr:primaryType': 'nt:unstructured', description: '2 Bibles', amount: 200 },
3: { 'jcr:primaryType': 'nt:unstructured', description: '2 Bibles', amount: 0 },
4: { }, },
$scope: $scope
})
}))
Expand All @@ -42,4 +44,24 @@ describe('Designation Editor Page Options', function () {
2: { amount: 200, description: '2 Bibles' }
})
})

it('should remove zero or empty objects', function () {
$ctrl.suggestedAmounts.push({
amount: 0,
description: '3 Bibles',
});
$ctrl.suggestedAmounts.push({
amount: 400,
description: '4 Bibles',
});
$ctrl.suggestedAmounts.push({ description: '5 Bibles' });

expect($ctrl.transformSuggestedAmounts()).toEqual({
1: { amount: 100, description: '1 Bible' },
2: { amount: 200, description: '2 Bibles' },
3: { amount: 400, description: '4 Bibles' }
})
})


})
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ProductConfigFormController {

const suggestedAmountsObservable = this.designationsService.suggestedAmounts(this.code, this.itemConfig)
.do(suggestedAmounts => {
this.suggestedAmounts = suggestedAmounts
this.suggestedAmounts = suggestedAmounts.filter((amount) => amount?.amount)
this.useSuggestedAmounts = !isEmpty(this.suggestedAmounts)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('product config form component', function () {

jest.spyOn($ctrl.commonService, 'getNextDrawDate').mockReturnValue(Observable.of('2016-10-02'))

jest.spyOn($ctrl.designationsService, 'suggestedAmounts').mockReturnValue(Observable.of([{ amount: 5 }, { amount: 10 }]))
jest.spyOn($ctrl.designationsService, 'suggestedAmounts').mockReturnValue(Observable.of([{ amount: 5 }, { amount: 10 }, , { amount: 0 }, , { }]))

jest.spyOn($ctrl.designationsService, 'givingLinks').mockReturnValue(Observable.of([]))
jest.spyOn($ctrl.analyticsFactory, 'giveGiftModal').mockReturnValue(() => {})
Expand Down Expand Up @@ -231,6 +231,19 @@ describe('product config form component', function () {
})
})


describe('loadData but suggestedAmounts only has 0 amounts or empty objects', () => {
beforeEach(() => {
jest.spyOn($ctrl.designationsService, 'suggestedAmounts').mockReturnValue(Observable.of([{ amount: 0 }, , { }]))
})

it('should use default amounts', () => {
$ctrl.loadData()
expect($ctrl.suggestedAmounts).toEqual([])
expect($ctrl.useSuggestedAmounts).toEqual(false)
})
})

describe('setDefaultAmount', () => {
beforeEach(() => {
$ctrl.itemConfig = {}
Expand Down

0 comments on commit ffcb82d

Please sign in to comment.