|
6 | 6 | getToday, |
7 | 7 | getCombinedDateColumnData, |
8 | 8 | getTimeColumnsData, |
| 9 | + getMonthColumnData, |
9 | 10 | } from '../utils/data'; |
10 | 11 |
|
11 | 12 | // The minutes are the same across all hour cycles, so we don't check those |
@@ -516,3 +517,33 @@ describe('getCombinedDateColumnData', () => { |
516 | 517 | ]); |
517 | 518 | }); |
518 | 519 | }); |
| 520 | + |
| 521 | +describe('getMonthColumnData()', () => { |
| 522 | + const monthValues = [1, 3, 5, 7, 9, 11]; |
| 523 | + const getValues = (refParts: DatetimeParts, minParts?: DatetimeParts, maxParts?: DatetimeParts) => |
| 524 | + getMonthColumnData('en-US', refParts, minParts, maxParts, monthValues).map((option) => option.value); |
| 525 | + |
| 526 | + it('should apply the min month only in the min year when monthValues is set', () => { |
| 527 | + const minParts = { month: 6, day: 1, year: 2020 }; |
| 528 | + |
| 529 | + expect(getValues({ month: 5, day: 1, year: 2020 }, minParts)).toEqual([7, 9, 11]); |
| 530 | + expect(getValues({ month: 3, day: 1, year: 2024 }, minParts)).toEqual([1, 3, 5, 7, 9, 11]); |
| 531 | + }); |
| 532 | + |
| 533 | + it('should apply the max month only in the max year when monthValues is set', () => { |
| 534 | + const maxParts = { month: 4, day: 30, year: 2025 }; |
| 535 | + |
| 536 | + expect(getValues({ month: 3, day: 1, year: 2025 }, undefined, maxParts)).toEqual([1, 3]); |
| 537 | + expect(getValues({ month: 9, day: 1, year: 2024 }, undefined, maxParts)).toEqual([1, 3, 5, 7, 9, 11]); |
| 538 | + }); |
| 539 | + |
| 540 | + it('should match the months shown when monthValues is not set', () => { |
| 541 | + const minParts = { month: 6, day: 1, year: 2020 }; |
| 542 | + const maxParts = { month: 4, day: 30, year: 2025 }; |
| 543 | + const refParts = { month: 3, day: 1, year: 2024 }; |
| 544 | + |
| 545 | + const allMonths = getMonthColumnData('en-US', refParts, minParts, maxParts).map((option) => option.value); |
| 546 | + expect(allMonths).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]); |
| 547 | + expect(getValues(refParts, minParts, maxParts)).toEqual([1, 3, 5, 7, 9, 11]); |
| 548 | + }); |
| 549 | +}); |
0 commit comments