Commit d98464d7 authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'task-79-feature/create_unit_tests' into 'development'

Task 79 feature/create unit tests

See merge request !56
parents c8d15d28 d70bebb7
This source diff could not be displayed because it is too large. You can view the blob instead.
export const getDaysInMonth = (dateNow) => {
if (dateNow.month <= 11 && dateNow.month >= 0) {
const newDaysInMonth = []
const daysInMonthNumber = new Date(dateNow.year, dateNow.month + 1, 0).getDate()
for (let i = 1; i <= daysInMonthNumber; i++) {
......@@ -7,16 +8,27 @@ export const getDaysInMonth = (dateNow) => {
newDaysInMonth.push({dayNumber: i, dayOfWeek: getDayOfWeekString})
}
return newDaysInMonth
} else {
return null
}
}
export const getCurrentMonthString = (dateNow) => {
if (dateNow.month <= 11 && dateNow.month >= 0) {
return ["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь", "Декабрь"][dateNow.month];
} else {
return null
}
}
export const dateToISOLikeButLocal = (date) => {
if (date instanceof Date && !isNaN(date)) {
const offsetMs = date.getTimezoneOffset() * 60 * 1000;
const msLocal = date.getTime() - offsetMs;
const dateLocal = new Date(msLocal);
const iso = dateLocal.toISOString();
return iso;
} else {
return null
}
}
\ No newline at end of file
import {getDaysInMonth, getCurrentMonthString, dateToISOLikeButLocal} from '../helpers/CalendarHelpers';
import {getAvailableTasks, getSortedTasks} 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);
})
})
describe('Получение допустимых задач для клетки', () => {
test('Валидные задачи', () => {
expect(getAvailableTasks([{infoForCell: {startYear: 2022, startMonth: 12, startDay: 12}}, {infoForCell: {startYear: 2022, startMonth: 12, startDay: 12}}], 2022, 11, 12).length).toBe(2);
})
test('Не валидные задачи', () => {
expect(getAvailableTasks([{infoForCell: {startYear: 2021, startMonth: 11, startDay: 12}}, {infoForCell: {startYear: 2022, startMonth: 12, startDay: 14}}], 2022, 11, 12).length).toBe(0);
})
test('Не все прошедшие проверку задачи', () => {
expect(getAvailableTasks([{infoForCell: {startYear: 2021, startMonth: 11, startDay: 12}}, {infoForCell: {startYear: 2022, startMonth: 12, startDay: 12}}], 2022, 11, 12).length).toBe(1);
})
})
\ 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