Commit 37e07b75 authored by Dmitriy Danilov's avatar Dmitriy Danilov Committed by Dmitry Danilov
Browse files

Merge branch 'development' into radio_buttons

parents 82405cfc 5846bf29
Showing with 345 additions and 28 deletions
+345 -28
# http://editorconfig.org
# https://editorconfig.org
root = true
......@@ -8,4 +8,4 @@ indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
\ No newline at end of file
trim_trailing_whitespace = true
......@@ -442,12 +442,22 @@ export class DatepickerPo extends BaseComponent {
actualMonthArr = globalLocales.mnLocale.months;
break;
case 'ka' :
actualMonthArr = globalLocales.kaLocale.months;
break;
default:
actualMonthArr = undefined;
}
if (actualMonthArr) {
actualMonthArr = Array.isArray(actualMonthArr) ? actualMonthArr : actualMonthArr.standalone;
}
cy.get(`${baseSelector}>${
pickerType === 'datepicker' ? this.datepickerContainer : this.daterangepickerContainer} tbody td`)
.eq(0).each((month, monthIndex) => {
.eq(0)
.each((month, monthIndex) => {
expect(month.text().toLowerCase()).to.contains(
actualMonthArr ? actualMonthArr[monthIndex].toLowerCase() :
new Date(2017, monthIndex)
......@@ -554,7 +564,7 @@ export class DatepickerPo extends BaseComponent {
.should(disabled ? 'have.class' : 'not.to.have.class', 'disabled');
}
}
isTodayHaveClass(className: string) {
cy.get(`body>${this.datepickerContainer} tbody td`)
.not('.week')
......
......@@ -66,7 +66,7 @@ export class BsDatepickerDirective implements OnInit, OnDestroy, OnChanges {
*/
@Input()
set bsValue(value: Date) {
if (this._bsValue && this._bsValue.getTime() === value.getTime()) {
if (this._bsValue && value && this._bsValue.getTime() === value.getTime()) {
return;
}
this._bsValue = value;
......
<ul class="pager">
<li [class.disabled]="noPrevious()" [class.previous]="align"
[ngClass]="{'pull-right': align, 'float-right': align}"
[ngClass]="{'pull-left': align, 'float-left': align}"
class="{{ pageBtnClass }}">
<a href (click)="selectPage(page - 1, $event)">{{ getText('previous') }}</a>
</li>
......
......@@ -690,18 +690,6 @@ describe('Directive: Buttons', () => {
expect(radioGroup.children[i].getAttribute('role')).toEqual('radio');
}
});
it(
'should not have a tabindex if group is disabled',
fakeAsync(() => {
context.disableGroups();
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(radioGroup.hasAttribute('tabindex')).toBeFalsy();
})
);
it('should have no radio selected by default', () => {
fixture.detectChanges();
expect(radioGroup.children[0].classList).not.toContain('active');
......
......@@ -58,7 +58,7 @@ describe('Component: Pager:', () => {
const listItems = element.querySelectorAll('li');
expect(listItems[0].classList).toContain('disabled');
expect(listItems[0].classList).toContain('pull-right');
expect(listItems[0].classList).toContain('pull-left');
expect(listItems[0].classList).toContain('previous');
expect(listItems[0].classList).toContain('btn');
expect(listItems[1].classList).not.toContain('disabled');
......
......@@ -13,12 +13,12 @@ import {
/* tslint:disable-next-line: no-any */
function getInputElements(fixture: any) {
return fixture.nativeElement.querySelectorAll('input') as HTMLInputElement;
return fixture.nativeElement.querySelectorAll('input') as HTMLInputElement[];
}
/* tslint:disable-next-line: no-any */
function getElements(fixture: any, selector: string) {
return fixture.nativeElement.querySelectorAll(selector) as HTMLElement;
return fixture.nativeElement.querySelectorAll(selector) as HTMLElement[];
}
/* tslint:disable-next-line: no-any */
......@@ -50,7 +50,7 @@ describe('Component: TimepickerComponent', () => {
let buttonMeridian: HTMLElement;
/* tslint:disable-next-line: no-any */
let buttonDebugMeridian: any;
let buttonChanges: HTMLElement;
let buttonChanges: HTMLElement[];
beforeEach(() => {
TestBed.configureTestingModule({
......@@ -69,7 +69,7 @@ describe('Component: TimepickerComponent', () => {
inputMinutes = getInputElements(fixture)[1];
inputSeconds = getInputElements(fixture)[2];
buttonChanges = getElements(fixture, 'a.btn');
buttonMeridian = getElements(fixture, 'button');
buttonMeridian = getElements(fixture, 'button')[0];
});
it('hours and minutes fields should be visible', () => {
......@@ -1149,4 +1149,320 @@ describe('Component: TimepickerComponent', () => {
});
});
describe('date part', () => {
beforeEach(() => {
fixture = TestBed.createComponent(TimepickerComponent);
component = fixture.componentInstance;
component.showSeconds = true;
component.showMeridian = false;
fixture.detectChanges();
const inputs = getInputElements(fixture);
inputHours = inputs[0];
inputMinutes = inputs[1];
inputSeconds = inputs[2];
buttonChanges = getElements(fixture, 'a.btn');
});
/**
* Extract only the date part, i.e. floor to previous midnight
* (in system local timezone)
* @param date with potential hours, minutes, seconds and milliseconds
*/
function _getDateOnly(date: Date): Date {
const result = new Date(date);
result.setHours(0, 0, 0, 0);
return result;
}
it('should preserve day when hour crosses up from 23 to 00', fakeAsync(() => {
const hourA = 23;
const hourAstr = '23';
let componentDateTime: Date;
component.registerOnChange((newDateTime: Date) => {
componentDateTime = newDateTime;
return newDateTime;
});
expect(componentDateTime).toBeUndefined();
const testedTime = testTime(hourA);
component.writeValue(testedTime);
fixture.detectChanges();
expect(componentDateTime.getHours()).toBe(hourA);
expect(inputHours.value).toBe(hourAstr);
// Record date part before changing hour
const expectedDate = _getDateOnly(componentDateTime);
fireEvent(buttonChanges[0], 'click'); // Hour increment button
const hourB = 0;
const hourBstr = '00';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(componentDateTime.getHours()).toBe(hourB);
expect(inputHours.value).toBe(hourBstr);
const actualDate = _getDateOnly(componentDateTime);
// Compare string output for easier debugging
expect(actualDate.toString()).toBe(expectedDate.toString());
// Still compare epoch value for millisecond precision
expect(actualDate.valueOf()).toBe(expectedDate.valueOf());
});
}));
it('should preserve day when hour crosses down from 00 to 23', fakeAsync(() => {
const hourA = 0;
const hourAstr = '00';
let componentDateTime: Date;
component.registerOnChange((newDateTime: Date) => {
componentDateTime = newDateTime;
return newDateTime;
});
expect(componentDateTime).toBeUndefined();
const testedTime = testTime(hourA);
component.writeValue(testedTime);
fixture.detectChanges();
expect(componentDateTime.getHours()).toBe(hourA);
expect(inputHours.value).toBe(hourAstr);
// Record date part before changing hour
const expectedDate = _getDateOnly(componentDateTime);
fireEvent(buttonChanges[3], 'click'); // Hour decrement button
const hourB = 23;
const hourBstr = '23';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(componentDateTime.getHours()).toBe(hourB);
expect(inputHours.value).toBe(hourBstr);
const actualDate = _getDateOnly(componentDateTime);
expect(actualDate.toString()).toBe(expectedDate.toString());
expect(actualDate.valueOf()).toBe(expectedDate.valueOf());
});
}));
// Case for #3139
// minuteStep default value is 5
it('should preserve day when minutes cross up from 23:59 to 00:04', fakeAsync(() => {
const hourA = 23;
const hourAstr = '23';
const minutesA = 59;
const minutesAstr = '59';
let componentDateTime: Date;
component.registerOnChange((newDateTime: Date) => {
componentDateTime = newDateTime;
return newDateTime;
});
expect(componentDateTime).toBeUndefined();
const testedTime = testTime(hourA, minutesA);
component.writeValue(testedTime);
fixture.detectChanges();
expect(componentDateTime.getHours()).toBe(hourA);
expect(inputHours.value).toBe(hourAstr);
expect(componentDateTime.getMinutes()).toBe(minutesA);
expect(inputMinutes.value).toBe(minutesAstr);
// Record date part before changing hour
const expectedDate = _getDateOnly(componentDateTime);
fireEvent(buttonChanges[1], 'click'); // Minutes increment button
const hourB = 0;
const hourBstr = '00';
const minutesB = 4;
const minutesBstr = '04';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(componentDateTime.getHours()).toBe(hourB);
expect(inputHours.value).toBe(hourBstr);
expect(componentDateTime.getMinutes()).toBe(minutesB);
expect(inputMinutes.value).toBe(minutesBstr);
const actualDate = _getDateOnly(componentDateTime);
expect(actualDate.toString()).toBe(expectedDate.toString());
expect(actualDate.valueOf()).toBe(expectedDate.valueOf());
});
}));
// Case for #3139
it('should preserve day when minutes cross down from 00:01 to 23:56', fakeAsync(() => {
const hourA = 0;
const hourAstr = '00';
const minutesA = 1;
const minutesAstr = '01';
let componentDateTime: Date;
component.registerOnChange((newDateTime: Date) => {
componentDateTime = newDateTime;
return newDateTime;
});
expect(componentDateTime).toBeUndefined();
const testedTime = testTime(hourA, minutesA);
component.writeValue(testedTime);
fixture.detectChanges();
expect(componentDateTime.getHours()).toBe(hourA);
expect(inputHours.value).toBe(hourAstr);
expect(componentDateTime.getMinutes()).toBe(minutesA);
expect(inputMinutes.value).toBe(minutesAstr);
// Record date part before changing hour
const expectedDate = _getDateOnly(componentDateTime);
fireEvent(buttonChanges[4], 'click'); // Minutes decrement button
const hourB = 23;
const hourBstr = '23';
const minutesB = 56;
const minutesBstr = '56';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(componentDateTime.getHours()).toBe(hourB);
expect(inputHours.value).toBe(hourBstr);
expect(componentDateTime.getMinutes()).toBe(minutesB);
expect(inputMinutes.value).toBe(minutesBstr);
const actualDate = _getDateOnly(componentDateTime);
expect(actualDate.toString()).toBe(expectedDate.toString());
expect(actualDate.valueOf()).toBe(expectedDate.valueOf());
});
}));
// Case for #3139
// secondsStep default value is 10
it('should preserve day when seconds cross up from 23:59:59 to 00:00:09', fakeAsync(() => {
const hourA = 23;
const hourAstr = '23';
const minutesA = 59;
const minutesAstr = '59';
const secondsA = 59;
const secondsAstr = '59';
let componentDateTime: Date;
component.registerOnChange((newDateTime: Date) => {
componentDateTime = newDateTime;
return newDateTime;
});
expect(componentDateTime).toBeUndefined();
const testedTime = testTime(hourA, minutesA, secondsA);
component.writeValue(testedTime);
fixture.detectChanges();
expect(componentDateTime.getHours()).toBe(hourA);
expect(inputHours.value).toBe(hourAstr);
expect(componentDateTime.getMinutes()).toBe(minutesA);
expect(inputMinutes.value).toBe(minutesAstr);
expect(componentDateTime.getSeconds()).toBe(secondsA);
expect(inputSeconds.value).toBe(secondsAstr);
// Record date part before changing hour
const expectedDate = _getDateOnly(componentDateTime);
fireEvent(buttonChanges[2], 'click'); // Seconds increment button
const hourB = 0;
const hourBstr = '00';
const minutesB = 0;
const minutesBstr = '00';
const secondsB = 9;
const secondsBstr = '09';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(componentDateTime.getHours()).toBe(hourB);
expect(inputHours.value).toBe(hourBstr);
expect(componentDateTime.getMinutes()).toBe(minutesB);
expect(inputMinutes.value).toBe(minutesBstr);
expect(componentDateTime.getSeconds()).toBe(secondsB);
expect(inputSeconds.value).toBe(secondsBstr);
const actualDate = _getDateOnly(componentDateTime);
expect(actualDate.toString()).toBe(expectedDate.toString());
expect(actualDate.valueOf()).toBe(expectedDate.valueOf());
});
}));
// Case for #3139
it('should preserve day when seconds cross down from 00:00:01 to 23:59:51', fakeAsync(() => {
const hourA = 0;
const hourAstr = '00';
const minutesA = 0;
const minutesAstr = '00';
const secondsA = 1;
const secondsAstr = '01';
let componentDateTime: Date;
component.registerOnChange((newDateTime: Date) => {
componentDateTime = newDateTime;
return newDateTime;
});
expect(componentDateTime).toBeUndefined();
const testedTime = testTime(hourA, minutesA, secondsA);
component.writeValue(testedTime);
fixture.detectChanges();
expect(componentDateTime.getHours()).toBe(hourA);
expect(inputHours.value).toBe(hourAstr);
expect(componentDateTime.getMinutes()).toBe(minutesA);
expect(inputMinutes.value).toBe(minutesAstr);
expect(componentDateTime.getSeconds()).toBe(secondsA);
expect(inputSeconds.value).toBe(secondsAstr);
// Record date part before changing hour
const expectedDate = _getDateOnly(componentDateTime);
fireEvent(buttonChanges[5], 'click'); // Seconds decrement button
const hourB = 23;
const hourBstr = '23';
const minutesB = 59;
const minutesBstr = '59';
const secondsB = 51;
const secondsBstr = '51';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(componentDateTime.getHours()).toBe(hourB);
expect(inputHours.value).toBe(hourBstr);
expect(componentDateTime.getMinutes()).toBe(minutesB);
expect(inputMinutes.value).toBe(minutesBstr);
expect(componentDateTime.getSeconds()).toBe(secondsB);
expect(inputSeconds.value).toBe(secondsBstr);
const actualDate = _getDateOnly(componentDateTime);
expect(actualDate.toString()).toBe(expectedDate.toString());
expect(actualDate.valueOf()).toBe(expectedDate.valueOf());
});
}));
});
});
......@@ -98,10 +98,7 @@ export function changeTime(value: Date, diff: Time): Date {
let seconds = value.getSeconds();
if (diff.hour) {
hour = (hour + toNumber(diff.hour)) % hoursPerDay;
if (hour < 0) {
hour += hoursPerDay;
}
hour = hour + toNumber(diff.hour);
}
if (diff.minute) {
......@@ -145,7 +142,7 @@ export function createDate(
minutes: number,
seconds: number
): Date {
return new Date(
const newValue = new Date(
value.getFullYear(),
value.getMonth(),
value.getDate(),
......@@ -154,6 +151,12 @@ export function createDate(
seconds,
value.getMilliseconds()
);
// #3139 ensure date part remains unchanged
newValue.setFullYear(value.getFullYear());
newValue.setMonth(value.getMonth());
newValue.setDate(value.getDate());
return newValue;
}
export function padNumber(value: number): string {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment