Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(demo): add new e2e test for field error #6596

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import {tuiGoto} from '@demo-playwright/utils';
import {TuiDocumentationPagePO, tuiGoto} from '@demo-playwright/utils';
import {expect, test} from '@playwright/test';

test.describe('TuiFieldError', () => {
test.describe('FieldError', () => {
test('Errors of invalid control are shown correctly', async ({page}) => {
const example = new TuiDocumentationPagePO(page).getExample('#base');

await tuiGoto(page, '/pipes/field-error');

const errorPipeInput = page
.locator('tui-field-error-pipe-example-1 input')
.first();
const input = example.locator('input').first();

await errorPipeInput.focus();
await input.focus();
await input.blur();

await page.waitForTimeout(50);
await page.waitForTimeout(500);

await errorPipeInput.blur();
await expect(example).toHaveScreenshot('01-field-error.png', {
animations: 'allow',
});
});

test('Submit invalid form', async ({page}) => {
const example = new TuiDocumentationPagePO(page).getExample('#patterns');

await tuiGoto(page, '/pipes/field-error');
await example.locator('button').click();

Check failure on line 26 in projects/demo-playwright/tests/kit/field-error/field-error.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (6 of 8)

[chromium] › tests/kit/field-error/field-error.spec.ts:22:9 › FieldError › Submit invalid form

1) [chromium] › tests/kit/field-error/field-error.spec.ts:22:9 › FieldError › Submit invalid form TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for locator('#patterns [automation-id="tui-doc-example"]').locator('button') 24 | 25 | await tuiGoto(page, '/pipes/field-error'); > 26 | await example.locator('button').click(); | ^ 27 | 28 | await page.waitForTimeout(500); 29 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/field-error/field-error.spec.ts:26:41

Check failure on line 26 in projects/demo-playwright/tests/kit/field-error/field-error.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (6 of 8)

[chromium] › tests/kit/field-error/field-error.spec.ts:22:9 › FieldError › Submit invalid form

1) [chromium] › tests/kit/field-error/field-error.spec.ts:22:9 › FieldError › Submit invalid form Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for locator('#patterns [automation-id="tui-doc-example"]').locator('button') 24 | 25 | await tuiGoto(page, '/pipes/field-error'); > 26 | await example.locator('button').click(); | ^ 27 | 28 | await page.waitForTimeout(500); 29 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/field-error/field-error.spec.ts:26:41

Check failure on line 26 in projects/demo-playwright/tests/kit/field-error/field-error.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (6 of 8)

[chromium] › tests/kit/field-error/field-error.spec.ts:22:9 › FieldError › Submit invalid form

1) [chromium] › tests/kit/field-error/field-error.spec.ts:22:9 › FieldError › Submit invalid form Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for locator('#patterns [automation-id="tui-doc-example"]').locator('button') 24 | 25 | await tuiGoto(page, '/pipes/field-error'); > 26 | await example.locator('button').click(); | ^ 27 | 28 | await page.waitForTimeout(500); 29 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/field-error/field-error.spec.ts:26:41

const example = page.getByTestId('tui-doc-example').first();
await page.waitForTimeout(500);

await expect(example).toHaveScreenshot('shows-error-under-field.png', {
await expect(example).toHaveScreenshot('02-field-error.png', {
animations: 'allow',
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<form
class="b-form"
[formGroup]="testForm"
(submit)="onSubmit()"
>
<label tuiLabel="Secret number">
<tui-input
Expand All @@ -23,7 +24,7 @@

<label
tuiLabel="Enter company name"
class="tui-space_top-4"
class="tui-space_top-4 tui-space_bottom-4"
>
<tui-input
formControlName="testValue2"
Expand All @@ -47,4 +48,31 @@
[error]="[] | tuiFieldError | async"
></tui-error>
</label>

<label>
<div class="checkbox">
<input
formControlName="testValue3"
size="s"
tuiCheckbox
type="checkbox"
/>

I agree on the conditions
</div>

<tui-error
formControlName="testValue3"
[error]="[] | tuiFieldError | async"
></tui-error>
</label>

<button
size="m"
tuiButton
type="submit"
class="tui-space_top-4"
>
Submit
</button>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.checkbox {
display: flex;
align-items: center;
gap: 0.5rem;
}
17 changes: 7 additions & 10 deletions projects/demo/src/modules/pipes/field-error/examples/3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ import {
} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import {TuiValidationError} from '@taiga-ui/cdk';
import {tuiMarkControlAsTouchedAndValidate, TuiValidationError} from '@taiga-ui/cdk';
import {type PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

const secretRegexTen = /^\d{10}$/;
const secretRegexTwelve = /^\d{12}$/;

export function innValidator(field: AbstractControl): unknown {
return field.value &&
(secretRegexTen.test(field.value) || secretRegexTwelve.test(field.value))
? null
: {
inn: new TuiValidationError('Secret number contains 10 or 12 digits'),
};
}

@Component({
selector: 'tui-field-error-pipe-example-3',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
Expand All @@ -41,12 +33,17 @@ export class TuiFieldErrorPipeExample3 implements OnInit {
protected readonly testForm = new FormGroup({
testValue1: new FormControl('', [Validators.required, this.getSecretValidator()]),
testValue2: this.testValue2,
testValue3: new FormControl(false, [Validators.requiredTrue]),
});

public ngOnInit(): void {
this.testValue2.setValidators([Validators.required, this.companyValidator]);
}

protected onSubmit(): void {
tuiMarkControlAsTouchedAndValidate(this.testForm);
}

private readonly companyValidator = (
field: AbstractControl,
): ValidationErrors | null =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
TuiLinkModule,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
import {TuiCheckboxModule} from '@taiga-ui/experimental';
import {
TuiFieldErrorPipeModule,
TuiInputModule,
Expand Down Expand Up @@ -49,6 +50,7 @@ import {ExampleTuiFieldErrorPipeComponent} from './field-error.component';
TuiInputNumberModule,
TuiCurrencyPipeModule,
PolymorpheusModule,
TuiCheckboxModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiFieldErrorPipeComponent)),
],
declarations: [
Expand Down
Loading