From 21dfa1529916fdd9ee406b079155eea080d3be03 Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Thu, 5 May 2022 13:51:48 -0400 Subject: [PATCH 1/3] When we open the product config modal directly without going to the designation landing page, the productConfig.modal.component.js is called before productConfigForm.component.js, which is where the code to set the default campaign code happens. This puts the logic in both places so it works regardless of the route the donor chooses to take. --- .../productConfig.modal.component.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/app/productConfig/productConfigModal/productConfig.modal.component.js b/src/app/productConfig/productConfigModal/productConfig.modal.component.js index 1f754b2d8..5939126df 100644 --- a/src/app/productConfig/productConfigModal/productConfig.modal.component.js +++ b/src/app/productConfig/productConfigModal/productConfig.modal.component.js @@ -4,6 +4,7 @@ import isArray from 'lodash/isArray' import productConfigForm from '../productConfigForm/productConfigForm.component' import { giveGiftParams } from '../giveGiftParams' import modalStateService from 'common/services/modalState.service' +import designationsService from 'common/services/api/designations.service' import { mobileBreakpoint } from 'common/app.constants' import template from './productConfig.modal.tpl.html' @@ -12,10 +13,11 @@ const componentName = 'productConfigModal' class ProductConfigModalController { /* @ngInject */ - constructor ($window, $location, modalStateService) { + constructor ($window, $location, modalStateService, designationsService) { this.$window = $window this.$location = $location this.modalStateService = modalStateService + this.designationsService = designationsService } $onInit () { @@ -72,6 +74,10 @@ class ProductConfigModalController { this.itemConfig['recurring-start-month'] = params[giveGiftParams.month] } + if (Object.prototype.hasOwnProperty.call(params, giveGiftParams.campaignPage) && params[giveGiftParams.campaignPage] !== '') { + this.itemConfig['campaign-page'] = params[giveGiftParams.campaignPage] + } + // If CampaignCode exists in URL, use it, otherwise use default-campaign-code if set. if (Object.prototype.hasOwnProperty.call(params, giveGiftParams.campaignCode)) { this.itemConfig['campaign-code'] = isArray(params[giveGiftParams.campaignCode]) @@ -84,10 +90,12 @@ class ProductConfigModalController { } } else if (Object.prototype.hasOwnProperty.call(this.itemConfig, 'default-campaign-code')) { this.itemConfig['campaign-code'] = this.itemConfig['default-campaign-code'] - } - - if (Object.prototype.hasOwnProperty.call(params, giveGiftParams.campaignPage) && params[giveGiftParams.campaignPage] !== '') { - this.itemConfig['campaign-page'] = params[giveGiftParams.campaignPage] + } else if (this.itemConfig['campaign-page']) { + // make sure we call the code to pull the default campaign code when going straight to the modal + this.designationsService.suggestedAmounts(this.code, this.itemConfig) + .subscribe(null, null, () => { + this.itemConfig['campaign-code'] = this.itemConfig['default-campaign-code'] + }) } } @@ -114,7 +122,8 @@ export default angular .module(componentName, [ 'ordinal', productConfigForm.name, - modalStateService.name + modalStateService.name, + designationsService.name ]) .component(componentName, { controller: ProductConfigModalController, From 9003129a5b96f7c494213a8b06d4325295624419 Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Thu, 5 May 2022 16:37:27 -0400 Subject: [PATCH 2/3] Add a new test --- .../productConfig.modal.component.spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/app/productConfig/productConfigModal/productConfig.modal.component.spec.js b/src/app/productConfig/productConfigModal/productConfig.modal.component.spec.js index e7070b857..051f1ddae 100644 --- a/src/app/productConfig/productConfigModal/productConfig.modal.component.spec.js +++ b/src/app/productConfig/productConfigModal/productConfig.modal.component.spec.js @@ -4,6 +4,7 @@ import module from './productConfig.modal.component' import { giveGiftParams } from '../giveGiftParams' import 'rxjs/add/observable/of' import 'rxjs/add/observable/throw' +import { Observable } from 'rxjs/Observable' describe('product config modal', function () { beforeEach(angular.mock.module(module.name)) @@ -21,6 +22,9 @@ describe('product config modal', function () { }, modalStateService: { name: jest.fn() + }, + designationsService: { + suggestedAmounts: jest.fn() } }, { @@ -79,6 +83,7 @@ describe('product config modal', function () { describe('initializeParams', () => { beforeEach(() => { jest.spyOn($ctrl, 'updateQueryParam').mockImplementation(() => {}) + jest.spyOn($ctrl.designationsService, 'suggestedAmounts').mockReturnValue(Observable.of([])) $ctrl.itemConfig = {} }) @@ -157,6 +162,18 @@ describe('product config modal', function () { expect($ctrl.itemConfig['campaign-code']).toEqual('DEFAULT') }) + it('sets the campaignCode from default-campaign-code if opening from modal directly', () => { + $ctrl.itemConfig['campaign-page'] = 'some-page' + + jest.spyOn($ctrl.designationsService, 'suggestedAmounts').mockImplementation(() => { + $ctrl.itemConfig['default-campaign-code'] = 'DEFAULT' + return Observable.from([]) + }) + expect($ctrl.itemConfig['campaign-code']).toBeUndefined() + $ctrl.initializeParams() + expect($ctrl.itemConfig['campaign-code']).toEqual('DEFAULT') + }) + it('cleans campaignCode if containing invalid characters', () => { $ctrl.$location.search.mockReturnValue({ [giveGiftParams.campaignCode]: 'LEGACY?vid=3408342..fj039jf08ajs&kdljfi3lniclisgw5DFS4' From 1e937c78370d800c9a72def216183514a8fe35b4 Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Thu, 5 May 2022 16:53:56 -0400 Subject: [PATCH 3/3] Add version file for asdf (unrelated to this task, but small and annoying to keep having to specify which files to add) --- .tool-versions | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 000000000..1c39cf3f8 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +nodejs 16.0.0 +yarn 1.22.17