|
1 | | -<button mat-raised-button color="primary" (click)="onAdd()"> |
| 1 | +<button mat-raised-button color="primary" (click)="onAdd()" data-testid="add-word-button"> |
2 | 2 | Add another word |
3 | 3 | </button> |
4 | 4 |
|
5 | 5 | <mat-form-field appearance="fill"> |
6 | 6 | <mat-label>Max number</mat-label> |
7 | | - <input matInput type="number" [formControl]="formGroup.controls.maxNumber" placeholder="100" required> |
| 7 | + <input |
| 8 | + matInput |
| 9 | + type="number" |
| 10 | + [formControl]="formGroup.controls.maxNumber" |
| 11 | + placeholder="100" |
| 12 | + required |
| 13 | + data-testid="input-max-number" /> |
8 | 14 | </mat-form-field> |
9 | 15 |
|
10 | | -@for(group of formGroup.controls.multiples.controls; track group) { |
| 16 | +@for(group of formGroup.controls.multiples.controls; let idx = $index; track group) { |
11 | 17 | <div class="content"> |
12 | 18 | <button mat-fab (click)="onRemove(group)"><mat-icon>delete</mat-icon></button> |
13 | 19 | <mat-form-field appearance="fill"> |
14 | 20 | <mat-label>Word to print</mat-label> |
15 | | - <input matInput type="text" [formControl]="group.controls.wordToPrint" placeholder="Fizz" required |
16 | | - [maxLength]="30" /> |
| 21 | + <input |
| 22 | + matInput type="text" |
| 23 | + [formControl]="group.controls.wordToPrint" |
| 24 | + placeholder="Fizz" |
| 25 | + required |
| 26 | + [maxLength]="30" |
| 27 | + [attr.data-testid]="'input-word-' + idx"/> |
17 | 28 | @if (group.controls.wordToPrint.errors){ |
18 | 29 | <mat-error> |
19 | 30 | Please enter a valid word |
|
22 | 33 | </mat-form-field> |
23 | 34 | <mat-form-field appearance="fill"> |
24 | 35 | <mat-label>Multiple</mat-label> |
25 | | - <input matInput type="number" [min]="1" [formControl]="group.controls.multiple" placeholder="3" required /> |
| 36 | + <input |
| 37 | + matInput |
| 38 | + type="number" |
| 39 | + [min]="1" |
| 40 | + [formControl]="group.controls.multiple" |
| 41 | + placeholder="3" |
| 42 | + required |
| 43 | + [attr.data-testid]="'input-multiple-' + idx" /> |
26 | 44 | @if (group.controls.multiple.errors?.['required'] || group.controls.multiple.errors?.['min']) { |
27 | | - <mat-error> |
| 45 | + <mat-error [attr.data-testid]="'error-required-multiple' + idx"> |
28 | 46 | Please valid a number |
29 | 47 | </mat-error> |
30 | 48 | } |
31 | 49 | @else if (group.controls.multiple.errors?.['duplicates']) { |
32 | | - <mat-error>Duplicate number</mat-error> |
| 50 | + <mat-error [attr.data-testid]="'error-required-duplicate' + idx">Duplicate number</mat-error> |
33 | 51 | } |
34 | 52 | </mat-form-field> |
35 | 53 | <br /> |
36 | 54 | </div> |
37 | 55 | } |
38 | 56 |
|
39 | | -<button mat-raised-button color="primary" (click)="onSubmit()" [disabled]="!formGroup.valid"> |
| 57 | +<button mat-raised-button color="primary" (click)="onSubmit()" [disabled]="!formGroup.valid" data-testid="submit-button"> |
40 | 58 | Submit |
41 | 59 | </button> |
42 | 60 |
|
43 | 61 | @if (formGroup.controls.multiples.errors) { |
44 | 62 | @if (formGroup.controls.multiples.errors['required']) { |
45 | | - <mat-error> |
| 63 | + <mat-error data-testid="error-required-multiples"> |
46 | 64 | Please add at least two words |
47 | 65 | </mat-error> |
48 | 66 | } |
|
0 commit comments