|
| 1 | +import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing'; |
| 2 | +import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; |
| 3 | +import {MatDatepickerInputHarness} from '@angular/material/datepicker/testing'; |
| 4 | +import {HarnessLoader} from '@angular/cdk/testing'; |
| 5 | +import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} |
| 6 | + from '@angular/platform-browser-dynamic/testing'; |
| 7 | +import {MatDatepickerModule} from '@angular/material/datepicker'; |
| 8 | +import {DatepickerHarnessExample} from './datepicker-harness-example'; |
| 9 | +import {NoopAnimationsModule} from '@angular/platform-browser/animations'; |
| 10 | +import {MatNativeDateModule} from '@angular/material/core'; |
| 11 | +import {FormsModule} from '@angular/forms'; |
| 12 | + |
| 13 | +describe('DatepickerHarnessExample', () => { |
| 14 | + let fixture: ComponentFixture<DatepickerHarnessExample>; |
| 15 | + let loader: HarnessLoader; |
| 16 | + |
| 17 | + beforeAll(() => { |
| 18 | + TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); |
| 19 | + }); |
| 20 | + |
| 21 | + beforeEach( |
| 22 | + waitForAsync(() => { |
| 23 | + TestBed.configureTestingModule({ |
| 24 | + imports: [MatDatepickerModule, NoopAnimationsModule, MatNativeDateModule, FormsModule], |
| 25 | + declarations: [DatepickerHarnessExample] |
| 26 | + }).compileComponents(); |
| 27 | + fixture = TestBed.createComponent(DatepickerHarnessExample); |
| 28 | + fixture.detectChanges(); |
| 29 | + loader = TestbedHarnessEnvironment.loader(fixture); |
| 30 | + }) |
| 31 | + ); |
| 32 | + |
| 33 | + it('should load all datepicker input harnesses', async () => { |
| 34 | + const inputs = await loader.getAllHarnesses(MatDatepickerInputHarness); |
| 35 | + expect(inputs.length).toBe(1); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should get whether the input has an associated calendar', async () => { |
| 39 | + const input = await loader.getHarness(MatDatepickerInputHarness); |
| 40 | + expect(await input.hasCalendar()).toBeTrue(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should set the input value', async () => { |
| 44 | + const input = await loader.getHarness(MatDatepickerInputHarness); |
| 45 | + expect(await input.getValue()).toBeFalsy(); |
| 46 | + |
| 47 | + await input.setValue('1/1/2020'); |
| 48 | + expect(await input.getValue()).toBe('1/1/2020'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should get the minimum date of the input', async () => { |
| 52 | + const input = await loader.getHarness(MatDatepickerInputHarness); |
| 53 | + fixture.componentInstance.minDate = new Date(2020, 0, 1, 12, 0, 0); |
| 54 | + expect(await input.getMin()).toEqual('2020-01-01'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should be able to open and close a calendar in popup mode', async () => { |
| 58 | + const input = await loader.getHarness(MatDatepickerInputHarness); |
| 59 | + expect(await input.isCalendarOpen()).toBe(false); |
| 60 | + |
| 61 | + await input.openCalendar(); |
| 62 | + expect(await input.isCalendarOpen()).toBe(true); |
| 63 | + |
| 64 | + await input.closeCalendar(); |
| 65 | + expect(await input.isCalendarOpen()).toBe(false); |
| 66 | + }); |
| 67 | +}); |
0 commit comments