Skip to content

Commit

Permalink
refactor: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioCastigliano committed Oct 12, 2023
1 parent dee1799 commit 9197f0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/components/sbb-calendar/sbb-calendar.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ describe('sbb-calendar', () => {
let element: SbbCalendar;

beforeEach(async () => {
await fixture(
element = await fixture(
html`<sbb-calendar data-now="1673348400000" selected-date="${selected}"></sbb-calendar>`,
);
element = document.querySelector('sbb-calendar');
await element.updateComplete;
});

it('renders', async () => {
Expand Down Expand Up @@ -98,9 +96,8 @@ describe('sbb-calendar', () => {

it('selects a different date', async () => {
const selectedSpy = new EventSpy('date-selected');
await element.updateComplete;

const selectedDate = element.shadowRoot.querySelector('button[data-day="15 1 2023"]');

expect(selectedDate).to.have.class('sbb-calendar__selected');

const newSelectedDate = element.shadowRoot.querySelector(
Expand Down Expand Up @@ -194,7 +191,7 @@ describe('sbb-calendar', () => {
expect(monthCells.length).to.be.equal(12);
expect(monthCells[0]).dom.to.be.equal(`
<td class="sbb-calendar__table-data sbb-calendar__table-month">
<button aria-disabled="false" aria-label="January 2023" aria-pressed="true" class="sbb-calendar__cell sbb-calendar__pill sbb-calendar__selected sbb-calendar__cell-current" data-month="0" tabindex="0">
<button aria-disabled="false" aria-label="January 2023" aria-pressed="true" class="sbb-calendar__cell sbb-calendar__pill sbb-calendar__selected sbb-calendar__cell-current" tabindex="0">
Jan
</button>
</td>
Expand Down Expand Up @@ -395,7 +392,6 @@ describe('sbb-calendar', () => {
});

it('navigates up via keyboard', async () => {
await element.updateComplete;
expect(
(document.activeElement.shadowRoot.activeElement as HTMLElement).innerText,
).to.be.equal('2023');
Expand Down Expand Up @@ -424,7 +420,6 @@ describe('sbb-calendar', () => {
});

it('navigates to first day via keyboard', async () => {
await element.updateComplete;
expect(
(document.activeElement.shadowRoot.activeElement as HTMLElement).innerText,
).to.be.equal('2023');
Expand Down
4 changes: 2 additions & 2 deletions src/components/sbb-calendar/sbb-calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ export class SbbCalendar extends LitElement {
aria-pressed=${selected}
aria-disabled=${isOutOfRange || isFilteredOut}
aria-current=${isToday ? 'date' : nothing}
data-day=${dayValue}
data-day=${dayValue || nothing}
tabindex="-1"
@keydown=${(evt: KeyboardEvent) => this._handleKeyboardEvent(evt, day)}
sbb-tooltip-close
Expand Down Expand Up @@ -1015,7 +1015,7 @@ export class SbbCalendar extends LitElement {
aria-pressed=${selected}
aria-disabled=${String(isOutOfRange || isFilteredOut)}
tabindex="-1"
data-month=${month.monthValue}
data-month=${month.monthValue || nothing}
@keydown=${(evt: KeyboardEvent) => this._handleKeyboardEvent(evt)}
>
${month.value}
Expand Down

0 comments on commit 9197f0d

Please sign in to comment.