chore(#433): more tests & remove as much logic as possible form template
This commit is contained in:
parent
c034f0802e
commit
91a9af2346
5 changed files with 64 additions and 16 deletions
|
|
@ -321,7 +321,8 @@ export class LionCalendar extends LocalizeMixin(LitElement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
__renderNextButton(nextMonth, nextYear) {
|
__renderNextButton(nextMonth, nextYear) {
|
||||||
const nextButtonTitle = `Next Month, ${nextMonth} ${nextYear}`;
|
const nextButtonTitle = `${this.msgLit('lion-calendar:nextMonth')}, ${nextMonth} ${nextYear}`;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<button
|
<button
|
||||||
class="calendar__next-month-button"
|
class="calendar__next-month-button"
|
||||||
|
|
@ -347,6 +348,9 @@ export class LionCalendar extends LocalizeMixin(LitElement) {
|
||||||
day.today = isSameDate(day.date, today);
|
day.today = isSameDate(day.date, today);
|
||||||
day.future = day.date > today;
|
day.future = day.date > today;
|
||||||
day.disabled = this.disableDates(day.date);
|
day.disabled = this.disableDates(day.date);
|
||||||
|
day.tabindex = day.central ? '0' : '-1';
|
||||||
|
day.ariaPressed = day.selected ? 'true' : 'false';
|
||||||
|
day.ariaCurrent = day.today ? 'date' : undefined;
|
||||||
|
|
||||||
if (this.minDate && normalizeDateTime(day.date) < normalizeDateTime(this.minDate)) {
|
if (this.minDate && normalizeDateTime(day.date) < normalizeDateTime(this.minDate)) {
|
||||||
day.disabled = true;
|
day.disabled = true;
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,8 @@ export function createDay(
|
||||||
past,
|
past,
|
||||||
today,
|
today,
|
||||||
future,
|
future,
|
||||||
|
tabindex: '-1',
|
||||||
|
ariaPressed: 'false',
|
||||||
|
ariaCurrent: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ export function dayTemplate(day, { weekdays, monthsLabels = defaultMonthLabels }
|
||||||
<button
|
<button
|
||||||
.date=${day.date}
|
.date=${day.date}
|
||||||
class="calendar__day-button"
|
class="calendar__day-button"
|
||||||
tabindex=${day.central ? '0' : '-1'}
|
tabindex=${day.tabindex}
|
||||||
aria-label=${`${dayNumber} ${monthName} ${year} ${weekdayName}`}
|
aria-label=${`${dayNumber} ${monthName} ${year} ${weekdayName}`}
|
||||||
aria-pressed=${day.selected ? 'true' : 'false'}
|
aria-pressed=${day.ariaPressed}
|
||||||
aria-current=${ifDefined(day.today ? 'date' : undefined)}
|
aria-current=${ifDefined(day.ariaCurrent)}
|
||||||
?disabled=${day.disabled}
|
?disabled=${day.disabled}
|
||||||
?selected=${day.selected}
|
?selected=${day.selected}
|
||||||
?past=${day.past}
|
?past=${day.past}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ describe('<lion-calendar>', () => {
|
||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
expect(el.shadowRoot.querySelector('.calendar__next-month-button')).dom.to.equal(`
|
expect(el.shadowRoot.querySelector('.calendar__next-month-button')).dom.to.equal(`
|
||||||
<button class="calendar__next-month-button" aria-label="Next Month, December 2019" title="Next Month, December 2019">></button>
|
<button class="calendar__next-month-button" aria-label="Next month, December 2019" title="Next month, December 2019">></button>
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -588,10 +588,10 @@ describe('<lion-calendar>', () => {
|
||||||
'Previous month, November 2000',
|
'Previous month, November 2000',
|
||||||
);
|
);
|
||||||
expect(elObj.nextMonthButtonEl.getAttribute('title')).to.equal(
|
expect(elObj.nextMonthButtonEl.getAttribute('title')).to.equal(
|
||||||
'Next Month, January 2001',
|
'Next month, January 2001',
|
||||||
);
|
);
|
||||||
expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal(
|
expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal(
|
||||||
'Next Month, January 2001',
|
'Next month, January 2001',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -1186,21 +1186,62 @@ describe('<lion-calendar>', () => {
|
||||||
|
|
||||||
const elObj = new CalendarObject(el);
|
const elObj = new CalendarObject(el);
|
||||||
expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal(
|
expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal(
|
||||||
'Next Month, December 2019',
|
'Next month, December 2019',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expect(elObj.previousMonthButtonEl.getAttribute('aria-label')).to.equal(
|
||||||
|
'Previous month, October 2019',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(elObj.weekdayHeaderEls.map(h => h.getAttribute('aria-label'))).to.eql([
|
||||||
|
'Sunday',
|
||||||
|
'Monday',
|
||||||
|
'Tuesday',
|
||||||
|
'Wednesday',
|
||||||
|
'Thursday',
|
||||||
|
'Friday',
|
||||||
|
'Saturday',
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(elObj.weekdayHeaderEls.map(h => h.textContent.trim())).to.deep.equal([
|
||||||
|
'Sun',
|
||||||
|
'Mon',
|
||||||
|
'Tue',
|
||||||
|
'Wed',
|
||||||
|
'Thu',
|
||||||
|
'Fri',
|
||||||
|
'Sat',
|
||||||
|
]);
|
||||||
|
|
||||||
localize.locale = 'nl-NL';
|
localize.locale = 'nl-NL';
|
||||||
await el.updateComplete;
|
await el.updateComplete;
|
||||||
expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal(
|
expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal(
|
||||||
'Next Month, december 2019',
|
'Volgende maand, december 2019',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
expect(elObj.previousMonthButtonEl.getAttribute('aria-label')).to.equal(
|
||||||
* TODO: add more tests, e.g. for:
|
'Vorige maand, oktober 2019',
|
||||||
* - weekdays
|
);
|
||||||
* - weekday abbreviations
|
|
||||||
* - month names
|
expect(elObj.weekdayHeaderEls.map(h => h.getAttribute('aria-label'))).to.eql([
|
||||||
*/
|
'zondag',
|
||||||
|
'maandag',
|
||||||
|
'dinsdag',
|
||||||
|
'woensdag',
|
||||||
|
'donderdag',
|
||||||
|
'vrijdag',
|
||||||
|
'zaterdag',
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(elObj.weekdayHeaderEls.map(h => h.textContent.trim())).to.deep.equal([
|
||||||
|
'zo',
|
||||||
|
'ma',
|
||||||
|
'di',
|
||||||
|
'wo',
|
||||||
|
'do',
|
||||||
|
'vr',
|
||||||
|
'za',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ describe('dayTemplate', () => {
|
||||||
<td role="gridcell" class="calendar__day-cell">
|
<td role="gridcell" class="calendar__day-cell">
|
||||||
<button
|
<button
|
||||||
class="calendar__day-button"
|
class="calendar__day-button"
|
||||||
tabindex="-1"
|
|
||||||
aria-label="19 April 2019 Friday"
|
aria-label="19 April 2019 Friday"
|
||||||
aria-pressed="false"
|
aria-pressed="false"
|
||||||
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
19
|
19
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue