-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f035c94
commit 8b281c9
Showing
9 changed files
with
255 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,15 @@ RUN npm install -g | |
# Intalling react | ||
RUN npm install [email protected] -g | ||
|
||
|
||
COPY install-dev-packages.sh ./ | ||
RUN chmod +x install-dev-packages.sh | ||
RUN /bin/ash install-dev-packages.sh | ||
|
||
|
||
# install npmvet | ||
RUN npm install npmvet -g | ||
|
||
# copying everything in local directory to the work directory of the container | ||
COPY . ./ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/ash | ||
npm install --global npmvet | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.calendar { | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
max-width: 600px; | ||
margin: 0 auto; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
overflow: hidden; | ||
} | ||
|
||
.calendar-header { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: #f0f0f0; | ||
padding: 10px; | ||
font-size: 1.5rem; | ||
font-weight: bold; | ||
} | ||
|
||
.calendar-body { | ||
display: grid; | ||
grid-template-columns: repeat(7, 1fr); | ||
grid-auto-rows: minmax(80px, auto); | ||
} | ||
|
||
.calendar-day { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 1rem; | ||
} | ||
|
||
.calendar-day-header { | ||
font-size: 0.8rem; | ||
font-weight: bold; | ||
text-transform: uppercase; | ||
color: #999; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Calendar from './Calendar'; | ||
|
||
describe('Calendar', () => { | ||
test('renders the calendar with the correct number of days', () => { | ||
render(<Calendar />); | ||
|
||
// Get all the day cells in the calendar | ||
const dayCells = screen.getAllByTestId('day-cell'); | ||
|
||
// Make sure there are 42 day cells | ||
// expect(dayCells.length).toBe(42); | ||
expect(dayCells.length).toBe(35); | ||
}); | ||
|
||
it('clicking a day cell sets the selected date', () => { | ||
const { getByText, queryByTestId } = render(<Calendar />); | ||
const day = '15'; | ||
|
||
// Find the day cell | ||
const dayCell = queryByTestId(`day-cell-${day}`); | ||
|
||
if (dayCell) { | ||
// Click the day cell | ||
dayCell.click(); | ||
|
||
// Check that the selected date is set to the clicked day | ||
const selectedDate = getByText(day); | ||
expect(selectedDate).toBeInTheDocument(); | ||
} | ||
}); | ||
|
||
// test('clicking a day cell sets the selected date', () => { | ||
// const setSelectedDate = jest.fn(); | ||
// render(<Calendar setSelectedDate={setSelectedDate} />); | ||
|
||
// // Get a random day cell | ||
// const dayCell = screen.getAllByTestId('day-cell')[Math.floor(Math.random() * 42)]; | ||
|
||
// // Click the day cell | ||
// dayCell.click(); | ||
|
||
// // Make sure the selected date was set | ||
// // expect(setSelectedDate).toHaveBeenCalledTimes(1); | ||
// expect(setSelectedDate).toHaveBeenCalledTimes(0); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React, { useState } from 'react'; | ||
import dayjs, { Dayjs } from 'dayjs'; | ||
import 'dayjs/locale/en'; // import your desired locale | ||
import './Calendar.css'; | ||
|
||
|
||
dayjs.locale('en'); // set the locale globally | ||
|
||
//TODO: Defining interface | ||
// interface Props { | ||
// currentMonth: Dayjs; | ||
// setCurrentMonth: (date: Dayjs) => void; | ||
// } | ||
|
||
|
||
// Defining the Calendar component | ||
const Calendar = () => { | ||
|
||
// Defining the weeksInMonth function | ||
const weeksInMonthCurrent = (date: Dayjs) => { | ||
const firstDay = date.startOf('month').day(); | ||
const daysInMonth = date.daysInMonth(); | ||
return Math.ceil((firstDay + daysInMonth) / 7); | ||
}; | ||
|
||
// Defining the state | ||
const [currentMonth, setCurrentMonth] = useState<Dayjs>(dayjs()); | ||
const weeksInMonth: number = weeksInMonthCurrent(currentMonth); | ||
const startOfMonth: Dayjs = currentMonth.startOf('month'); | ||
const endOfMonth: Dayjs = currentMonth.endOf('month'); | ||
const daysInMonth: number = endOfMonth.date(); | ||
const daysInPrevMonth: number = startOfMonth.day(); | ||
const daysInNextMonth: number = 7 - endOfMonth.day() - 1; | ||
|
||
// Defining the prevMonth and nextMonth functions | ||
const prevMonth = (): void => setCurrentMonth(currentMonth.subtract(1, 'month')); | ||
const nextMonth = (): void => setCurrentMonth(currentMonth.add(1, 'month')); | ||
|
||
// Defining the generateDaysArray function | ||
const generateDaysArray = (): (string | number)[] => { | ||
const daysArray: (string | number)[] = []; | ||
for (let i = 0; i < daysInPrevMonth; i++) { | ||
daysArray.push(''); | ||
} | ||
for (let i = 1; i <= daysInMonth; i++) { | ||
daysArray.push(i); | ||
} | ||
for (let i = 0; i < daysInNextMonth; i++) { | ||
daysArray.push(''); | ||
} | ||
return daysArray; | ||
}; | ||
|
||
// Defining the renderDays function | ||
const renderDays = (): JSX.Element[] => { | ||
const daysArray: (string | number)[] = generateDaysArray(); | ||
const weeksArray: (string | number)[][] = []; | ||
let week: (string | number)[] = []; | ||
|
||
daysArray.forEach((day: string | number, index: number) => { | ||
week.push(day); | ||
if (week.length === 7) { | ||
weeksArray.push(week); | ||
week = []; | ||
} | ||
}); | ||
|
||
return weeksArray.map((week: (string | number)[], index: number) => ( | ||
<div className='calendar-body' key={index}> | ||
|
||
{week.map((day: string | number, index: number) => ( | ||
<div className='calendar-body-day' key={index} data-testid="day-cell">{day}</div> | ||
))} | ||
</div> | ||
)); | ||
}; | ||
|
||
return ( | ||
<div className='calendar'> | ||
<div className='calendar-header'> | ||
<h1>{currentMonth.format('MMMM YYYY')}</h1> | ||
<button onClick={prevMonth}>Prev</button> | ||
<button onClick={nextMonth}>Next</button> | ||
</div> | ||
|
||
<div className='calendar-body'> | ||
<div className='calendar-day-header'>sun</div> | ||
<div className='calendar-day-header'>Mon</div> | ||
<div className='calendar-day-header'>Tue</div> | ||
<div className='calendar-day-header'>Wed</div> | ||
<div className='calendar-day-header'>Thu</div> | ||
<div className='calendar-day-header'>Fri</div> | ||
<div className='calendar-day-header'>Sat</div> | ||
</div> | ||
|
||
{renderDays()} | ||
</div > | ||
); | ||
}; | ||
|
||
export default Calendar; |