@@ -4,9 +4,12 @@ import userEvent from '@testing-library/user-event';
44import { Single } from '../app/components/Examples' ;
55import { getLocaleMonth } from './utils' ;
66
7+ const dateInstance = new Date ( 2022 , 9 , 1 ) ;
8+ const idValue = 'value' ;
9+ const idSelectedDates = 'selected-dates' ;
10+
711describe ( 'common functionality' , ( ) => {
812 it ( 'should display correct year/month' , async ( ) => {
9- const dateInstance = new Date ( 2022 , 9 , 1 ) ;
1013 jest . useFakeTimers ( { now : dateInstance } ) ;
1114 const user = userEvent . setup ( { delay : null } ) ;
1215 render ( < Single /> ) ;
@@ -49,4 +52,29 @@ describe('common functionality', () => {
4952 expect ( screen . getByText ( currentMonth ) ) . toBeInTheDocument ( ) ;
5053 expect ( screen . getByTitle ( 'today' ) ) . toHaveTextContent ( '1' ) ;
5154 } ) ;
55+
56+ it ( 'should change value and selected dates correctly' , async ( ) => {
57+ jest . useFakeTimers ( { now : dateInstance } ) ;
58+ const user = userEvent . setup ( { delay : null } ) ;
59+ render ( < Single /> ) ;
60+ const valueBlock = screen . getByTestId ( idValue ) ;
61+ const datesBlock = screen . getByTestId ( idSelectedDates ) ;
62+ let testString = dateInstance . toDateString ( ) ;
63+ expect ( valueBlock ) . toHaveTextContent ( testString ) ;
64+ expect ( datesBlock ) . toHaveTextContent ( testString ) ;
65+
66+ const date10 = screen . getByRole ( 'button' , { name : '10' } ) ;
67+ await user . click ( date10 ) ;
68+ testString = new Date ( 2022 , 9 , 10 ) . toDateString ( ) ;
69+ expect ( valueBlock ) . toHaveTextContent ( testString ) ;
70+ expect ( datesBlock ) . toHaveTextContent ( testString ) ;
71+ expect ( datesBlock . childElementCount ) . toBe ( 2 ) ;
72+
73+ const date20 = screen . getByRole ( 'button' , { name : '20' } ) ;
74+ await user . click ( date20 ) ;
75+ testString = new Date ( 2022 , 9 , 20 ) . toDateString ( ) ;
76+ expect ( valueBlock ) . toHaveTextContent ( testString ) ;
77+ expect ( datesBlock ) . toHaveTextContent ( testString ) ;
78+ expect ( datesBlock . childElementCount ) . toBe ( 2 ) ;
79+ } ) ;
5280} ) ;
0 commit comments