Skip to content

Commit

Permalink
fix: display concardis direct debit form on checkout payment page (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrueber authored May 19, 2020
1 parent a951e27 commit 30444ef
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/app/core/models/payment-method/payment-method.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ describe('Payment Method Mapper', () => {
name: 'BIC',
type: 'string',
},
{
displayName: 'paymentMethodId',
hidden: true,
name: 'paymentMethodId',
type: 'string',
},
];

it(`should return PaymentMethod when getting a PaymentMethodData`, () => {
Expand Down Expand Up @@ -119,20 +125,23 @@ describe('Payment Method Mapper', () => {
const paymentMethod = PaymentMethodMapper.fromData(paymentMethodData)[0];

expect(paymentMethod.saveAllowed).toBeTrue();
expect(paymentMethod.parameters).toHaveLength(3);
expect(paymentMethod.parameters).toHaveLength(4);
expect(paymentMethod.parameters[0].type).toEqual('input');
expect(paymentMethod.parameters[0].key).toEqual('holder');
expect(paymentMethod.parameters[0].hide).toBeFalse();
expect(paymentMethod.parameters[0].templateOptions.type).toEqual('text');
expect(paymentMethod.parameters[0].templateOptions.required).toBeTrue();

expect(paymentMethod.parameters[1].templateOptions.pattern).toBe(regexp);
expect(paymentMethod.parameters[1].templateOptions.minLength).toBe(15);
expect(paymentMethod.parameters[1].templateOptions.maxLength).toBe(34);
expect(paymentMethod.parameters[1].templateOptions.attributes).toBeObject();

expect(paymentMethod.parameters[3].hide).toBeTrue();
});
});

describe('fromOptions', () => {
describe('Payment Method Mapper', () => {
const paymentMethodsData = {
payments: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class PaymentMethodMapper {
: undefined,
attributes: {},
},
hide: p.hidden,
};

if (p.constraints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class PaymentConcardisDirectdebitComponent extends PaymentConcardisCompon
* hide fields without labels and enrich mandate reference and mandate text with corresponding values from hosted payment page parameters
*/
getFieldConfig(): FormlyFieldConfig[] {
return this.paymentMethod.parameters.map(param => (!param.templateOptions.label ? this.modifyParam(param) : param));
return this.paymentMethod.parameters.map(param => (param.hide ? this.modifyParam(param) : param));
}

private modifyParam(p: FormlyFieldConfig): FormlyFieldConfig {
Expand All @@ -85,7 +85,7 @@ export class PaymentConcardisDirectdebitComponent extends PaymentConcardisCompon
if (param.key === 'mandateReference') {
param.defaultValue = this.getParamValue('mandateId', '');
}
param.hide = true;

if (param.key === 'mandateText') {
param.type = 'checkbox';
param.fieldGroupClassName = 'offset-md-4 col-md-8';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ish-input
*ngIf="field && field.templateOptions"
*ngIf="field && field.templateOptions && !field.hide"
[form]="form"
[controlName]="field.key"
[type]="field.templateOptions.type"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ish-select
*ngIf="field && field.templateOptions"
*ngIf="field && field.templateOptions && !field.hide"
[form]="form"
[controlName]="field.key"
[label]="field.templateOptions.label"
Expand Down
30 changes: 30 additions & 0 deletions src/app/shared/forms-dynamic/forms-dynamic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ describe('Forms Dynamic', () => {
expect(element.querySelector('ish-input')).toBeTruthy();
});

it('should not display dynamic input when supplied as field but hide option is true', () => {
component.fields = [
{
key: 'text',
type: 'input',
hide: true,
templateOptions: {
type: 'text',
},
},
];

fixture.detectChanges();
expect(element.querySelector('ish-input')).toBeFalsy();
});

it('should display dynamic select when supplied as field', () => {
component.fields = [
{
Expand All @@ -73,6 +89,20 @@ describe('Forms Dynamic', () => {
expect(element.querySelector('ish-select')).toBeTruthy();
});

it('should display dynamic select when supplied as field but hide option is true', () => {
component.fields = [
{
key: 'text',
type: 'select',
hide: true,
templateOptions: {},
},
];

fixture.detectChanges();
expect(element.querySelector('ish-select')).toBeFalsy();
});

it('should display dynamic checkbox when supplied as field', () => {
component.fields = [
{
Expand Down

0 comments on commit 30444ef

Please sign in to comment.