@dsivd/prestations-ng 19.2.0-beta.13 → 19.2.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GOOD_PRACTICES.md +71 -2
- package/UPGRADING_V19.md +4 -2
- package/package.json +1 -1
package/GOOD_PRACTICES.md
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
- [Example with foehn-input-date of prestations-ng](good-practices#example_with_foehn-input-date_of_prestations-ng)
|
|
34
34
|
- [Displaying the global validation of the component](good-practices#displaying_the_global_validation_of_the_component)
|
|
35
35
|
- [Avoiding error display problems in a `@for` loop](good-practices#avoiding_error_display_problems_in_a__code__for__code__loop)
|
|
36
|
+
- [Types of the form fields](good-practices#types_of_the_form_fields)
|
|
36
37
|
- [Form validation](good-practices#form_validation)
|
|
37
38
|
- [Standard handling](good-practices#standard_handling)
|
|
38
39
|
- [Manual handling](good-practices#manual_handling)
|
|
@@ -471,6 +472,9 @@ ngOnInit(): void {
|
|
|
471
472
|
}
|
|
472
473
|
```
|
|
473
474
|
|
|
475
|
+
If a service fills the form for the page, the page must still be notified: let the service return an
|
|
476
|
+
`Observable` (or take a callback), and call `markForCheck()` in the page.
|
|
477
|
+
|
|
474
478
|
### Deriving a state from view queries
|
|
475
479
|
|
|
476
480
|
> ⚠️ A field read by the template and modified in `ngAfterViewInit()`, `ngAfterContentInit()` or
|
|
@@ -552,8 +556,20 @@ it('should display the details', async () => {
|
|
|
552
556
|
});
|
|
553
557
|
```
|
|
554
558
|
|
|
555
|
-
`await fixture.whenStable()` also waits for the pending tasks, such as the
|
|
556
|
-
doesn't end before them (otherwise
|
|
559
|
+
`await fixture.whenStable()` also waits for the pending tasks of the application, such as the debounced
|
|
560
|
+
`userInput` of the prestations-ng inputs: the test doesn't end before them (otherwise
|
|
561
|
+
`NG0205: Injector has already been destroyed`). But it doesn't wait for the HTTP requests of a spec:
|
|
562
|
+
`provideHttpClientTesting()` keeps them pending until the test answers them. Answer them first with
|
|
563
|
+
`HttpTestingController`, then `await fixture.whenStable()`:
|
|
564
|
+
|
|
565
|
+
```ts
|
|
566
|
+
it('should display the reference of the demand', async () => {
|
|
567
|
+
httpMock.expectOne('api/demande/1').flush({ reference: 'DEM-1' });
|
|
568
|
+
await fixture.whenStable();
|
|
569
|
+
|
|
570
|
+
expect(fixture.nativeElement.textContent).toContain('DEM-1');
|
|
571
|
+
});
|
|
572
|
+
```
|
|
557
573
|
|
|
558
574
|
Keep `fixture.detectChanges()` for:
|
|
559
575
|
|
|
@@ -1269,6 +1285,59 @@ export class DemandePageComponent
|
|
|
1269
1285
|
}
|
|
1270
1286
|
```
|
|
1271
1287
|
|
|
1288
|
+
## Types of the form fields
|
|
1289
|
+
|
|
1290
|
+
> ℹ️ `AbstractPageComponent` replaces `form` with the JSON sent by the backend, as is: at runtime, a field has
|
|
1291
|
+
> the type of the JSON written from the Java model, whatever its TypeScript type says.
|
|
1292
|
+
|
|
1293
|
+
Give the Java field the type matching the model of the component:
|
|
1294
|
+
|
|
1295
|
+
| Component | TypeScript model | Java field |
|
|
1296
|
+
| ------------------------------------------------------------------ | -------------------- | -------------------------------------- |
|
|
1297
|
+
| `foehn-input-text`, `foehn-input-textarea`, `foehn-input-email`... | `string` | `String` |
|
|
1298
|
+
| `foehn-input-time` | `string` | `String` with `@ValidStringTime` |
|
|
1299
|
+
| `foehn-input-date` | `(number \| null)[]` | `LenientLocalDate` |
|
|
1300
|
+
| `foehn-input-date-time` | `(number \| null)[]` | `LenientLocalDateTime` |
|
|
1301
|
+
| `foehn-boolean-checkbox`, `foehn-boolean-radio` | `boolean` | `Boolean` |
|
|
1302
|
+
| `foehn-input-number` | `string` | `Integer`, `BigDecimal`... (see below) |
|
|
1303
|
+
|
|
1304
|
+
> ⚠️ The model of `foehn-input-number` is a `string`: the component keeps the input as typed (decimal comma,
|
|
1305
|
+
> leading zeros, number of decimals). But the Java field is a number (`Integer`, `BigDecimal`), which is
|
|
1306
|
+
> written as a number in the JSON. The field holds `'0'` after the input of the user, and `0` once the form
|
|
1307
|
+
> comes back from the backend. The same happens with any component whose model is a `string` bound to a Java
|
|
1308
|
+
> field which isn't a `String`.
|
|
1309
|
+
|
|
1310
|
+
Never test such a field by its truthiness (`!!value`, `if (value)`, `value || ...`): `'0'` is true, `0` is
|
|
1311
|
+
false.
|
|
1312
|
+
|
|
1313
|
+
What **not** to do:
|
|
1314
|
+
|
|
1315
|
+
```ts
|
|
1316
|
+
isAmountFilled(): boolean {
|
|
1317
|
+
// true after the input of '0', false once the form is loaded (0)
|
|
1318
|
+
return !!this.form?.amount;
|
|
1319
|
+
}
|
|
1320
|
+
```
|
|
1321
|
+
|
|
1322
|
+
What **to** do:
|
|
1323
|
+
|
|
1324
|
+
```ts
|
|
1325
|
+
isAmountFilled(): boolean {
|
|
1326
|
+
const amount = this.form?.amount;
|
|
1327
|
+
return amount !== null && amount !== undefined && amount !== '';
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
getTotal(): number {
|
|
1331
|
+
// Number() converts '12.50' as well as 12.5
|
|
1332
|
+
return Number(this.form?.amount ?? 0) + Number(this.form?.fees ?? 0);
|
|
1333
|
+
}
|
|
1334
|
+
```
|
|
1335
|
+
|
|
1336
|
+
> ⚠️ The values of the elements of `foehn-select` and `foehn-checkbox` must have the type of the Java field:
|
|
1337
|
+
> they are compared to the model with `===`. With `'1'` as value of an element and `1` sent by the backend
|
|
1338
|
+
> (`Integer`), no element is selected anymore once the form is loaded, and the component warns that the saved
|
|
1339
|
+
> value no longer exists in the list.
|
|
1340
|
+
|
|
1272
1341
|
## Form validation
|
|
1273
1342
|
|
|
1274
1343
|
> ℹ️ When your form is saved in GESDEM, the `AbstractPageComponent` handles the
|
package/UPGRADING_V19.md
CHANGED
|
@@ -1593,7 +1593,7 @@ then uninstall zone.js:
|
|
|
1593
1593
|
npm uninstall zone.js
|
|
1594
1594
|
```
|
|
1595
1595
|
|
|
1596
|
-
`zone.js`
|
|
1596
|
+
`zone.js` can stay in your `package-lock.json` as an optional peer dependency of `@angular/core`: this is expected. Check
|
|
1597
1597
|
instead that the build of your application no longer outputs a `polyfills` chunk (unless you still have other
|
|
1598
1598
|
polyfills, e.g. `@angular/localize/init`).
|
|
1599
1599
|
|
|
@@ -1671,7 +1671,9 @@ Pay attention to:
|
|
|
1671
1671
|
(`ExpressionChangedAfterItHasBeenCheckedError`). Fix the component (signal, `markForCheck()`) rather than the
|
|
1672
1672
|
test.
|
|
1673
1673
|
- `await fixture.whenStable()` waits for the change detection and for the pending tasks of the application
|
|
1674
|
-
(e.g. the debounced `userInput` of the prestations-ng inputs), not for the timers
|
|
1674
|
+
(e.g. the debounced `userInput` of the prestations-ng inputs), not for the timers, nor for the HTTP requests of a
|
|
1675
|
+
spec: `provideHttpClientTesting()` keeps them pending until the test answers them. Answer them first with
|
|
1676
|
+
`HttpTestingController` (`expectOne(...).flush(...)`), then `await fixture.whenStable()`.
|
|
1675
1677
|
|
|
1676
1678
|
### Last but not least, check if your application is working!!!
|
|
1677
1679
|
|
package/package.json
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"ng-update": {
|
|
40
40
|
"migrations": "./schematics/migration-collection.json"
|
|
41
41
|
},
|
|
42
|
-
"version": "19.2.0-beta.
|
|
42
|
+
"version": "19.2.0-beta.14",
|
|
43
43
|
"module": "fesm2022/dsivd-prestations-ng.mjs",
|
|
44
44
|
"typings": "types/dsivd-prestations-ng.d.ts",
|
|
45
45
|
"exports": {
|