diff --git a/src/elements/calendar/calendar.spec.ts b/src/elements/calendar/calendar.spec.ts index f43ffa5ed9..6311ec64e1 100644 --- a/src/elements/calendar/calendar.spec.ts +++ b/src/elements/calendar/calendar.spec.ts @@ -1,5 +1,6 @@ import { assert, expect } from '@open-wc/testing'; -import { sendKeys } from '@web/test-runner-commands'; +import { SbbBreakpointMediumMin } from '@sbb-esta/lyne-design-tokens'; +import { sendKeys, setViewport } from '@web/test-runner-commands'; import { html } from 'lit/static-html.js'; import type { SbbSecondaryButtonElement } from '../button/secondary-button.js'; @@ -209,6 +210,47 @@ describe(`sbb-calendar`, () => { expect(dayCells.length).to.be.equal(31); }); + it('changes to year and month selection views if wide', async () => { + await setViewport({ width: SbbBreakpointMediumMin, height: 1000 }); + element.wide = true; + + await waitForLitRender(element); + + // Open year selection + element + .shadowRoot!.querySelector('button#sbb-calendar__date-selection')! + .click(); + + await waitForTransition(); + await waitForLitRender(element); + + const selectedYear: HTMLElement = Array.from( + element.shadowRoot!.querySelectorAll('.sbb-calendar__table-year'), + ).find((e) => e.innerText === '2063')!; + const yearButton: HTMLElement = selectedYear.querySelector('button')!; + + // Open month selection + yearButton.click(); + + await waitForLitRender(element); + await waitForTransition(); + + // Click last available month on right side + element + .shadowRoot!.querySelector('button[aria-label="December 2062"]')! + .click(); + + await waitForLitRender(element); + await waitForTransition(); + + // Day view should be opened with December 2062 + expect( + element + .shadowRoot!.querySelector('button#sbb-calendar__date-selection')! + .innerText.trim(), + ).to.be.equal('December 2062'); + }); + it('renders with min and max', async () => { const page: HTMLElement = await fixture( html` extends SbbHydrationMixin(LitElement) {
${this._createMonthTable(this._months, this._chosenYear!)} - ${this._wide ? this._createMonthTable(this._months, this._chosenYear! + 1, true) : nothing} + ${this._wide ? this._createMonthTable(this._months, this._chosenYear! + 1) : nothing}
`; } @@ -1050,7 +1050,7 @@ class SbbCalendarElement extends SbbHydrationMixin(LitElement) { } /** Creates the table for the month selection view. */ - private _createMonthTable(months: Month[][], year: number, shiftRight = false): TemplateResult { + private _createMonthTable(months: Month[][], year: number): TemplateResult { return html` extends SbbHydrationMixin(LitElement) { 'sbb-calendar__crossed-out': !isOutOfRange && isFilteredOut, 'sbb-calendar__selected': selected, })} - @click=${() => this._onMonthSelection(month.monthValue, year, shiftRight)} + @click=${() => this._onMonthSelection(month.monthValue, year)} ?disabled=${isOutOfRange || isFilteredOut} aria-label=${`${month.longValue} ${this._chosenYear}`} aria-pressed=${selected} @@ -1119,8 +1119,8 @@ class SbbCalendarElement extends SbbHydrationMixin(LitElement) { } /** Select the month and change the view to day selection. */ - private _onMonthSelection(month: number, year: number, shiftRight: boolean): void { - this._chosenMonth = shiftRight ? month + 1 : month; + private _onMonthSelection(month: number, year: number): void { + this._chosenMonth = month; this._nextCalendarView = 'day'; this._init( this._dateAdapter.createDate(