Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
58310411
Commit
58310411
authored
Nov 30, 2022
by
Ermolaev Timur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#79
Начал писать тесты для функций
parent
c8d15d28
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2007 additions
and
866 deletions
+2007
-866
package-lock.json
planner-front/package-lock.json
+1926
-853
CalendarHelpers.js
planner-front/src/helpers/CalendarHelpers.js
+25
-13
MonthCalendar.test.js
planner-front/src/tests/MonthCalendar.test.js
+56
-0
No files found.
planner-front/package-lock.json
View file @
58310411
This source diff could not be displayed because it is too large. You can
view the blob
instead.
planner-front/src/helpers/CalendarHelpers.js
View file @
58310411
export
const
getDaysInMonth
=
(
dateNow
)
=>
{
const
newDaysInMonth
=
[]
const
daysInMonthNumber
=
new
Date
(
dateNow
.
year
,
dateNow
.
month
+
1
,
0
).
getDate
()
for
(
let
i
=
1
;
i
<=
daysInMonthNumber
;
i
++
)
{
const
dayOfWeekNumber
=
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
i
).
getDay
()
const
getDayOfWeekString
=
[
"ВС"
,
"ПН"
,
"ВТ"
,
"СР"
,
"ЧТ"
,
"ПТ"
,
"СБ"
][
dayOfWeekNumber
]
newDaysInMonth
.
push
({
dayNumber
:
i
,
dayOfWeek
:
getDayOfWeekString
})
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
++
)
{
const
dayOfWeekNumber
=
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
i
).
getDay
()
const
getDayOfWeekString
=
[
"ВС"
,
"ПН"
,
"ВТ"
,
"СР"
,
"ЧТ"
,
"ПТ"
,
"СБ"
][
dayOfWeekNumber
]
newDaysInMonth
.
push
({
dayNumber
:
i
,
dayOfWeek
:
getDayOfWeekString
})
}
return
newDaysInMonth
}
else
{
return
null
}
return
newDaysInMonth
}
export
const
getCurrentMonthString
=
(
dateNow
)
=>
{
return
[
"Январь"
,
"Февраль"
,
"Март"
,
"Апрель"
,
"Май"
,
"Июнь"
,
"Июль"
,
"Август"
,
"Сентябрь"
,
"Октябрь"
,
"Ноябрь"
,
"Декабрь"
][
dateNow
.
month
];
if
(
dateNow
.
month
<=
11
&&
dateNow
.
month
>=
0
)
{
return
[
"Январь"
,
"Февраль"
,
"Март"
,
"Апрель"
,
"Май"
,
"Июнь"
,
"Июль"
,
"Август"
,
"Сентябрь"
,
"Октябрь"
,
"Ноябрь"
,
"Декабрь"
][
dateNow
.
month
];
}
else
{
return
null
}
}
export
const
dateToISOLikeButLocal
=
(
date
)
=>
{
const
offsetMs
=
date
.
getTimezoneOffset
()
*
60
*
1000
;
const
msLocal
=
date
.
getTime
()
-
offsetMs
;
const
dateLocal
=
new
Date
(
msLocal
);
const
iso
=
dateLocal
.
toISOString
();
return
iso
;
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
planner-front/src/tests/MonthCalendar.test.js
0 → 100644
View file @
58310411
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment