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
7e821cde
Commit
7e821cde
authored
Dec 10, 2022
by
Ermolaev Timur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#98
Чуть улучшил код недели, написал дополнительные юнит тесты
parent
beb6a6e8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
173 additions
and
25 deletions
+173
-25
CalendarRow.js
...onthCalendar/MonthCalendarBody/CalendarRow/CalendarRow.js
+1
-1
CalendarRowDayWeek.js
...WeekCalendarBody/CalendarRowDayWeek/CalendarRowDayWeek.js
+25
-0
WeekCalendarBody.js
...ponents/WeekCalendar/WeekCalendarBody/WeekCalendarBody.js
+6
-15
CalendarHelpers.js
planner-front/src/helpers/CalendarHelpers.js
+11
-4
MonthCalendar.test.js
planner-front/src/tests/MonthCalendar.test.js
+62
-5
WeekCalendar.test.js
planner-front/src/tests/WeekCalendar.test.js
+68
-0
No files found.
planner-front/src/components/MonthCalendar/MonthCalendarBody/CalendarRow/CalendarRow.js
View file @
7e821cde
...
...
@@ -5,7 +5,7 @@ const CalendarRow = ({children, week}) => {
<
Grid
container
align
=
'center'
sx
=
{{
borderBottom
:
week
?
null
:
'1px solid black'
,
border
Right
:
'1px solid black'
,
border
Left
:
'1px solid black'
}}
sx
=
{{
borderBottom
:
week
?
null
:
'1px solid black'
,
borderLeft
:
'1px solid black'
}}
>
{
children
}
<
/Grid
>
...
...
planner-front/src/components/WeekCalendar/WeekCalendarBody/CalendarRowDayWeek/CalendarRowDayWeek.js
0 → 100644
View file @
7e821cde
import
{
Grid
}
from
"@mui/material"
;
import
CalendarRow
from
"../../../MonthCalendar/MonthCalendarBody/CalendarRow/CalendarRow"
;
import
CalendarStandartCell
from
"../../../MonthCalendar/MonthCalendarBody/CalendarStandartCell.js/CalendarStandartCell"
;
function
CalendarRowDayWeek
({
week
,
hoursInDay
})
{
return
(
<>
<
Grid
item
xs
=
{
11.005
}
>
<
CalendarRow
week
=
{
true
}
>
{
week
?.
map
((
weekDay
,
i
)
=>
{
return
(
<
Grid
item
key
=
{
i
}
xs
=
{
12
/
week
.
length
}
>
{
hoursInDay
?.
map
((
hour
,
i
)
=>
{
return
(
<
CalendarStandartCell
key
=
{
i
}
week
=
{
true
}
>
<
/CalendarStandartCell>
)
})}
<
/Grid>
)
})}
<
/CalendarRow
>
<
/Grid
>
<
/>
)
;
}
export
default
CalendarRowDayWeek
;
\ No newline at end of file
planner-front/src/components/WeekCalendar/WeekCalendarBody/WeekCalendarBody.js
View file @
7e821cde
...
...
@@ -3,6 +3,7 @@ import { Box } from "@mui/system";
import
CalendarRow
from
"../../MonthCalendar/MonthCalendarBody/CalendarRow/CalendarRow"
;
import
CalendarSmallCell
from
"../../MonthCalendar/MonthCalendarBody/CalendarSmallCell/CalendarSmallCell"
;
import
CalendarStandartCell
from
"../../MonthCalendar/MonthCalendarBody/CalendarStandartCell.js/CalendarStandartCell"
;
import
CalendarRowDayWeek
from
"./CalendarRowDayWeek/CalendarRowDayWeek"
;
import
{
getCurrentWeekDayString
}
from
"./Helpers"
;
function
WeekCalendarBody
({
week
,
hoursInDay
,
hourFormat
,
setHourFormat
})
{
...
...
@@ -42,21 +43,11 @@ function WeekCalendarBody({week, hoursInDay, hourFormat, setHourFormat}) {
})}
<
/Grid
>
<
Grid
item
xs
=
{
11.005
}
>
<
CalendarRow
week
=
{
true
}
>
{
week
?.
map
((
weekDay
,
i
)
=>
{
return
(
<
Grid
item
key
=
{
i
}
xs
=
{
12
/
week
.
length
}
>
{
hoursInDay
?.
map
((
hour
,
i
)
=>
{
return
(
<
CalendarStandartCell
key
=
{
i
}
week
=
{
true
}
>
<
/CalendarStandartCell>
)
})}
<
/Grid>
)
})}
<
/CalendarRow
>
<
/Grid
>
<
CalendarRowDayWeek
week
=
{
week
}
hoursInDay
=
{
hoursInDay
}
/
>
<
/CalendarRow
>
<
/Grid
>
<
/Box
>
...
...
planner-front/src/helpers/CalendarHelpers.js
View file @
7e821cde
...
...
@@ -58,11 +58,18 @@ export const getWeekFromCurrentDate = (year, month, curDay) => {
export
const
getWeekInfoString
=
(
week
,
date
)
=>
{
if
(
week
[
0
]
>
week
[
6
])
{
if
(
date
.
month
===
11
)
{
return
getCurrentMonthString
(
date
.
month
)
+
' - '
+
getCurrentMonthString
(
0
)
+
' '
+
date
.
year
if
(
date
.
currentDay
<
week
[
0
])
{
if
(
date
.
month
===
0
)
{
return
getCurrentMonthString
(
11
)
+
' - '
+
getCurrentMonthString
(
0
)
+
' '
+
date
.
year
}
return
getCurrentMonthString
(
date
.
month
-
1
)
+
' - '
+
getCurrentMonthString
(
date
.
month
)
+
' '
+
date
.
year
}
else
{
if
(
date
.
month
===
11
)
{
return
getCurrentMonthString
(
date
.
month
)
+
' - '
+
getCurrentMonthString
(
0
)
+
' '
+
date
.
year
}
return
getCurrentMonthString
(
date
.
month
)
+
' - '
+
getCurrentMonthString
(
date
.
month
+
1
)
+
' '
+
date
.
year
}
return
getCurrentMonthString
(
date
.
month
)
+
' - '
+
getCurrentMonthString
(
date
.
month
+
1
)
+
' '
+
date
.
year
}
else
{
return
getCurrentMonthString
(
date
.
month
)
+
' '
+
date
.
year
}
}
}
\ No newline at end of file
planner-front/src/tests/MonthCalendar.test.js
View file @
7e821cde
import
{
getDaysInMonth
,
getCurrentMonthString
,
dateToISOLikeButLocal
}
from
'../helpers/CalendarHelpers'
;
import
{
getAvailableTasks
,
getSortedTasks
}
from
'../components/MonthCalendarBody/CalendarRowDay/Helpers'
import
{
getAvailableTasks
,
getSortedTasks
}
from
'../components/MonthCalendar
/MonthCalendar
Body/CalendarRowDay/Helpers'
describe
(
'Получение дней в феврале 2022'
,
()
=>
{
test
(
'Всего дней'
,
()
=>
{
...
...
@@ -33,16 +33,16 @@ describe('Получение дней в ноябре 2022', () => {
describe
(
'Получение месяца'
,
()
=>
{
test
(
'Первый месяц'
,
()
=>
{
expect
(
getCurrentMonthString
(
{
month
:
0
}
)).
toBe
(
"Январь"
);
expect
(
getCurrentMonthString
(
0
)).
toBe
(
"Январь"
);
})
test
(
'Последний месяц'
,
()
=>
{
expect
(
getCurrentMonthString
(
{
month
:
11
}
)).
toBe
(
"Декабрь"
);
expect
(
getCurrentMonthString
(
11
)).
toBe
(
"Декабрь"
);
})
test
(
'Неккоретное значение выше нормы'
,
()
=>
{
expect
(
getCurrentMonthString
(
{
month
:
12
}
)).
toBe
(
null
);
expect
(
getCurrentMonthString
(
12
)).
toBe
(
null
);
})
test
(
'Неккоретное значение ниже нормы'
,
()
=>
{
expect
(
getCurrentMonthString
(
{
month
:
-
1
}
)).
toBe
(
null
);
expect
(
getCurrentMonthString
(
-
1
)).
toBe
(
null
);
})
})
...
...
@@ -65,4 +65,61 @@ describe('Получение допустимых задач для клетки
test
(
'Не все прошедшие проверку задачи'
,
()
=>
{
expect
(
getAvailableTasks
([{
infoForCell
:
{
startYear
:
2021
,
startMonth
:
11
,
startDay
:
12
}},
{
infoForCell
:
{
startYear
:
2022
,
startMonth
:
12
,
startDay
:
12
}}],
2022
,
11
,
12
).
length
).
toBe
(
1
);
})
})
describe
(
'Получение сортированных задач'
,
()
=>
{
test
(
'Сортировка прошла успешно Вариант№1'
,
()
=>
{
const
tasks
=
[
{
infoForCell
:
{
startHour
:
12
,
endHour
:
14
}
},
{
infoForCell
:
{
startHour
:
13
,
endHour
:
14
}
}]
expect
(
getSortedTasks
(
tasks
)).
toEqual
(
tasks
)
})
test
(
'Сортировка прошла успешно Вариант№2'
,
()
=>
{
const
tasks
=
[
{
infoForCell
:
{
startHour
:
12
,
endHour
:
14
}
},
{
infoForCell
:
{
startHour
:
10
,
endHour
:
14
}
}]
expect
(
getSortedTasks
(
tasks
)).
toEqual
(
tasks
.
reverse
())
})
test
(
'Сортировка прошла успешно Вариант№3'
,
()
=>
{
const
tasks
=
[
{
infoForCell
:
{
startHour
:
12
,
endHour
:
14
}
},
{
infoForCell
:
{
startHour
:
10
,
endHour
:
14
}
},
{
infoForCell
:
{
startHour
:
11
,
endHour
:
12
}
}]
expect
(
getSortedTasks
(
tasks
)).
toEqual
([
tasks
[
1
],
tasks
[
0
],
tasks
[
2
]])
})
})
\ No newline at end of file
planner-front/src/tests/WeekCalendar.test.js
0 → 100644
View file @
7e821cde
import
{
getCurrentWeekDayString
}
from
'../components/WeekCalendar/WeekCalendarBody/Helpers'
;
import
{
getWeekFromCurrentDate
,
getWeekInfoString
}
from
'../helpers/CalendarHelpers'
;
describe
(
'Получение недели в 7дневном формате'
,
()
=>
{
test
(
'Получение недели 10 декабря 2022'
,
()
=>
{
expect
(
getWeekFromCurrentDate
(
2022
,
11
,
10
)).
toEqual
([
5
,
6
,
7
,
8
,
9
,
10
,
11
]);
})
test
(
'Получение недели 1 декабря 2022'
,
()
=>
{
expect
(
getWeekFromCurrentDate
(
2022
,
11
,
1
)).
toEqual
([
28
,
29
,
30
,
1
,
2
,
3
,
4
]);
})
test
(
'Получение недели 1 октября 2023'
,
()
=>
{
expect
(
getWeekFromCurrentDate
(
2023
,
9
,
1
)).
toEqual
([
25
,
26
,
27
,
28
,
29
,
30
,
1
]);
})
})
describe
(
'Получение информации о неделе'
,
()
=>
{
test
(
'Получение информации о недели 10 декабря 2022'
,
()
=>
{
const
date
=
{
month
:
11
,
year
:
2022
,
currentDay
:
10
}
const
week
=
[
5
,
6
,
7
,
8
,
9
,
10
,
11
]
expect
(
getWeekInfoString
(
week
,
date
)).
toBe
(
"Декабрь 2022"
);
})
test
(
'Получение информации о недели 1 декабря 2022'
,
()
=>
{
const
date
=
{
month
:
11
,
year
:
2022
,
currentDay
:
1
}
const
week
=
[
28
,
29
,
30
,
1
,
2
,
3
,
4
]
expect
(
getWeekInfoString
(
week
,
date
)).
toBe
(
"Ноябрь - Декабрь 2022"
);
})
test
(
'Получение информации о недели 30 ноября 2022'
,
()
=>
{
const
date
=
{
month
:
10
,
year
:
2022
,
currentDay
:
30
}
const
week
=
[
28
,
29
,
30
,
1
,
2
,
3
,
4
]
expect
(
getWeekInfoString
(
week
,
date
)).
toBe
(
"Ноябрь - Декабрь 2022"
);
})
test
(
'Получение информации о недели 31 декабря 2022'
,
()
=>
{
const
date
=
{
month
:
11
,
year
:
2022
,
currentDay
:
31
}
const
week
=
[
26
,
27
,
28
,
29
,
30
,
31
,
1
]
expect
(
getWeekInfoString
(
week
,
date
)).
toBe
(
"Декабрь - Январь 2022"
);
})
test
(
'Получение информации о недели 1 января 2023'
,
()
=>
{
const
date
=
{
month
:
0
,
year
:
2023
,
currentDay
:
1
}
const
week
=
[
26
,
27
,
28
,
29
,
30
,
31
,
1
]
expect
(
getWeekInfoString
(
week
,
date
)).
toBe
(
"Декабрь - Январь 2023"
);
})
test
(
'Получение информации о недели 31 января 2023'
,
()
=>
{
const
date
=
{
month
:
0
,
year
:
2023
,
currentDay
:
31
}
const
week
=
[
30
,
31
,
1
,
2
,
3
,
4
,
5
]
expect
(
getWeekInfoString
(
week
,
date
)).
toBe
(
"Январь - Февраль 2023"
);
})
})
describe
(
'Получение дня недели'
,
()
=>
{
test
(
'Понедельник'
,
()
=>
{
expect
(
getCurrentWeekDayString
(
0
)).
toBe
(
'ПН'
);
})
test
(
'Четверг'
,
()
=>
{
expect
(
getCurrentWeekDayString
(
3
)).
toBe
(
'ЧТ'
);
})
test
(
'Воскресенье'
,
()
=>
{
expect
(
getCurrentWeekDayString
(
6
)).
toBe
(
'ВС'
);
})
test
(
'Неккоретное значение выше нормы'
,
()
=>
{
expect
(
getCurrentWeekDayString
(
7
)).
toBe
(
null
);
})
test
(
'Неккоретное значение ниже нормы'
,
()
=>
{
expect
(
getCurrentWeekDayString
(
-
1
)).
toBe
(
null
);
})
})
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