From bb785f6b5b03025a3fc630337827e1ecab251682 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 8 Feb 2024 18:54:06 +0100 Subject: [PATCH] ref: move generateMonthMatrixTest to TS --- ...trixTest.js => generateMonthMatrixTest.ts} | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) rename tests/unit/{generateMonthMatrixTest.js => generateMonthMatrixTest.ts} (85%) diff --git a/tests/unit/generateMonthMatrixTest.js b/tests/unit/generateMonthMatrixTest.ts similarity index 85% rename from tests/unit/generateMonthMatrixTest.js rename to tests/unit/generateMonthMatrixTest.ts index 67dd65e6b1fd..6f81ebc5c585 100644 --- a/tests/unit/generateMonthMatrixTest.js +++ b/tests/unit/generateMonthMatrixTest.ts @@ -1,8 +1,10 @@ -import generateMonthMatrix from '../../src/components/DatePicker/CalendarPicker/generateMonthMatrix'; +import generateMonthMatrix from '@src/components/DatePicker/CalendarPicker/generateMonthMatrix'; + +type MonthMatrix = Array>; describe('generateMonthMatrix', () => { it('returns the correct matrix for January 2022', () => { - const expected = [ + const expected: MonthMatrix = [ [null, null, null, null, null, 1, 2], [3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16], @@ -14,7 +16,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for February 2022', () => { - const expected = [ + const expected: MonthMatrix = [ [null, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], @@ -25,7 +27,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for leap year February 2020', () => { - const expected = [ + const expected: MonthMatrix = [ [null, null, null, null, null, 1, 2], [3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16], @@ -36,7 +38,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for March 2022', () => { - const expected = [ + const expected: MonthMatrix = [ [null, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], @@ -47,7 +49,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for April 2022', () => { - const expected = [ + const expected: MonthMatrix = [ [null, null, null, null, 1, 2, 3], [4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17], @@ -58,7 +60,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for December 2022', () => { - const expected = [ + const expected: MonthMatrix = [ [null, null, null, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], @@ -69,7 +71,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for January 2025', () => { - const expected = [ + const expected: MonthMatrix = [ [null, null, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18, 19], @@ -80,7 +82,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for February 2025', () => { - const expected = [ + const expected: MonthMatrix = [ [null, null, null, null, null, 1, 2], [3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16], @@ -91,7 +93,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for June 2025', () => { - const expected = [ + const expected: MonthMatrix = [ [null, null, null, null, null, null, 1], [2, 3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15], @@ -103,7 +105,7 @@ describe('generateMonthMatrix', () => { }); it('returns the correct matrix for December 2025', () => { - const expected = [ + const expected: MonthMatrix = [ [1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], @@ -125,13 +127,6 @@ describe('generateMonthMatrix', () => { expect(() => generateMonthMatrix(-1, 0)).toThrow(); }); - it('throws an error if year or month is not a number', () => { - expect(() => generateMonthMatrix()).toThrow(); - expect(() => generateMonthMatrix(2022, 'invalid')).toThrow(); - expect(() => generateMonthMatrix('2022', '0')).toThrow(); - expect(() => generateMonthMatrix(null, undefined)).toThrow(); - }); - it('returns a matrix with 6 rows and 7 columns for January 2022', () => { const matrix = generateMonthMatrix(2022, 0); expect(matrix.length).toBe(6);