Skip to content

Commit

Permalink
deps: formly 6 update and necessary code adaptions
Browse files Browse the repository at this point in the history
- update to "6.0.0-next.7" as a final Angular 13 compatible version is not yet available

BREAKING CHANGE: Formly 6 upgrade (see [upgrade from 5.0 to 6.0](https://github.com/ngx-formly/ngx-formly/blob/v6.0.0-next.7/UPGRADE-6.0.md) for more details).
  • Loading branch information
Eisie96 committed Feb 1, 2022
1 parent 74724bc commit f01ebbf
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 101 deletions.
15 changes: 4 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@ngrx/store": "13.0.2",
"@ngrx/store-devtools": "13.0.2",
"@nguniversal/express-engine": "13.0.1",
"@ngx-formly/core": "^5.10.23",
"@ngx-formly/core": "^6.0.0-next.7",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"@rx-angular/state": "1.4.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ describe('Lazy Captcha Component', () => {
});

it('should throw an error if there is no control "captcha" in the given form', () => {
component.form = component.form as FormGroup;
delete component.form.controls.captcha;
expect(() => fixture.detectChanges()).toThrowErrorMatchingInlineSnapshot(
`"form control 'captcha' does not exist in the given form for LazyCaptchaComponent"`
);
});

it('should throw an error if there is no control "captchaAction" in the given form', () => {
component.form = component.form as FormGroup;
delete component.form.controls.captchaAction;
expect(() => fixture.detectChanges()).toThrowErrorMatchingInlineSnapshot(
`"form control 'captchaAction' does not exist in the given form for LazyCaptchaComponent"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { AbstractControl, FormGroup, Validators } from '@angular/forms';
import { AbstractControl, FormArray, FormGroup, Validators } from '@angular/forms';
import { Subject } from 'rxjs';
import { switchMapTo, take, takeUntil } from 'rxjs/operators';

Expand Down Expand Up @@ -41,7 +41,7 @@ export class LazyCaptchaComponent implements OnInit, AfterViewInit, OnDestroy {
/**
form containing the captcha form controls
*/
@Input() form: FormGroup;
@Input() form: FormGroup | FormArray;

/**
css Class for rendering the captcha V2 control, default='offset-md-4 col-md-8'
Expand Down Expand Up @@ -85,7 +85,7 @@ export class LazyCaptchaComponent implements OnInit, AfterViewInit, OnDestroy {
const moduleRef = createNgModuleRef(CaptchaV3ComponentModule, this.injector);
const componentRef = this.anchor.createComponent(CaptchaV3Component, { ngModuleRef: moduleRef });

componentRef.instance.parentForm = this.form;
componentRef.instance.parentForm = this.form as FormGroup;
componentRef.changeDetectorRef.markForCheck();
} else if (version === 2) {
this.formControl.setValidators([Validators.required]);
Expand All @@ -100,7 +100,7 @@ export class LazyCaptchaComponent implements OnInit, AfterViewInit, OnDestroy {
const componentRef = this.anchor.createComponent(CaptchaV2Component, { ngModuleRef: moduleRef });

componentRef.instance.cssClass = this.cssClass;
componentRef.instance.parentForm = this.form;
componentRef.instance.parentForm = this.form as FormGroup;
componentRef.changeDetectorRef.markForCheck();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ describe('Direct Order Component', () => {

it('should display form with direct order configuration', () => {
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toMatchInlineSnapshot(`
NodeList [
<formly-field hide-deprecation=""
><ng-component
>TextInputFieldComponent: sku ish-text-input-field { "fieldClass": "col-12", "placeholder":
"shopping_cart.direct_order.item_placeholder", "attributes": { "autocomplete": "on" }, "label":
"", "focus": false, "disabled": false}</ng-component
></formly-field
>,
]
`);
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toMatchInlineSnapshot(`
NodeList [
<formly-field
><ng-component
>TextInputFieldComponent: sku ish-text-input-field { "fieldClass": "col-12", "placeholder":
"shopping_cart.direct_order.item_placeholder", "attributes": { "autocomplete": "on" }, "label":
"", "disabled": false}</ng-component
></formly-field
>,
]
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
</div>
<div class="section d-flex flex-nowrap">
<a (click)="add(); updateContexts()" data-testing-id="add-quickorder-line">{{ to?.addText | translate }}</a>
<a (click)="addMultipleRows(1)" data-testing-id="add-quickorder-line">{{ to?.addText | translate }}</a>
<span class="link-separator"></span>
<a (click)="addMultipleRows(to?.numberMoreRows)">{{ to?.addMoreText | translate: { '0': to?.numberMoreRows } }}</a>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ describe('Quickorder Add Products Form Component', () => {

it('should display form with add products configuration', () => {
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toMatchInlineSnapshot(`
NodeList [
<formly-field hide-deprecation=""
><ish-quickorder-repeat-field></ish-quickorder-repeat-field
></formly-field>,
]
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toMatchInlineSnapshot(`
NodeList [
<formly-field><ish-quickorder-repeat-field></ish-quickorder-repeat-field></formly-field>,
]
`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ describe('Account Addresses Component', () => {
expect(component.preferredAddressesEqual).toBeTruthy();
expect(element.querySelector('div[data-testing-id=preferred-invoice-and-shipping-address]')).toBeTruthy();
expect(
element.querySelectorAll('div[data-testing-id=preferred-invoice-and-shipping-address] formly-field')
element
.querySelector('div[data-testing-id=preferred-invoice-and-shipping-address] formly-field')
.querySelectorAll('formly-field')
).toHaveLength(2);
expect(element.querySelector('div[data-testing-id=preferred-invoice-address]')).toBeFalsy();
expect(element.querySelector('div[data-testing-id=preferred-shipping-address]')).toBeFalsy();
Expand All @@ -148,9 +150,17 @@ describe('Account Addresses Component', () => {

expect(element.querySelector('div[data-testing-id=preferred-invoice-and-shipping-address]')).toBeFalsy();
expect(element.querySelector('div[data-testing-id=preferred-invoice-address]')).toBeTruthy();
expect(element.querySelectorAll('div[data-testing-id=preferred-invoice-address] formly-field')).toHaveLength(1);
expect(
element
.querySelector('div[data-testing-id=preferred-invoice-address] formly-field')
.querySelectorAll('formly-field')
).toHaveLength(1);
expect(element.querySelector('div[data-testing-id=preferred-shipping-address]')).toBeTruthy();
expect(element.querySelectorAll('div[data-testing-id=preferred-shipping-address] formly-field')).toHaveLength(1);
expect(
element
.querySelector('div[data-testing-id=preferred-shipping-address] formly-field')
.querySelectorAll('formly-field')
).toHaveLength(1);
});

it('should not display further addresses if only preferred invoice and shipping addresses are available', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Account Profile Company Component', () => {

it('should display 3 input fields for companyName, companyName2 and taxationID', () => {
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toHaveLength(3);
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toHaveLength(3);
});

it('should emit updateCompanyProfile event if form is valid', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Account Profile Email Component', () => {
it('should display 3 input fields for email, emailConfirmation and password', () => {
fixture.detectChanges();

expect(element.querySelectorAll('formly-field')).toHaveLength(3);
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toHaveLength(3);
});

it('should emit updateEmail event if form is valid', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Account Profile Password Component', () => {

it('should display 3 input fields for oldPassword, password and passwordConfirmation', () => {
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toHaveLength(3);
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toHaveLength(3);
});

it('should emit updatePassword event if form is valid', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { FieldType } from '@ngx-formly/core';
import { FieldType, FieldTypeConfig } from '@ngx-formly/core';

@Component({
selector: 'ish-checkout-review-tac-field',
templateUrl: './checkout-review-tac-field.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CheckoutReviewTacFieldComponent extends FieldType {
formControl: FormControl;

export class CheckoutReviewTacFieldComponent extends FieldType<FieldTypeConfig> {
getArgs() {
return this.to.args ? this.to.args : {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ describe('Checkout Shipping Component', () => {

it('should render available shipping methods on page', () => {
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toHaveLength(1);
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toHaveLength(1);
});

it('should throw updateShippingMethod event when the user changes payment selection', () => {
fixture.detectChanges();

component.shippingForm.get('shippingMethod').setValue('testShipping');

verify(checkoutFacade.updateBasketShippingMethod(anything())).once();
verify(checkoutFacade.updateBasketShippingMethod(anything())).twice();
const [arg] = capture(checkoutFacade.updateBasketShippingMethod).last();
expect(arg).toMatchInlineSnapshot(`"testShipping"`);
});

it('should update basket if current shippingMethod is invalid', () => {
when(checkoutFacade.getValidShippingMethod$()).thenReturn(of('other'));
fixture.detectChanges();
verify(checkoutFacade.updateBasketShippingMethod(anything())).once();
verify(checkoutFacade.updateBasketShippingMethod(anything())).twice();
const [arg] = capture(checkoutFacade.updateBasketShippingMethod).last();
expect(arg).toMatchInlineSnapshot(`"other"`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Contact Form Component', () => {

it('should always render formly form', () => {
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toHaveLength(7);
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toHaveLength(7);
});

it('should not emit contact request when invalid form is submitted', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { FormGroup } from '@angular/forms';
import { FieldType } from '@ngx-formly/core';

@Component({
Expand All @@ -8,8 +8,6 @@ import { FieldType } from '@ngx-formly/core';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RegistrationAddressFieldComponent extends FieldType {
formControl: FormControl;

get parent() {
return this.form as FormGroup;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { FieldType } from '@ngx-formly/core';
import { FieldType, FieldTypeConfig } from '@ngx-formly/core';

@Component({
selector: 'ish-registration-tac-field',
templateUrl: './registration-tac-field.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RegistrationTacFieldComponent extends FieldType {
formControl: FormControl;
}
export class RegistrationTacFieldComponent extends FieldType<FieldTypeConfig> {}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ describe('Registration Page Component', () => {

it('should display form with registration configuration', () => {
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toMatchInlineSnapshot(`
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toMatchInlineSnapshot(`
NodeList [
<formly-field hide-deprecation=""
<formly-field
><ng-component
>TextInputFieldComponent: test ish-text-input-field { "label": "", "placeholder": "", "focus":
false, "disabled": false}</ng-component
>TextInputFieldComponent: test ish-text-input-field { "label": "", "placeholder": "",
"disabled": false}</ng-component
></formly-field
>,
]
Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/registration/registration-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RegistrationConfigType,
RegistrationFormConfigurationService,
} from 'ish-core/services/registration-form-configuration/registration-form-configuration.service';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

/**
* The Registration Page Container renders the customer registration form using the {@link RegistrationFormComponent}
Expand Down Expand Up @@ -56,6 +57,7 @@ export class RegistrationPageComponent implements OnInit {

onCreate() {
if (this.form.invalid) {
markAsDirtyRecursive(this.form);
this.submitted = true;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe('Basket Cost Center Selection Component', () => {
when(checkoutFacade.eligibleCostCenterSelectOptions$()).thenReturn(of([mockCostCenterOptions[0]]));
fixture.detectChanges();

expect(element.querySelectorAll('formly-field')).toHaveLength(1);
expect(element.querySelector('formly-field').textContent).toMatchInlineSnapshot(`
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toHaveLength(1);
expect(element.querySelector('formly-field').querySelector('formly-field').textContent).toMatchInlineSnapshot(`
"SelectFieldComponent: costCenter ish-select-field {
\\"label\\": \\"checkout.cost_center.select.label\\",
\\"required\\": true,
Expand All @@ -81,7 +81,6 @@ describe('Basket Cost Center Selection Component', () => {
}
],
\\"placeholder\\": \\"\\",
\\"focus\\": false,
\\"disabled\\": false
}"
`);
Expand All @@ -91,8 +90,8 @@ describe('Basket Cost Center Selection Component', () => {
when(accountFacade.isBusinessCustomer$).thenReturn(of(true));
when(checkoutFacade.eligibleCostCenterSelectOptions$()).thenReturn(of(mockCostCenterOptions));
fixture.detectChanges();
expect(element.querySelectorAll('formly-field')).toHaveLength(1);
expect(element.querySelector('formly-field').textContent).toMatchInlineSnapshot(`
expect(element.querySelector('formly-field').querySelectorAll('formly-field')).toHaveLength(1);
expect(element.querySelector('formly-field').querySelector('formly-field').textContent).toMatchInlineSnapshot(`
"SelectFieldComponent: costCenter ish-select-field {
\\"label\\": \\"checkout.cost_center.select.label\\",
\\"required\\": true,
Expand All @@ -108,7 +107,6 @@ describe('Basket Cost Center Selection Component', () => {
}
],
\\"placeholder\\": \\"account.option.select.text\\",
\\"focus\\": false,
\\"disabled\\": false
}"
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ describe('Basket Shipping Address Widget Component', () => {
"ish-address",
"formly-form",
"formly-field",
"formly-group",
"formly-field",
"ng-component",
"ish-formly-customer-address-form",
]
Expand All @@ -114,6 +116,8 @@ describe('Basket Shipping Address Widget Component', () => {
"ish-address",
"formly-form",
"formly-field",
"formly-group",
"formly-field",
"ng-component",
"ish-formly-customer-address-form",
]
Expand Down Expand Up @@ -141,6 +145,8 @@ describe('Basket Shipping Address Widget Component', () => {
Array [
"formly-form",
"formly-field",
"formly-group",
"formly-field",
"ng-component",
"ish-formly-customer-address-form",
]
Expand All @@ -163,6 +169,8 @@ describe('Basket Shipping Address Widget Component', () => {
Array [
"formly-form",
"formly-field",
"formly-group",
"formly-field",
"ng-component",
"ish-formly-customer-address-form",
]
Expand Down
Loading

0 comments on commit f01ebbf

Please sign in to comment.