Commit 58310411 authored by Ermolaev Timur's avatar Ermolaev Timur

#79 Начал писать тесты для функций

parent c8d15d28
This source diff could not be displayed because it is too large. You can view the blob instead.
export const getDaysInMonth = (dateNow) => { export const getDaysInMonth = (dateNow) => {
if (dateNow.month <= 11 && dateNow.month >= 0) {
const newDaysInMonth = [] const newDaysInMonth = []
const daysInMonthNumber = new Date(dateNow.year, dateNow.month + 1, 0).getDate() const daysInMonthNumber = new Date(dateNow.year, dateNow.month + 1, 0).getDate()
for (let i = 1; i <= daysInMonthNumber; i++) { for (let i = 1; i <= daysInMonthNumber; i++) {
...@@ -7,16 +8,27 @@ export const getDaysInMonth = (dateNow) => { ...@@ -7,16 +8,27 @@ export const getDaysInMonth = (dateNow) => {
newDaysInMonth.push({dayNumber: i, dayOfWeek: getDayOfWeekString}) newDaysInMonth.push({dayNumber: i, dayOfWeek: getDayOfWeekString})
} }
return newDaysInMonth return newDaysInMonth
} else {
return null
}
} }
export const getCurrentMonthString = (dateNow) => { export const getCurrentMonthString = (dateNow) => {
if (dateNow.month <= 11 && dateNow.month >= 0) {
return ["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь", "Декабрь"][dateNow.month]; return ["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь", "Декабрь"][dateNow.month];
} else {
return null
}
} }
export const dateToISOLikeButLocal = (date) => { export const dateToISOLikeButLocal = (date) => {
if (date instanceof Date && !isNaN(date)) {
const offsetMs = date.getTimezoneOffset() * 60 * 1000; const offsetMs = date.getTimezoneOffset() * 60 * 1000;
const msLocal = date.getTime() - offsetMs; const msLocal = date.getTime() - offsetMs;
const dateLocal = new Date(msLocal); const dateLocal = new Date(msLocal);
const iso = dateLocal.toISOString(); const iso = dateLocal.toISOString();
return iso; return iso;
} else {
return null
}
} }
\ No newline at end of file
import {getDaysInMonth, getCurrentMonthString, dateToISOLikeButLocal} from '../helpers/CalendarHelpers';
import {taskIsAvailableInCell} from '../components/MonthCalendarBody/CalendarRowDay/Helpers'
describe('Получение дней в феврале 2022', () => {
test('Всего дней', () => {
expect(getDaysInMonth({year:2022, month:1}).length).toBe(28);
})
test('Первый день', () => {
expect(getDaysInMonth({year:2022, month:1})[0]).toEqual({dayNumber: 1, dayOfWeek: 'ВТ'});
})
test('Последний день', () => {
expect(getDaysInMonth({year:2022, month:1})[27]).toEqual({dayNumber: 28, dayOfWeek: 'ПН'});
})
test('Неккоретное значение выше нормы', () => {
expect(getDaysInMonth({year:2022, month:12})).toBe(null);
})
test('Неккоретное значение ниже нормы', () => {
expect(getDaysInMonth({year:2022, month:-1})).toBe(null);
})
})
describe('Получение дней в ноябре 2022', () => {
test('Всего дней', () => {
expect(getDaysInMonth({year:2022, month:10}).length).toBe(30);
})
test('Первый день', () => {
expect(getDaysInMonth({year:2022, month:10})[0]).toEqual({dayNumber: 1, dayOfWeek: 'ВТ'});
})
test('Последний день', () => {
expect(getDaysInMonth({year:2022, month:10})[29]).toEqual({dayNumber: 30, dayOfWeek: 'СР'});
})
})
describe('Получение месяца', () => {
test('Первый месяц', () => {
expect(getCurrentMonthString({month:0})).toBe("Январь");
})
test('Последний месяц', () => {
expect(getCurrentMonthString({month:11})).toBe("Декабрь");
})
test('Неккоретное значение выше нормы', () => {
expect(getCurrentMonthString({month:12})).toBe(null);
})
test('Неккоретное значение ниже нормы', () => {
expect(getCurrentMonthString({month:-1})).toBe(null);
})
})
describe('Получение ISO даты', () => {
test('Валидная дата', () => {
expect(dateToISOLikeButLocal(new Date(2021, 11, 28, 5, 59))).toBe("2021-12-28T05:59:00.000Z");
})
test('Не валидная дата', () => {
expect(dateToISOLikeButLocal(new Date(2021, 'sd', 28, 5, 59))).toBe(null);
})
})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment