Skip to content

Commit 3c49bf9

Browse files
committed
add test attributess
1 parent 251a457 commit 3c49bf9

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

angular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,8 @@
9999
}
100100
}
101101
}
102+
},
103+
"cli": {
104+
"analytics": false
102105
}
103106
}

src/app/fizz-buzz/fizz-buzz.component.html

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
<button mat-raised-button color="primary" (click)="onAdd()">
1+
<button mat-raised-button color="primary" (click)="onAdd()" data-testid="add-word-button">
22
Add another word
33
</button>
44

55
<mat-form-field appearance="fill">
66
<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" />
814
</mat-form-field>
915

10-
@for(group of formGroup.controls.multiples.controls; track group) {
16+
@for(group of formGroup.controls.multiples.controls; let idx = $index; track group) {
1117
<div class="content">
1218
<button mat-fab (click)="onRemove(group)"><mat-icon>delete</mat-icon></button>
1319
<mat-form-field appearance="fill">
1420
<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"/>
1728
@if (group.controls.wordToPrint.errors){
1829
<mat-error>
1930
Please enter a valid word
@@ -22,27 +33,34 @@
2233
</mat-form-field>
2334
<mat-form-field appearance="fill">
2435
<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" />
2644
@if (group.controls.multiple.errors?.['required'] || group.controls.multiple.errors?.['min']) {
27-
<mat-error>
45+
<mat-error [attr.data-testid]="'error-required-multiple' + idx">
2846
Please valid a number
2947
</mat-error>
3048
}
3149
@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>
3351
}
3452
</mat-form-field>
3553
<br />
3654
</div>
3755
}
3856

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">
4058
Submit
4159
</button>
4260

4361
@if (formGroup.controls.multiples.errors) {
4462
@if (formGroup.controls.multiples.errors['required']) {
45-
<mat-error>
63+
<mat-error data-testid="error-required-multiples">
4664
Please add at least two words
4765
</mat-error>
4866
}

src/app/fizz-buzz/fizz-buzz.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export class FizzBuzzComponent {
5151
}
5252

5353
protected onSubmit() {
54+
this.formGroup.markAllAsTouched();
55+
5456
const multiples = this.formGroup.controls.multiples.controls.map((group) => {
5557
return {
5658
multiple: group.controls.multiple.value,

0 commit comments

Comments
 (0)