Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(timepicker): input filter to accept only numbers
- Loading branch information
Showing
7 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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
4 changes: 4 additions & 0 deletions
4
e2e-app/src/app/timepicker/filter/timepicker-filter.component.html
This file contains 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,4 @@ | ||
<ngb-timepicker | ||
[seconds]="true" | ||
[(ngModel)]="time" | ||
></ngb-timepicker> |
8 changes: 8 additions & 0 deletions
8
e2e-app/src/app/timepicker/filter/timepicker-filter.component.ts
This file contains 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,8 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
templateUrl: './timepicker-filter.component.html', | ||
}) | ||
export class TimepickerFilterComponent { | ||
time = {hour: null, minute: null, second: null}; | ||
} |
69 changes: 69 additions & 0 deletions
69
e2e-app/src/app/timepicker/filter/timepicker-filter.e2e-spec.ts
This file contains 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,69 @@ | ||
import {protractor} from 'protractor'; | ||
|
||
import {openUrl} from '../../tools.po'; | ||
|
||
import {TimepickerFilterPage} from './timepicker-filter.po'; | ||
|
||
describe('Timepicker', () => { | ||
let page: TimepickerFilterPage; | ||
|
||
beforeAll(() => page = new TimepickerFilterPage()); | ||
beforeEach(async() => await openUrl('timepicker/filter')); | ||
|
||
async function expectValue(expectedValue) { | ||
const inputs = page.getFields(); | ||
|
||
const values = []; | ||
for (let i = 0; i < inputs.length; i++) { | ||
values[i] = await inputs[i].getAttribute('value'); | ||
} | ||
expect(values.join(':')).toBe(expectedValue); | ||
} | ||
|
||
describe('filter', async() => { | ||
it(`should accept numbers`, async() => { | ||
await expectValue('::'); // No starting values | ||
|
||
const inputs = page.getFields(); | ||
await inputs[0].sendKeys('1'); | ||
await inputs[1].sendKeys('2'); | ||
await inputs[2].sendKeys('3'); | ||
|
||
await inputs[0].click(); | ||
await expectValue('01:02:03'); | ||
}); | ||
|
||
it(`shouldn't accept alpha`, async() => { | ||
await expectValue('::'); // No starting values | ||
|
||
const inputs = page.getFields(); | ||
await inputs[0].sendKeys('A'); | ||
await inputs[1].sendKeys('A'); | ||
await inputs[2].sendKeys('A'); | ||
|
||
await inputs[0].click(); | ||
await expectValue('::'); | ||
}); | ||
|
||
it(`shouldn accept special commands`, async() => { | ||
|
||
const inputs = page.getFields(); | ||
|
||
await inputs[0].sendKeys('1'); | ||
await inputs[0].sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'a')); | ||
await inputs[0].sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'c')); | ||
|
||
await inputs[1].click(); | ||
await inputs[1].sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'v')); | ||
|
||
await inputs[2].click(); | ||
await inputs[2].sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'v')); | ||
|
||
await inputs[0].click(); | ||
await expectValue('01:01:01'); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains 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,8 @@ | ||
import {$} from 'protractor'; | ||
|
||
export type Field = 'hour' | 'minute' | 'second'; | ||
|
||
export class TimepickerFilterPage { | ||
getField(field: Field) { return $(`.ngb-tp-${field} > input`); } | ||
getFields() { return ['hour', 'minute', 'second'].map((field: Field) => this.getField(field)); } | ||
} |
This file contains 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