-
Notifications
You must be signed in to change notification settings - Fork 2
feat(ps-date-time-input): added the PsDateTimeInputComponent #152
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
Open
KuhnMichael
wants to merge
3
commits into
master
Choose a base branch
from
datetime
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // export what ./public_api exports so we can import with the lib name like this: | ||
| // import { ModuleA } from 'libname' | ||
| export * from './public_api'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "ngPackage": { | ||
| "lib": { | ||
| "entryFile": "index.ts" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { PsDateTimeInputComponent as DateTimeComponent } from './src/date-time-input.component'; | ||
| export { PsDateTimeInputModule } from './src/date-time-input.module'; |
29 changes: 29 additions & 0 deletions
29
projects/components/date-time-input/src/date-time-input.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <div class="ps-date-time__grid-container"> | ||
| <!-- https://github.com/angular/material2/issues/5648 --> | ||
| <input | ||
| #dateInput | ||
| class="mat-input-element ps-date-time-picker__date-input" | ||
| [disabled]="disabled" | ||
| [(ngModel)]="datum" | ||
| (keyup)="onChanged()" | ||
| (dateChange)="onChanged()" | ||
| [matDatepicker]="publishPicker" | ||
| (focus)="onFocus()" | ||
| (blur)="onBlur()" | ||
| /> | ||
| <div class="mat-form-field-suffix"><mat-datepicker-toggle [for]="publishPicker"></mat-datepicker-toggle></div> | ||
| <input | ||
| #timeInput | ||
| class="mat-input-element ps-date-time-picker__time-input" | ||
| [disabled]="disabled" | ||
| type="time" | ||
| [(ngModel)]="uhrzeit" | ||
| (keyup)="onChanged()" | ||
| (change)="onChanged()" | ||
| (focus)="onFocus()" | ||
| (blur)="onBlur()" | ||
| step="60" | ||
| /> | ||
| </div> | ||
|
|
||
| <mat-datepicker #publishPicker></mat-datepicker> |
11 changes: 11 additions & 0 deletions
11
projects/components/date-time-input/src/date-time-input.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .ps-date-time__grid-container { | ||
| display: grid; | ||
| grid-template-columns: 2fr min-content minmax(min-content, 1fr); | ||
| grid-gap: 1px; | ||
| margin-bottom: -0.7em; | ||
| margin-top: -0.7em; | ||
| } | ||
|
|
||
| .mat-form-field-suffix { | ||
| top: 0; | ||
| } |
104 changes: 104 additions & 0 deletions
104
projects/components/date-time-input/src/date-time-input.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { Platform } from '@angular/cdk/platform'; | ||
| import { HarnessLoader } from '@angular/cdk/testing'; | ||
| import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
| import { getLocaleFirstDayOfWeek } from '@angular/common'; | ||
| import { Component, Inject, Injectable, LOCALE_ID, ViewChild } from '@angular/core'; | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { DateAdapter, MatDateFormats, MAT_DATE_FORMATS, NativeDateAdapter } from '@angular/material/core'; | ||
| import { parseHumanInput } from '@prosoft/components/utils'; | ||
| import { PsDateTimeInputComponent } from './date-time-input.component'; | ||
| import { PsDateTimeInputModule } from './date-time-input.module'; | ||
| import { PsDateTimeInputHarness } from './testing/date-time-input.harness'; | ||
|
|
||
| export const TEST_DATE_FORMATS: MatDateFormats = { | ||
| parse: { | ||
| dateInput: null, | ||
| }, | ||
| display: { | ||
| dateInput: { year: 'numeric', month: '2-digit', day: '2-digit' }, | ||
| monthYearLabel: { year: 'numeric', month: 'short' }, | ||
| dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' }, | ||
| monthYearA11yLabel: { year: 'numeric', month: 'long' }, | ||
| }, | ||
| }; | ||
|
|
||
| // extend NativeDateAdapter's format method to specify the date format. | ||
| @Injectable({ providedIn: 'root' }) | ||
| export class TestDateTimeAdapter extends NativeDateAdapter { | ||
| constructor(@Inject(LOCALE_ID) _locale: string, platform: Platform) { | ||
| super(_locale, platform); | ||
| } | ||
|
|
||
| public sameDate(a: any, b: any) { | ||
| return !a && !b ? false : super.sameDate(a, b); | ||
| } | ||
|
|
||
| public getFirstDayOfWeek(): number { | ||
| return getLocaleFirstDayOfWeek(this.locale); | ||
| } | ||
|
|
||
| // If required extend other NativeDateAdapter methods. | ||
| public parse(value: any): Date | null { | ||
| return parseHumanInput(value); | ||
| } | ||
|
|
||
| public getIs24Hours(): boolean { | ||
| return new Date(79200000).toLocaleTimeString(this.locale).indexOf('11') === -1; | ||
| } | ||
| } | ||
|
|
||
| @Component({ | ||
| selector: 'ps-test-component', | ||
| template: ` <ps-date-time-input [disabled]="disabled"></ps-date-time-input> `, | ||
| }) | ||
| export class TestDataSourceComponent { | ||
| public disabled = false; | ||
| @ViewChild(PsDateTimeInputComponent) public dateTimeInputComponent: PsDateTimeInputComponent; | ||
| } | ||
|
|
||
| describe('DateTimeInputComponent', () => { | ||
| let fixture: ComponentFixture<TestDataSourceComponent>; | ||
| let component: TestDataSourceComponent; | ||
| let loader: HarnessLoader; | ||
| let dateTimeInput: PsDateTimeInputHarness; | ||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [PsDateTimeInputModule], | ||
| declarations: [TestDataSourceComponent], | ||
| providers: [ | ||
| { provide: DateAdapter, useClass: TestDateTimeAdapter }, | ||
| { provide: MAT_DATE_FORMATS, useValue: TEST_DATE_FORMATS }, | ||
| ], | ||
| }); | ||
| fixture = TestBed.createComponent(TestDataSourceComponent); | ||
| component = fixture.componentInstance; | ||
| expect(component).toBeDefined(); | ||
|
|
||
| loader = TestbedHarnessEnvironment.loader(fixture); | ||
| dateTimeInput = await loader.getHarness(PsDateTimeInputHarness); | ||
| }); | ||
|
|
||
| it('Should be disabled', async () => { | ||
| expect(await dateTimeInput.isDisabled()).toEqual(false); | ||
| component.disabled = true; | ||
| expect(await dateTimeInput.isDisabled()).toEqual(true); | ||
| }); | ||
|
|
||
| it('Should return valid date', () => { | ||
| component.dateTimeInputComponent.datum = new Date(); | ||
| component.dateTimeInputComponent.uhrzeit = '11:11'; | ||
| const value = component.dateTimeInputComponent.convertToDate(); | ||
|
|
||
| const expectedValue = new Date(); | ||
| expectedValue.setHours(11, 11); | ||
| expect(value.getDate()).toEqual(expectedValue.getDate()); | ||
| }); | ||
|
|
||
| it('Should return invalid Date', () => { | ||
| component.dateTimeInputComponent.datum = new Date(); | ||
| component.dateTimeInputComponent.uhrzeit = null; | ||
| const value = component.dateTimeInputComponent.convertToDate(); | ||
|
|
||
| expect(value.getTime()).toEqual(NaN); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name of this test class seems wrong