Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reidbarber committed Nov 27, 2024
1 parent 94241a4 commit 37b329a
Showing 1 changed file with 56 additions and 10 deletions.
66 changes: 56 additions & 10 deletions packages/@react-spectrum/calendar/test/CalendarBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,15 @@ describe('CalendarBase', () => {
});

it.each`
Name | Calendar | props
${'v3 Calendar'} | ${Calendar} | ${{defaultValue: new CalendarDate(2024, 1, 1)}}
${'v3 RangeCalendar'} | ${RangeCalendar} | ${{defaultValue: {start: new CalendarDate(2024, 1, 1), end: new CalendarDate(2024, 1, 1)}}}
`('$Name should override start of week with firstDayOfWeek="mon"', ({Calendar, props}) => {
let {getAllByRole, getByRole} = render(<Calendar {...props} firstDayOfWeek="mon" />);
Name | Calendar | props | locale
${'v3 Calendar'} | ${Calendar} | ${{defaultValue: new CalendarDate(2024, 1, 1)}} | ${'en-US'}}
${'v3 RangeCalendar'} | ${RangeCalendar} | ${{defaultValue: {start: new CalendarDate(2024, 1, 1), end: new CalendarDate(2024, 1, 1)}}} | ${'en-US'}}
`('$Name should override start of week with firstDayOfWeek="mon" (en-US)', ({Calendar, props, locale = 'en-US'}) => {
let {getAllByRole, getByRole} = render(
<Provider theme={theme} locale={locale}>
<Calendar {...props} firstDayOfWeek="mon" />
</Provider>
);

let grid = getByRole('grid');
let headers = getAllByRole('columnheader', {hidden: true});
Expand All @@ -806,11 +810,15 @@ describe('CalendarBase', () => {
});

it.each`
Name | Calendar | props
${'v3 Calendar'} | ${Calendar} | ${{defaultValue: new CalendarDate(2024, 1, 1)}}
${'v3 RangeCalendar'} | ${RangeCalendar} | ${{defaultValue: {start: new CalendarDate(2024, 1, 1), end: new CalendarDate(2024, 1, 1)}}}
`('$Name should override start of week with firstDayOfWeek="sat"', ({Calendar, props}) => {
let {getAllByRole, getByRole} = render(<Calendar {...props} firstDayOfWeek="sat" />);
Name | Calendar | props | locale
${'v3 Calendar'} | ${Calendar} | ${{defaultValue: new CalendarDate(2024, 1, 1)}} | ${'en-US'}}
${'v3 RangeCalendar'} | ${RangeCalendar} | ${{defaultValue: {start: new CalendarDate(2024, 1, 1), end: new CalendarDate(2024, 1, 1)}}} | ${'en-US'}}
`('$Name should override start of week with firstDayOfWeek="sat" (en-US)', ({Calendar, props, locale}) => {
let {getAllByRole, getByRole} = render(
<Provider theme={theme} locale={locale}>
<Calendar {...props} firstDayOfWeek="sat" />
</Provider>
);

let grid = getByRole('grid');
let headers = getAllByRole('columnheader', {hidden: true});
Expand All @@ -819,5 +827,43 @@ describe('CalendarBase', () => {
let cells = within(grid).getAllByRole('gridcell');
expect(cells[2]).toHaveTextContent('1');
});

it.each`
Name | Calendar | props | locale
${'v3 Calendar'} | ${Calendar} | ${{defaultValue: new CalendarDate(2024, 1, 1)}} | ${'fr-FR'}}
${'v3 RangeCalendar'} | ${RangeCalendar} | ${{defaultValue: {start: new CalendarDate(2024, 1, 1), end: new CalendarDate(2024, 1, 1)}}} | ${'fr-FR'}}
`('$Name should override start of week with firstDayOfWeek="mon" (fr-FR)', ({Calendar, props, locale}) => {
let {getAllByRole, getByRole} = render(
<Provider theme={theme} locale={locale}>
<Calendar {...props} firstDayOfWeek="mon" />
</Provider>
);

let grid = getByRole('grid');
let headers = getAllByRole('columnheader', {hidden: true});
expect(headers.map(h => h.textContent)).toEqual(['L', 'M', 'M', 'J', 'V', 'S', 'D']);

let cells = within(grid).getAllByRole('gridcell');
expect(cells[0]).toHaveTextContent('1');
});

it.each`
Name | Calendar | props | locale
${'v3 Calendar'} | ${Calendar} | ${{defaultValue: new CalendarDate(2024, 1, 1)}} | ${'fr-FR'}}
${'v3 RangeCalendar'} | ${RangeCalendar} | ${{defaultValue: {start: new CalendarDate(2024, 1, 1), end: new CalendarDate(2024, 1, 1)}}} | ${'fr-FR'}}
`('$Name should override start of week with firstDayOfWeek="sat" (fr-FR)', ({Calendar, props, locale}) => {
let {getAllByRole, getByRole} = render(
<Provider theme={theme} locale={locale}>
<Calendar {...props} firstDayOfWeek="sat" />
</Provider>
);

let grid = getByRole('grid');
let headers = getAllByRole('columnheader', {hidden: true});
expect(headers.map(h => h.textContent)).toEqual(['S', 'D', 'L', 'M', 'M', 'J', 'V']);

let cells = within(grid).getAllByRole('gridcell');
expect(cells[2]).toHaveTextContent('1');
});
});
});

0 comments on commit 37b329a

Please sign in to comment.