Skip to content

Commit d3cbd48

Browse files
committed
docs(material/timepicker): add a basic docs example
Adds a basic example to work around a CI failure.
1 parent 9546fe7 commit d3cbd48

File tree

7 files changed

+101
-1
lines changed

7 files changed

+101
-1
lines changed

src/components-examples/material/timepicker/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ ng_test_library(
3838
":timepicker",
3939
"//src/cdk/testing",
4040
"//src/cdk/testing/testbed",
41+
"//src/material/core",
4142
"//src/material/timepicker",
4243
"//src/material/timepicker/testing",
44+
"@npm//@angular/platform-browser",
4345
],
4446
)
4547

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export const TEMP = true;
1+
export {TimepickerOverviewExample} from './timepicker-overview/timepicker-overview-example';
2+
export {TimepickerHarnessExample} from './timepicker-harness/timepicker-harness-example';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<input [matTimepicker]="picker" [(value)]="date"/>
2+
<mat-timepicker #picker/>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {ComponentFixture, TestBed} from '@angular/core/testing';
2+
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
3+
import {MatTimepickerInputHarness} from '@angular/material/timepicker/testing';
4+
import {HarnessLoader} from '@angular/cdk/testing';
5+
import {TimepickerHarnessExample} from './timepicker-harness-example';
6+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
7+
import {DateAdapter, MatNativeDateModule} from '@angular/material/core';
8+
9+
describe('TimepickerHarnessExample', () => {
10+
let fixture: ComponentFixture<TimepickerHarnessExample>;
11+
let loader: HarnessLoader;
12+
13+
beforeEach(() => {
14+
TestBed.configureTestingModule({imports: [NoopAnimationsModule, MatNativeDateModule]});
15+
TestBed.inject(DateAdapter).setLocale('en-US'); // Set the locale to en-US to guarantee consistent tests.
16+
fixture = TestBed.createComponent(TimepickerHarnessExample);
17+
fixture.detectChanges();
18+
loader = TestbedHarnessEnvironment.loader(fixture);
19+
});
20+
21+
it('should load all timepicker input harnesses', async () => {
22+
const inputs = await loader.getAllHarnesses(MatTimepickerInputHarness);
23+
expect(inputs.length).toBe(1);
24+
});
25+
26+
it('should open and close a timepicker', async () => {
27+
const input = await loader.getHarness(MatTimepickerInputHarness);
28+
expect(await input.isTimepickerOpen()).toBe(false);
29+
30+
await input.openTimepicker();
31+
expect(await input.isTimepickerOpen()).toBe(true);
32+
});
33+
34+
it('should set the input value', async () => {
35+
const input = await loader.getHarness(MatTimepickerInputHarness);
36+
expect(await input.getValue()).toBe('11:45 AM');
37+
38+
await input.setValue('3:21 PM');
39+
expect(await input.getValue()).toBe('3:21 PM');
40+
});
41+
42+
it('should select an option from the timepicker', async () => {
43+
const input = await loader.getHarness(MatTimepickerInputHarness);
44+
const timepicker = await input.openTimepicker();
45+
expect(await input.getValue()).toBe('11:45 AM');
46+
47+
await timepicker.selectOption({text: '1:00 PM'});
48+
expect(await input.getValue()).toBe('1:00 PM');
49+
});
50+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {ChangeDetectionStrategy, Component, Signal, signal} from '@angular/core';
2+
import {provideNativeDateAdapter} from '@angular/material/core';
3+
import {MatTimepickerModule} from '@angular/material/timepicker';
4+
5+
/**
6+
* @title Testing with MatTimepickerInputHarness
7+
*/
8+
@Component({
9+
selector: 'timepicker-harness-example',
10+
templateUrl: 'timepicker-harness-example.html',
11+
standalone: true,
12+
providers: [provideNativeDateAdapter()],
13+
imports: [MatTimepickerModule],
14+
changeDetection: ChangeDetectionStrategy.OnPush,
15+
})
16+
export class TimepickerHarnessExample {
17+
date: Signal<Date | null>;
18+
19+
constructor() {
20+
const today = new Date();
21+
this.date = signal(new Date(today.getFullYear(), today.getMonth(), today.getDate(), 11, 45));
22+
}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<mat-form-field>
2+
<mat-label>Pick a time</mat-label>
3+
<input matInput [matTimepicker]="picker">
4+
<mat-timepicker-toggle matIconSuffix [for]="picker"/>
5+
<mat-timepicker #picker/>
6+
</mat-form-field>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {ChangeDetectionStrategy, Component} from '@angular/core';
2+
import {MatTimepickerModule} from '@angular/material/timepicker';
3+
import {MatInputModule} from '@angular/material/input';
4+
import {MatFormFieldModule} from '@angular/material/form-field';
5+
import {provideNativeDateAdapter} from '@angular/material/core';
6+
7+
/** @title Basic timepicker */
8+
@Component({
9+
selector: 'timepicker-overview-example',
10+
templateUrl: 'timepicker-overview-example.html',
11+
standalone: true,
12+
providers: [provideNativeDateAdapter()],
13+
imports: [MatFormFieldModule, MatInputModule, MatTimepickerModule],
14+
changeDetection: ChangeDetectionStrategy.OnPush,
15+
})
16+
export class TimepickerOverviewExample {}

0 commit comments

Comments
 (0)