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

fix(kit): InputDateTime validators not triggered when value change #9846

Merged
merged 2 commits into from
Nov 27, 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,4 +1,4 @@
import {

Check failure on line 1 in projects/demo-playwright/tests/kit/input-date-time/input-date-time.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error

1) [chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error Test timeout of 30000ms exceeded.

Check failure on line 1 in projects/demo-playwright/tests/kit/input-date-time/input-date-time.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error

1) [chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.
TuiDocumentationPagePO,
tuiGoto,
TuiInputDateTimePO,
Expand Down Expand Up @@ -241,4 +241,38 @@
});
});
});

test.describe('Examples', () => {
let example!: Locator;
let documentationPage!: TuiDocumentationPagePO;
let inputDateTime!: TuiInputDateTimePO;

test.beforeEach(async ({page}) => {
await tuiGoto(page, 'components/input-date-time');

documentationPage = new TuiDocumentationPagePO(page);
example = documentationPage.apiPageExample;

inputDateTime = new TuiInputDateTimePO(
example.locator('tui-input-date-time'),
);
});

test('With validator: enter incomplete date -> validator error', async () => {
example = documentationPage.getExample('#with-validator');
inputDateTime = new TuiInputDateTimePO(
example.locator('tui-input-date-time'),
);

await inputDateTime.textfield.clear();

Check failure on line 267 in projects/demo-playwright/tests/kit/input-date-time/input-date-time.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error

1) [chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error Error: locator.clear: Test timeout of 30000ms exceeded. Call log: - waiting for locator('#with-validator [automation-id="tui-doc-example"]').locator('tui-input-date-time').getByRole('textbox') 265 | ); 266 | > 267 | await inputDateTime.textfield.clear(); | ^ 268 | await inputDateTime.textfield.fill('11'); 269 | await inputDateTime.textfield.blur(); 270 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-time/input-date-time.spec.ts:267:43

Check failure on line 267 in projects/demo-playwright/tests/kit/input-date-time/input-date-time.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error

1) [chromium] › tests/kit/input-date-time/input-date-time.spec.ts:261:13 › InputDateTime › Examples › With validator: enter incomplete date -> validator error Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: locator.clear: Test timeout of 30000ms exceeded. Call log: - waiting for locator('#with-validator [automation-id="tui-doc-example"]').locator('tui-input-date-time').getByRole('textbox') 265 | ); 266 | > 267 | await inputDateTime.textfield.clear(); | ^ 268 | await inputDateTime.textfield.fill('11'); 269 | await inputDateTime.textfield.blur(); 270 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-time/input-date-time.spec.ts:267:43
await inputDateTime.textfield.fill('11');
await inputDateTime.textfield.blur();

// allow animations to capture tui-error validation message on screenshot
await expect(example).toHaveScreenshot(
'04-input-data-time-with-validator.png',
{animations: 'allow'},
mdlufy marked this conversation as resolved.
Show resolved Hide resolved
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<tui-input-date-time [formControl]="control">Choose date and time</tui-input-date-time>
<tui-error
[error]="[] | tuiFieldError | async"
[formControl]="control"
></tui-error>

<p>Form value:</p>

<pre><code>{{ control.value | json }}</code></pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Component} from '@angular/core';
import {
AbstractControl,
FormControl,
ValidationErrors,
ValidatorFn,
} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import {TuiDay} from '@taiga-ui/cdk';

const completeDateTimeValidator: ValidatorFn = (
control: AbstractControl,
): ValidationErrors | null =>
control.value.every(Boolean) ? null : {incompleteDateTime: true};

@Component({
selector: 'tui-input-date-time-example-6',
templateUrl: './index.html',
encapsulation,
changeDetection,
})
export class TuiInputDateTimeExample6 {
readonly control = new FormControl(
[new TuiDay(2017, 2, 15), null],
completeDateTimeValidator,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export class ExampleTuiInputDateTimeComponent extends AbstractExampleTuiControl
HTML: import('./examples/5/index.html?raw'),
};

readonly example6: TuiDocExample = {
TypeScript: import('./examples/6/index.ts?raw'),
HTML: import('./examples/6/index.html?raw'),
};

readonly minVariants: ReadonlyArray<TuiDay | [TuiDay, TuiTime]> = [
TUI_FIRST_DAY,
new TuiDay(2017, 2, 5),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ import {RouterModule} from '@angular/router';
import {TuiAddonDocModule, tuiGenerateRoutes} from '@taiga-ui/addon-doc';
import {
TuiDropdownModule,
TuiErrorModule,
TuiHintModule,
TuiLinkModule,
TuiNotificationModule,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
import {TuiInputDateTimeModule} from '@taiga-ui/kit';
import {TuiFieldErrorPipeModule, TuiInputDateTimeModule} from '@taiga-ui/kit';

import {InheritedDocumentationModule} from '../abstract/inherited-documentation/inherited-documentation.module';
import {TuiInputDateTimeExample1} from './examples/1';
import {TuiInputDateTimeExample2} from './examples/2';
import {TuiInputDateTimeExample3} from './examples/3';
import {TuiInputDateTimeExample4} from './examples/4';
import {TuiInputDateTimeExample5} from './examples/5';
import {TuiInputDateTimeExample6} from './examples/6';
import {ExampleTuiInputDateTimeComponent} from './input-date-time.component';

@NgModule({
imports: [
TuiErrorModule,
TuiFieldErrorPipeModule,
TuiAddonDocModule,
InheritedDocumentationModule,
ReactiveFormsModule,
Expand All @@ -42,6 +46,7 @@ import {ExampleTuiInputDateTimeComponent} from './input-date-time.component';
TuiInputDateTimeExample3,
TuiInputDateTimeExample4,
TuiInputDateTimeExample5,
TuiInputDateTimeExample6,
],
exports: [ExampleTuiInputDateTimeComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ <h3>DI-tokens for input-configurations:</h3>
</tui-notification>
<tui-input-date-time-example-5></tui-input-date-time-example-5>
</tui-doc-example>

<tui-doc-example
id="with-validator"
heading="With validator"
[content]="example6"
>
<tui-input-date-time-example-6></tui-input-date-time-example-6>
</tui-doc-example>
</ng-template>

<ng-template pageTab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ export class TuiInputDateTimeComponent
}

onValueChange(value: string): void {
if (this.control) {
this.control.updateValueAndValidity({emitEvent: false});
}

if (!value) {
this.onOpenChange(true);
}
Expand Down
Loading