From 8a49d160e2d066be97c9370ffa7e91cd7a689e4f Mon Sep 17 00:00:00 2001 From: "Bang, Jaehun" Date: Wed, 3 Apr 2024 18:21:46 +0900 Subject: [PATCH] chore: change 'weekends' and 'weekDays' to 'weekdays' (#321) --- examples/react/src/pages/calendar/index.tsx | 4 ++-- examples/react/src/pages/index.tsx | 4 ++-- packages/calendar/.e2e/basic.e2e.ts | 7 ++++--- packages/calendar/src/core/createCalendarInfo.ts | 4 ++-- packages/calendar/src/stories/Calendar.tsx | 4 ++-- packages/calendar/src/useCalendar.test.ts | 14 +++++++------- packages/calendar/src/useCalendar.ts | 8 ++++---- website/docs/calendar/example.md | 2 +- website/docs/calendar/get-started.md | 2 +- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/react/src/pages/calendar/index.tsx b/examples/react/src/pages/calendar/index.tsx index 638a20de..96468e34 100644 --- a/examples/react/src/pages/calendar/index.tsx +++ b/examples/react/src/pages/calendar/index.tsx @@ -105,9 +105,9 @@ export default function CalendarExample() { - {headers.weekDays.map(({ key, value }) => { + {headers.weekdays.map(({ key, value }) => { return ( - + {format(value, "E", { locale })} ); diff --git a/examples/react/src/pages/index.tsx b/examples/react/src/pages/index.tsx index d1344093..cec08096 100644 --- a/examples/react/src/pages/index.tsx +++ b/examples/react/src/pages/index.tsx @@ -103,9 +103,9 @@ export default function BasicExample() { - {headers.weekDays.map(({ key, value }) => { + {headers.weekdays.map(({ key, value }) => { return ( - + {format(value, "E", { locale })} ); diff --git a/packages/calendar/.e2e/basic.e2e.ts b/packages/calendar/.e2e/basic.e2e.ts index e3698cdd..31738dc1 100644 --- a/packages/calendar/.e2e/basic.e2e.ts +++ b/packages/calendar/.e2e/basic.e2e.ts @@ -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', } @@ -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() diff --git a/packages/calendar/src/core/createCalendarInfo.ts b/packages/calendar/src/core/createCalendarInfo.ts index d184bc0a..bdb1cf47 100644 --- a/packages/calendar/src/core/createCalendarInfo.ts +++ b/packages/calendar/src/core/createCalendarInfo.ts @@ -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), })); @@ -25,7 +25,7 @@ export default function createCalendarInfo(cursorDate: Date, { weekStartsOn }: { weekStartsOn, startWeekdayInMonth, weeksInMonth, - weekDays, + weekdays, today: { weekIndex: getCurrentWeekIndex(day, startWeekdayInMonth), dateIndex: getDay(cursorDate), diff --git a/packages/calendar/src/stories/Calendar.tsx b/packages/calendar/src/stories/Calendar.tsx index aab5c92d..35a33363 100644 --- a/packages/calendar/src/stories/Calendar.tsx +++ b/packages/calendar/src/stories/Calendar.tsx @@ -36,9 +36,9 @@ export function Calendar() { - {headers.weekDays.map(({ key, value }) => { + {headers.weekdays.map(({ key, value }) => { return ( - + {format(value, "E")} ); diff --git a/packages/calendar/src/useCalendar.test.ts b/packages/calendar/src/useCalendar.test.ts index 2c8edb3d..4908bbbc 100644 --- a/packages/calendar/src/useCalendar.test.ts +++ b/packages/calendar/src/useCalendar.test.ts @@ -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", () => { @@ -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; @@ -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([ @@ -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; @@ -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([ diff --git a/packages/calendar/src/useCalendar.ts b/packages/calendar/src/useCalendar.ts index 75747896..e757ed40 100644 --- a/packages/calendar/src/useCalendar.ts +++ b/packages/calendar/src/useCalendar.ts @@ -30,7 +30,7 @@ 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) => { @@ -38,15 +38,15 @@ export function useCalendar({ 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( diff --git a/website/docs/calendar/example.md b/website/docs/calendar/example.md index 4ba0942b..e1b28a79 100644 --- a/website/docs/calendar/example.md +++ b/website/docs/calendar/example.md @@ -15,7 +15,7 @@ export default function Calendar() { - {headers.weekDays.map(({ key, value }) => { + {headers.weekdays.map(({ key, value }) => { return })} diff --git a/website/docs/calendar/get-started.md b/website/docs/calendar/get-started.md index ba916295..c9ed7d75 100644 --- a/website/docs/calendar/get-started.md +++ b/website/docs/calendar/get-started.md @@ -45,7 +45,7 @@ export default function Calendar() {
{format(value, 'E', { locale })}
- {headers.weekDays.map(({ key, value }) => { + {headers.weekdays.map(({ key, value }) => { return })}
{format(value, 'E', { locale })}