Skip to content

Commit

Permalink
chore: change 'weekends' and 'weekDays' to 'weekdays' (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehunn authored Apr 3, 2024
1 parent 2b1ef7b commit 8a49d16
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/react/src/pages/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export default function CalendarExample() {
</TableCaption>
<Thead>
<Tr>
{headers.weekDays.map(({ key, value }) => {
{headers.weekdays.map(({ key, value }) => {
return (
<Th key={key} data-testid="calendar-weekends">
<Th key={key} data-testid="calendar-weekdays">
{format(value, "E", { locale })}
</Th>
);
Expand Down
4 changes: 2 additions & 2 deletions examples/react/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ export default function BasicExample() {
</TableCaption>
<Thead>
<Tr>
{headers.weekDays.map(({ key, value }) => {
{headers.weekdays.map(({ key, value }) => {
return (
<Th key={key} data-testid="calendar-weekends">
<Th key={key} data-testid="calendar-weekdays">
{format(value, "E", { locale })}
</Th>
);
Expand Down
7 changes: 4 additions & 3 deletions packages/calendar/.e2e/basic.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const BASIC_EXAMPLES_URL =

const SELECTOR = {
CURSOR_DATE: 'data-testid=cursor-date',
WEEKDAYS: 'data-testid=calendar-weekdays',
WEEKS: 'data-testid=calendar-weeks',
CELL_TODAY: 'data-testid=calendar-cell--today',
}
Expand All @@ -35,9 +36,9 @@ test('render calendar successfully', async ({ page }) => {
const pageTitle = page.locator(SELECTOR.CURSOR_DATE)
await expect(pageTitle).toHaveText(dateFormat(baseDate))

// render weekends in calendar
const weekendsCount = await page.locator('data-testid=calendar-weekends').count()
expect(weekendsCount).toBe(7)
// render weekdays in calendar
const weekdaysCount = await page.locator(SELECTOR.WEEKDAYS).count()
expect(weekdaysCount).toBe(7)

// render calendar cells
const weeksCount = await page.locator(SELECTOR.WEEKS).count()
Expand Down
4 changes: 2 additions & 2 deletions packages/calendar/src/core/createCalendarInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function createCalendarInfo(cursorDate: Date, { weekStartsOn }: {
const { year, month, day } = parseDate(cursorDate);
const startWeekdayInMonth = getStartWeekdayInMonth(cursorDate, weekStartsOn);
const weeksInMonth = getWeeksInMonth(cursorDate, startWeekdayInMonth);
const weekDays = arrayOf(7).map((index) => ({
const weekdays = arrayOf(7).map((index) => ({
value: setDay(cursorDate, index + weekStartsOn),
}));

Expand All @@ -25,7 +25,7 @@ export default function createCalendarInfo(cursorDate: Date, { weekStartsOn }: {
weekStartsOn,
startWeekdayInMonth,
weeksInMonth,
weekDays,
weekdays,
today: {
weekIndex: getCurrentWeekIndex(day, startWeekdayInMonth),
dateIndex: getDay(cursorDate),
Expand Down
4 changes: 2 additions & 2 deletions packages/calendar/src/stories/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export function Calendar() {
</caption>
<thead>
<tr>
{headers.weekDays.map(({ key, value }) => {
{headers.weekdays.map(({ key, value }) => {
return (
<th key={key} data-testid="calendar-weekends">
<th key={key} data-testid="calendar-weekdays">
{format(value, "E")}
</th>
);
Expand Down
14 changes: 7 additions & 7 deletions packages/calendar/src/useCalendar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe("useCalendar hooks test", () => {
}),
);
// Then
const onlyDates = result.current.headers.weekDays.map(({ value }) => ({
const onlyDates = result.current.headers.weekdays.map(({ value }) => ({
value,
}));
expect(onlyDates).toEqual(DecemberFirstWeekData.value[0].value);
expect(result.current.headers.weekDays[0].key).toBeDefined();
expect(result.current.headers.weekdays[0].key).toBeDefined();
});

it("return weekdays array when month viewType", () => {
Expand All @@ -43,13 +43,13 @@ describe("useCalendar hooks test", () => {
}),
);
// Then
const onlyDates = result.current.headers.weekDays.map(({ value }) => ({
const onlyDates = result.current.headers.weekdays.map(({ value }) => ({
value,
}));
expect(onlyDates).toEqual([{ value: defaultDate }]);
});

it("return weekDays when set WeekDayType: 0", () => {
it("return weekdays when set WeekDayType: 0", () => {
// Given
const defaultDate = new Date(2021, 8, 30);
const defaultWeekStart = 0;
Expand All @@ -61,7 +61,7 @@ describe("useCalendar hooks test", () => {
}),
);
// Then
const onlyDates = result.current.headers.weekDays.map(({ value }) => ({
const onlyDates = result.current.headers.weekdays.map(({ value }) => ({
value,
}));
expect(onlyDates).toEqual([
Expand All @@ -74,7 +74,7 @@ describe("useCalendar hooks test", () => {
{ value: new Date(2021, 9, 2) },
]);
});
it("return weekDays when set WeekDayType: 1", () => {
it("return weekdays when set WeekDayType: 1", () => {
// Given
const defaultDate = new Date(2021, 8, 30);
const defaultWeekStart = 1;
Expand All @@ -86,7 +86,7 @@ describe("useCalendar hooks test", () => {
}),
);
// Then
const onlyDates = result.current.headers.weekDays.map(({ value }) => ({
const onlyDates = result.current.headers.weekdays.map(({ value }) => ({
value,
}));
expect(onlyDates).toEqual([
Expand Down
8 changes: 4 additions & 4 deletions packages/calendar/src/useCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ export function useCalendar({
const [viewType, setViewType] = useState(defaultViewType);

const calendar = createCalendarInfo(cursorDate, { weekStartsOn });
const { weekDays, weeksInMonth, today, getDateCellByIndex } = calendar;
const { weekdays, weeksInMonth, today, getDateCellByIndex } = calendar;

const getHeaders = useCallback(
(viewType: CalendarViewType) => {
switch (viewType) {
case CalendarViewType.Month:
case CalendarViewType.Week:
return {
weekDays: withKey(weekDays, "weekdays"),
weekdays: withKey(weekdays, "weekdays"),
};
default:
return {
weekDays: withKey([{ value: cursorDate }], "weekdays"),
weekdays: withKey([{ value: cursorDate }], "weekdays"),
};
}
},
[cursorDate, weekDays],
[cursorDate, weekdays],
);

const createMatrix = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion website/docs/calendar/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Calendar() {
<Table>
<Thead>
<Tr>
{headers.weekDays.map(({ key, value }) => {
{headers.weekdays.map(({ key, value }) => {
return <Th key={key}>{format(value, 'E', { locale })}</Th>
})}
</Tr>
Expand Down
2 changes: 1 addition & 1 deletion website/docs/calendar/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function Calendar() {
<Table>
<Thead>
<Tr>
{headers.weekDays.map(({ key, value }) => {
{headers.weekdays.map(({ key, value }) => {
return <Th key={key}>{format(value, 'E', { locale })}</Th>
})}
</Tr>
Expand Down

0 comments on commit 8a49d16

Please sign in to comment.