diff --git a/__tests__/datePicker.darkMode.test.js b/__tests__/datePicker.darkMode.test.js index f7e23cd..0942e2b 100644 --- a/__tests__/datePicker.darkMode.test.js +++ b/__tests__/datePicker.darkMode.test.js @@ -1,4 +1,4 @@ -import DatePicker from "../src/datePicker"; +import DatePicker from '../src/datePicker'; describe('Dark/light mode UI', () => { let datePicker; @@ -12,7 +12,7 @@ describe('Dark/light mode UI', () => { datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), - darkMode: true + darkMode: true, }); datePicker.init(); @@ -24,7 +24,7 @@ describe('Dark/light mode UI', () => { datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), - darkMode: false + darkMode: false, }); datePicker.init(); diff --git a/__tests__/datePicker.interactions.test.js b/__tests__/datePicker.interactions.test.js index da56877..1bcb349 100644 --- a/__tests__/datePicker.interactions.test.js +++ b/__tests__/datePicker.interactions.test.js @@ -1,5 +1,5 @@ -import DatePicker from '../src/datePicker' -import { getMonthName } from '../src/utils' +import DatePicker from '../src/datePicker'; +import { getMonthName } from '../src/utils'; describe('Interactions and basic functionality', () => { let datePicker; @@ -11,7 +11,8 @@ describe('Interactions and basic functionality', () => { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, + selectPastDatesEnabled: true, }); datePicker.init(); }); @@ -81,7 +82,7 @@ describe('Interactions and basic functionality', () => { datePicker.selectedEndDate = new Date(2023, 5, 15); const newStartDate = new Date(2023, 5, 20); datePicker.handleDayClick(newStartDate.getDate(), newStartDate.getMonth()); - expect(datePicker.selectedStartDate).toEqual(newStartDate); + expect(datePicker.selectedStartDate.toString()).toMatch(newStartDate.toString()); expect(datePicker.selectedEndDate).toBeNull(); }); -}); \ No newline at end of file +}); diff --git a/__tests__/datePicker.leapYear.test.js b/__tests__/datePicker.leapYear.test.js index 9ae9727..3ef8e03 100644 --- a/__tests__/datePicker.leapYear.test.js +++ b/__tests__/datePicker.leapYear.test.js @@ -1,4 +1,4 @@ -import DatePicker from '../src/datePicker' +import DatePicker from '../src/datePicker'; describe('Leap year handling', () => { let datePicker; @@ -10,7 +10,7 @@ describe('Leap year handling', () => { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -28,4 +28,4 @@ describe('Leap year handling', () => { const days = datePicker.element.querySelectorAll('.datepicker-day.current-month'); expect(days.length).toBe(29); }); -}); \ No newline at end of file +}); diff --git a/__tests__/datePicker.localization.test.js b/__tests__/datePicker.localization.test.js index 43e1ce6..f2cc82e 100644 --- a/__tests__/datePicker.localization.test.js +++ b/__tests__/datePicker.localization.test.js @@ -1,4 +1,4 @@ -import DatePicker from "../src/datePicker"; +import DatePicker from '../src/datePicker'; jest.useFakeTimers(); @@ -6,14 +6,13 @@ const containerId = 'test-container'; let datePicker; describe('Localization', () => { - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -185,7 +184,6 @@ describe('Localization', () => { }); }); - describe('Localization for Bulgarian (bg-BG)', () => { let datePicker; @@ -195,7 +193,7 @@ describe('Localization for Bulgarian (bg-BG)', () => { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -220,14 +218,13 @@ describe('Localization for Bulgarian (bg-BG)', () => { describe('Localization for Czech (cs)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -252,14 +249,13 @@ describe('Localization for Czech (cs)', () => { describe('Localization for Danish (da)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -284,14 +280,13 @@ describe('Localization for Danish (da)', () => { describe('Localization for Greek (el)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -313,18 +308,16 @@ describe('Localization for Greek (el)', () => { }); }); - describe('Localization for Finnish (fi)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -346,18 +339,16 @@ describe('Localization for Finnish (fi)', () => { }); }); - describe('Localization for Croatian (hr-HR)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -379,18 +370,16 @@ describe('Localization for Croatian (hr-HR)', () => { }); }); - describe('Localization for Hungarian (hu)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -412,18 +401,16 @@ describe('Localization for Hungarian (hu)', () => { }); }); - describe('Localization for Indonesian (id)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -445,18 +432,16 @@ describe('Localization for Indonesian (id)', () => { }); }); - describe('Localization for Korean (ko)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -478,18 +463,16 @@ describe('Localization for Korean (ko)', () => { }); }); - describe('Localization for Lithuanian (lt-LT)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -511,18 +494,16 @@ describe('Localization for Lithuanian (lt-LT)', () => { }); }); - describe('Localization for Norwegian Bokmål (nb)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -544,18 +525,16 @@ describe('Localization for Norwegian Bokmål (nb)', () => { }); }); - describe('Localization for Polish (pl)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -580,14 +559,13 @@ describe('Localization for Polish (pl)', () => { describe('Localization for Brazilian Portuguese (pt-BR)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -612,14 +590,13 @@ describe('Localization for Brazilian Portuguese (pt-BR)', () => { describe('Localization for European Portuguese (pt-PT)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -644,14 +621,13 @@ describe('Localization for European Portuguese (pt-PT)', () => { describe('Localization for Romanian (ro-RO)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -676,7 +652,6 @@ describe('Localization for Romanian (ro-RO)', () => { describe('Localization for Slovak (sk-SK)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; @@ -684,7 +659,7 @@ describe('Localization for Slovak (sk-SK)', () => { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -710,14 +685,13 @@ describe('Localization for Slovak (sk-SK)', () => { describe('Localization for Slovenian (sl-SL)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -742,14 +716,13 @@ describe('Localization for Slovenian (sl-SL)', () => { describe('Localization for Swedish (sv)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -774,14 +747,13 @@ describe('Localization for Swedish (sv)', () => { describe('Localization for Thai (th)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -806,14 +778,13 @@ describe('Localization for Thai (th)', () => { describe('Localization for Turkish (tr)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -835,18 +806,16 @@ describe('Localization for Turkish (tr)', () => { }); }); - describe('Localization for Vietnamese (vi)', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -868,16 +837,14 @@ describe('Localization for Vietnamese (vi)', () => { }); }); - describe('Localization with Page Language', () => { let datePicker; - beforeEach(() => { document.body.innerHTML = `
`; }); - const setHtmlLangAttribute = (lang) => { + const setHtmlLangAttribute = lang => { document.documentElement.lang = lang; }; @@ -887,7 +854,7 @@ describe('Localization with Page Language', () => { datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), - usePageLanguage: true + usePageLanguage: true, }); datePicker.init(); datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 @@ -901,7 +868,6 @@ describe('Localization with Page Language', () => { }); }; - testPageLanguageSetting('en', 'Sun', 'January 2023'); testPageLanguageSetting('fr', 'Dim', 'Janvier 2023'); testPageLanguageSetting('es', 'Dom', 'Enero 2023'); @@ -935,9 +901,7 @@ describe('Localization with Page Language', () => { testPageLanguageSetting('tr', 'Paz', 'Ocak 2023'); testPageLanguageSetting('vi', 'CN', 'Tháng Một 2023'); - afterEach(() => { setHtmlLangAttribute('en'); }); }); - diff --git a/__tests__/datePicker.test.js b/__tests__/datePicker.test.js index f240024..f05ea0a 100644 --- a/__tests__/datePicker.test.js +++ b/__tests__/datePicker.test.js @@ -1,18 +1,17 @@ -import DatePicker from "../src/datePicker"; +import DatePicker from '../src/datePicker'; jest.useFakeTimers(); let datePicker; const containerId = 'test-container'; describe('DatePicker', () => { - beforeEach(() => { document.body.innerHTML = `
`; datePicker = new DatePicker(containerId, { mode: 'single', onSelect: jest.fn(), blockedDays: [0, 6], // Sundays and Saturdays - showDayNames: true + showDayNames: true, }); datePicker.init(); }); @@ -32,7 +31,7 @@ describe('DatePicker', () => { mode: 'single', onSelect: null, blockedDays: [], - showDayNames: true + showDayNames: true, }); }); @@ -65,7 +64,6 @@ describe('DatePicker', () => { }); }); - describe('Corner Style', () => { test('applies round style by default', () => { datePicker = new DatePicker(containerId, {});