import { screen } from '@testing-library/react' ; import { format } from 'date-fns' ; export function getDayButton ( day ) { return screen . getByRole ( 'button' , { name : format ( day , 'do MMMM (EEEE)' ) } ) ; } export function getAllSelectedDays ( ) { const buttons = screen . getByRole ( 'grid' ) . getElementsByTagName ( 'tbody' ) [ 0 ] . getElementsByTagName ( 'button' ) ; return Array . from ( buttons ) . filter ( ( button ) => button . getAttribute ( 'aria-pressed' ) === 'true' ) ; } export function getAllEnabledDays ( ) { const buttons = screen . getByRole ( 'grid' ) . getElementsByTagName ( 'tbody' ) [ 0 ] . getElementsByTagName ( 'button' ) ; return Array . from ( buttons ) . filter ( ( button ) => ! button . disabled ) ; } export function getDayButtons ( day ) { return screen . getByRole ( 'button' , { name : format ( day , 'do MMMM (EEEE)' ) } ) ; } export function queryDayButton ( day ) { return screen . queryByRole ( 'button' , { name : format ( day , 'do MMMM (EEEE)' ) } ) ; } export function getDayCell ( day ) { return screen . getByRole ( 'cell' , { name : format ( day , 'do MMMM (EEEE)' ) } ) ; } export function getWeekButton ( week ) { return screen . getByRole ( 'button' , { name : `Week n. ${ week }` } ) ; } export function getTableFooter ( ) { return screen . getByRole ( 'grid' ) . querySelector ( 'tfoot' ) ; } export function getPrevButton ( ) { return screen . getByRole ( 'button' , { name : 'Go to previous month' } ) ; } export function queryPrevButton ( ) { return screen . queryByRole ( 'button' , { name : 'Go to previous month' } ) ; } export function getNextButton ( ) { return screen . getByRole ( 'button' , { name : 'Go to next month' } ) ; } export function queryNextButton ( ) { return screen . queryByRole ( 'button' , { name : 'Go to next month' } ) ; } export function getMonthCaption ( displayIndex = 0 ) { return screen . getAllByRole ( 'heading' , { level : 2 } ) [ displayIndex ] ; } export function getMonthGrid ( index = 0 ) { return screen . getAllByRole ( 'grid' ) [ index ] ; } export function queryMonthGrids ( ) { return screen . getAllByRole ( 'grid' ) ; } export function getYearDropdown ( ) { return screen . getByRole ( 'combobox' , { name : 'Year:' } ) ; } export function getMonthDropdown ( ) { return screen . getByRole ( 'combobox' , { name : 'Month:' } ) ; } export function getFocusedElement ( ) { if ( ! document . activeElement ) { throw new Error ( 'Could not find any focused element' ) ; } return document . activeElement ; }