cronofy-elements
Advanced tools
Comparing version 1.40.1 to 1.40.2
{ | ||
"name": "cronofy-elements", | ||
"version": "1.40.1", | ||
"version": "1.40.2", | ||
"description": "Fast track scheduling with Cronofy's embeddable UI Elements", | ||
@@ -5,0 +5,0 @@ "main": "build/npm/CronofyElements.js", |
@@ -17,2 +17,3 @@ import React from "react"; | ||
import { useTheme } from "./contexts/theme-context"; | ||
import { useTz } from "./contexts/tz-context"; | ||
@@ -22,2 +23,3 @@ const Calendar = () => { | ||
const theme = useTheme(); | ||
const [tz] = useTz(); | ||
@@ -32,4 +34,3 @@ const weekdays = getWeekDays(status.startDay); | ||
const handleGridNavigation = (date, e) => { | ||
const currentMonth = status.months.find(month => month.current).month; | ||
const monthlySlots = status.monthlySlots.find(month => month.month === currentMonth); | ||
const monthlySlots = status.monthlyView; | ||
const availableDaysInGrid = getAvailableDaysInMonthDisplay(monthlySlots.days); | ||
@@ -76,5 +77,6 @@ if (!date) { | ||
dispatchStatus({ | ||
type: "SET_FOCUS_FOR_NEW_MONTH", | ||
type: "SELECT_MONTH", | ||
month: result.month, | ||
focusedDay: result.date, | ||
month: result.month, | ||
tzid: tz.selectedTzid.tzid, | ||
}); | ||
@@ -87,4 +89,4 @@ } | ||
const currentMonth = status.months.find(month => month.current).month; | ||
const monthlySlots = status.monthlySlots.find(month => month.month === currentMonth); | ||
const monthlySlots = status.monthlyView; | ||
const currentMonth = monthlySlots.month; | ||
@@ -91,0 +93,0 @@ const grid = monthlySlots.days.map((row, i) => ( |
@@ -8,2 +8,3 @@ import React, { useEffect, useState } from "react"; | ||
import { useTheme } from "./contexts/theme-context"; | ||
import { useTz } from "./contexts/tz-context"; | ||
@@ -14,2 +15,3 @@ const CalendarHeader = () => { | ||
const theme = useTheme(); | ||
const [tz] = useTz(); | ||
@@ -19,3 +21,7 @@ const [monthState, setMonthState] = useState(() => calculateMonthNav(status.months)); | ||
const handleMonthNav = target => { | ||
dispatchStatus({ type: "SELECT_MONTH", month: target }); | ||
dispatchStatus({ | ||
type: "SELECT_MONTH", | ||
month: target, | ||
tzid: tz.selectedTzid.tzid, | ||
}); | ||
}; | ||
@@ -22,0 +28,0 @@ |
@@ -36,3 +36,3 @@ import React from "react"; | ||
{i18n.customFormatedTimeZone( | ||
moment(status.selected.start, "YYYY-MM-DD"), | ||
moment(status.selected.start, "YYYY-MM-DDTHH:mm:00Z"), | ||
tz.selectedTzid.tzid, | ||
@@ -39,0 +39,0 @@ "dddd, MMMM Do YYYY" |
@@ -5,3 +5,3 @@ import React, { createContext, useContext, useReducer } from "react"; | ||
const statusContext = createContext(); | ||
const StatusContext = createContext(); | ||
@@ -11,7 +11,7 @@ export const StatusProvider = ({ children, options }) => { | ||
return ( | ||
<statusContext.Provider value={[status, dispatchStatus]}>{children}</statusContext.Provider> | ||
<StatusContext.Provider value={[status, dispatchStatus]}>{children}</StatusContext.Provider> | ||
); | ||
}; | ||
export const useStatus = () => { | ||
const context = useContext(statusContext); | ||
const context = useContext(StatusContext); | ||
if (context === undefined) { | ||
@@ -18,0 +18,0 @@ throw new Error("useStatus must be used within a StatusProvider"); |
@@ -33,2 +33,3 @@ import { | ||
} | ||
case "CONFIRM_SELECTION": { | ||
@@ -38,2 +39,3 @@ sendSlotNotification(action.tzid); | ||
} | ||
case "ERROR_GETTING_SLOTS": { | ||
@@ -49,76 +51,69 @@ const notification = { | ||
} | ||
case "NO_SLOTS_FOUND": { | ||
return { ...state, columnView: "no-slots" }; | ||
} | ||
case "RECALCULATE_MONTH_SLOTS": { | ||
const monthlySlots = state.months.map(month => ({ | ||
month: month.month, | ||
case "RECALCULATE_MONTH_VIEW": { | ||
const monthlyView = { | ||
month: state.monthlyView.month, | ||
days: parseTimeSlots({ | ||
slots: state.slots, | ||
month: month.month, | ||
month: state.monthlyView.month, | ||
tzid: action.tzid, | ||
startDay: state.startDay, | ||
}), | ||
})); | ||
return { ...state, monthlySlots }; | ||
} | ||
case "SET_INITIAL_SLOTS": { | ||
const hasNewSlots = Object.keys(action.slots).length >= 1; | ||
const slotsObject = hasNewSlots | ||
? addSlotsToObject(state.slots, action.slots) | ||
: state.slots; | ||
const hasAnySlots = Object.keys(slotsObject).length >= 1; | ||
const selectedDay = hasAnySlots | ||
? getFirstAvailableDay(slotsObject, action.tzid) | ||
: false; | ||
const availableDays = hasAnySlots ? getAvailableDays(slotsObject, state.tzid) : false; | ||
}; | ||
return { | ||
...state, | ||
selectedDay, | ||
focusedDay: selectedDay, | ||
slots: slotsObject, | ||
availableDays: availableDays, | ||
slotFetchCount: state.slotFetchCount + 1, | ||
monthlyView, | ||
}; | ||
} | ||
case "SET_DEFAULT_SLOTS": | ||
case "SET_ADDITIONAL_SLOTS": { | ||
const hasNewSlots = Object.keys(action.slots).length >= 1; | ||
const slotsObject = hasNewSlots | ||
? addSlotsToObject(state.slots, action.slots) | ||
: state.slots; | ||
const hasAnySlots = Object.keys(slotsObject).length >= 1; | ||
const selectedDay = | ||
hasAnySlots && !state.selectedDay | ||
? getFirstAvailableDay(slotsObject, action.tzid) | ||
: state.selectedDay; | ||
case "SET_SLOTS": { | ||
if (!action.slots.length > 0) { | ||
return state; | ||
} | ||
const slotsObject = addSlotsToObject(state.slots, action.slots); | ||
let daySlots = state.daySlots; | ||
let columnView = state.columnView; | ||
let focusedDay = state.focusedDay; | ||
let selectedDay = state.selectedDay; | ||
let availableDays = getAvailableDays(addSlotsToObject({}, action.slots), action.tzid); | ||
const availableDaysSet = new Set([...state.availableDays, ...availableDays]); | ||
availableDays = [...availableDaysSet].sort(); | ||
if (!state.selectedDay) { | ||
columnView = "slots"; | ||
focusedDay = availableDays[0]; | ||
selectedDay = availableDays[0]; | ||
daySlots = getSlotsByDay(slotsObject, selectedDay, action.tzid); | ||
} | ||
return { | ||
...state, | ||
daySlots, | ||
columnView, | ||
focusedDay, | ||
selectedDay, | ||
availableDays, | ||
slots: slotsObject, | ||
selectedDay, | ||
focusedDay: selectedDay, | ||
slotFetchCount: state.slotFetchCount + 1, | ||
slotInjectionPoint: getLocalDayFromUtc(action.slots[0].start, action.tzid), | ||
}; | ||
} | ||
case "SET_FOCUS": { | ||
return { ...state, focusedDay: action.focusedDay }; | ||
} | ||
case "SET_FOCUS_FOR_NEW_MONTH": { | ||
const months = state.months.map(month => ({ | ||
...month, | ||
current: month.month === action.month, | ||
})); | ||
return { ...state, months, focusedDay: action.focusedDay }; | ||
} | ||
case "SELECT_DAY_INITIAL": | ||
const initialDaySlots = getSlotsByDay(state.slots, action.day, action.tzid); | ||
return { | ||
...state, | ||
selectedDay: action.day, | ||
focusedDay: action.day, | ||
columnView: "slots", | ||
daySlots: initialDaySlots, | ||
populated: true, | ||
focusedDay: action.focusedDay, | ||
}; | ||
case "SELECT_DAY": | ||
} | ||
case "SELECT_DAY": { | ||
const daySlots = getSlotsByDay(state.slots, action.day, action.tzid); | ||
@@ -134,3 +129,4 @@ return { | ||
}; | ||
case "SELECT_MONTH": | ||
} | ||
case "SELECT_MONTH": { | ||
const months = state.months.map(month => ({ | ||
@@ -140,7 +136,23 @@ ...month, | ||
})); | ||
let focusedDay = action.focusedDay ?? false; | ||
const monthlyView = { | ||
month: action.month, | ||
days: parseTimeSlots({ | ||
tzid: action.tzid, | ||
slots: state.slots, | ||
month: action.month, | ||
startDay: state.startDay, | ||
}), | ||
}; | ||
return { | ||
...state, | ||
months, | ||
focusedDay: false, | ||
focusedDay, | ||
monthlyView, | ||
}; | ||
} | ||
case "SELECT_SLOT": { | ||
@@ -159,14 +171,16 @@ state = { | ||
} | ||
case "SELECT_TZID": { | ||
const availableDays = getAvailableDays(state.slots, action.tzid); | ||
const daySlots = getSlotsByDay(state.slots, state.selectedDay, action.tzid); | ||
const monthlySlots = state.months.map(month => ({ | ||
month: month.month, | ||
const monthlyView = { | ||
month: state.monthlyView.month, | ||
days: parseTimeSlots({ | ||
slots: state.slots, | ||
month: month.month, | ||
month: state.monthlyView.month, | ||
tzid: action.tzid, | ||
startDay: state.startDay, | ||
}), | ||
})); | ||
}; | ||
@@ -177,3 +191,3 @@ state = { | ||
daySlots, | ||
monthlySlots, | ||
monthlyView, | ||
}; | ||
@@ -180,0 +194,0 @@ |
import React, { useState } from "react"; | ||
import moment from "moment-timezone"; | ||
@@ -26,11 +27,14 @@ import { | ||
const months = getMonthObjectsFromQuery(query, options.tzid); | ||
const monthlySlots = months.map(month => ({ | ||
month: month.month, | ||
const currentMonth = months.length ? months[0].month : moment().format("YYYY-MM"); | ||
const monthlyView = { | ||
month: currentMonth, | ||
days: parseTimeSlots({ | ||
slots: {}, | ||
month: month.month, | ||
month: currentMonth, | ||
tzid: options.tzid, | ||
startDay: options.config.startDay, | ||
}), | ||
})); | ||
}; | ||
return { | ||
@@ -51,11 +55,10 @@ auth: { | ||
months, | ||
monthlySlots, | ||
monthlyView, | ||
selected: false, | ||
selectedDay: false, | ||
startDay: options.config.startDay, | ||
focusedDay: false, | ||
focusedSlot: false, | ||
availableDays: false, | ||
availableDays: [], | ||
slots: {}, | ||
slotFetchCount: 0, | ||
slotInjectionPoint: undefined, | ||
tzid: options.tzid, | ||
@@ -62,0 +65,0 @@ populated: false, |
@@ -22,2 +22,3 @@ import React, { useEffect, useRef } from "react"; | ||
const theme = useTheme(); | ||
const confirmButtonRef = useRef(); | ||
@@ -27,34 +28,27 @@ | ||
if (!status.query.query_periods) { | ||
dispatchStatus({ type: "SET_DEFAULT_SLOTS", slots: {} }); | ||
return; | ||
} | ||
const currentMonth = status.months.find(month => month.current); | ||
// Get all slots for current month | ||
getSlots({ | ||
query: currentMonth.query, | ||
auth: status.auth, | ||
tzid: status.tzid, | ||
}) | ||
.then(res => { | ||
const fetchMonthSlots = query => { | ||
return getSlots({ | ||
query, | ||
auth: status.auth, | ||
tzid: status.tzid, | ||
}).then(res => { | ||
dispatchStatus({ | ||
type: "SET_INITIAL_SLOTS", | ||
type: "SET_SLOTS", | ||
slots: res, | ||
tzid: tz.selectedTzid.tzid, | ||
}); | ||
}); | ||
}; | ||
const currentMonth = status.months.find(m => m.current); | ||
// Get slots for current month | ||
fetchMonthSlots(currentMonth.query) | ||
.then(() => { | ||
// Get slots for remianing months | ||
const remainingMonths = status.months.filter(month => !month.current); | ||
remainingMonths.forEach(month => { | ||
getSlots({ | ||
query: month.query, | ||
auth: status.auth, | ||
tzid: status.tzid, | ||
}).then(res => { | ||
dispatchStatus({ | ||
type: "SET_ADDITIONAL_SLOTS", | ||
month: month.month, | ||
slots: res, | ||
tzid: tz.selectedTzid.tzid, | ||
}); | ||
}); | ||
}); | ||
remainingMonths.forEach(month => fetchMonthSlots(month.query)); | ||
}) | ||
@@ -76,22 +70,39 @@ .catch(error => { | ||
// Set grid display if there are available slots | ||
if (slotsCount > 0) { | ||
dispatchStatus({ type: "RECALCULATE_MONTH_SLOTS", tzid: tz.selectedTzid.tzid }); | ||
// Set grid display if there are available slots within the current month | ||
if (slotsCount < 1) { | ||
return; | ||
} | ||
}, [status.slotFetchCount]); | ||
const weeksInMonth = status.monthlyView.days; | ||
const firstDay = moment(weeksInMonth[0][0].date, "YYYY-MM-DD"); | ||
const lastWeekInMonth = weeksInMonth[weeksInMonth.length - 1]; | ||
const lastDay = moment(lastWeekInMonth[lastWeekInMonth.length - 1].date, "YYYY-MM-DD"); | ||
const injectionPoint = status.slotInjectionPoint | ||
? moment(status.slotInjectionPoint, "YYYY-MM-DD") | ||
: undefined; | ||
if (injectionPoint && !injectionPoint.isBetween(firstDay, lastDay)) { | ||
return; | ||
} | ||
dispatchStatus({ | ||
type: "RECALCULATE_MONTH_VIEW", | ||
tzid: tz.selectedTzid.tzid, | ||
}); | ||
}, [status.slotFetchCount, status.slotInjectionPoint]); | ||
useEffect(() => { | ||
if (status.selectedDay) { | ||
if (!status.populated) { | ||
dispatchStatus({ | ||
type: "SELECT_DAY_INITIAL", | ||
day: status.selectedDay, | ||
}); | ||
} | ||
const currentMonthParts = status.months.find(month => month.current).month.split("-"); | ||
const selectedDayParts = status.selectedDay.split("-"); | ||
const currentMonthParts = status.monthlyView.month.split("-"); | ||
const inCurrentMonth = currentMonthParts[1] === selectedDayParts[1]; | ||
if (!inCurrentMonth) { | ||
const newMonth = moment(status.selectedDay, "YYYY-MM-DD").format("YYYY-MM"); | ||
dispatchStatus({ type: "SELECT_MONTH", month: newMonth }); | ||
dispatchStatus({ | ||
type: "SELECT_MONTH", | ||
month: newMonth, | ||
tzid: tz.selectedTzid.tzid, | ||
}); | ||
} | ||
@@ -98,0 +109,0 @@ } |
@@ -19,4 +19,10 @@ import { compose } from "./functional"; | ||
export const uniqueItems = array => array.filter((elem, pos, arr) => arr.indexOf(elem) == pos); | ||
export const uniqueItems = array => { | ||
if (!Array.isArray(array)) { | ||
return []; | ||
} | ||
return [...new Set(array)]; | ||
}; | ||
export const objectIsEmpty = obj => { | ||
@@ -23,0 +29,0 @@ for (let key in obj) { |
@@ -28,2 +28,4 @@ import { statusReducer } from "../../../src/js/components/DateTimePicker/contexts/status-reducer"; | ||
const testMonthlyView = testMonthlySlots[0]; | ||
const startingState = { | ||
@@ -36,3 +38,3 @@ columnView: "slots", | ||
months, | ||
monthlySlots: testMonthlySlots, | ||
monthlyView: testMonthlyView, | ||
selected: { | ||
@@ -47,5 +49,6 @@ start: "2021-09-29T08:00:00Z", | ||
focusedSlot: "2021-09-29T08:00:00Z", | ||
availableDays: false, | ||
availableDays: [], | ||
slots: testSlotsObject, | ||
slotFetchCount: 1, | ||
slotInjectionPoint: undefined, | ||
tzid: "Europe/London", | ||
@@ -151,226 +154,162 @@ populated: true, | ||
it("RECALCULATE_MONTH_SLOTS", async () => { | ||
it("RECALCULATE_MONTH_VIEW", async () => { | ||
const oldState = { ...startingState }; | ||
const result = statusReducer(oldState, { | ||
type: "RECALCULATE_MONTH_SLOTS", | ||
type: "RECALCULATE_MONTH_VIEW", | ||
tzid: "Europe/London", | ||
}); | ||
delete oldState.monthlySlots; | ||
delete oldState.monthlyView; | ||
const { monthlySlots, ...newState } = result; | ||
const { monthlyView, ...newState } = result; | ||
// These values have been updated | ||
expect(monthlySlots).toStrictEqual(testMonthlySlots); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
expect(oldState).toStrictEqual(newState); | ||
expect(monthlyView).toStrictEqual(testMonthlyView); | ||
}); | ||
it("SET_INITIAL_SLOTS", async () => { | ||
const oldState = { | ||
...startingState, | ||
selectedDay: false, | ||
focusedDay: false, | ||
slots: {}, | ||
availableDays: [], | ||
slotFetchCount: 0, | ||
}; | ||
const result = statusReducer(oldState, { | ||
type: "SET_INITIAL_SLOTS", | ||
slots: testSlotsArray, | ||
tzid: "Europe/London", | ||
}); | ||
describe("SET_SLOTS", () => { | ||
it("sets initial slots", () => { | ||
const oldState = { | ||
...startingState, | ||
selectedDay: false, | ||
focusedDay: false, | ||
slots: {}, | ||
availableDays: [], | ||
slotFetchCount: 0, | ||
slotInjectionPoint: undefined, | ||
}; | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.availableDays; | ||
delete oldState.slotFetchCount; | ||
const result = statusReducer(oldState, { | ||
type: "SET_SLOTS", | ||
slots: testSlotsArray, | ||
tzid: "Europe/London", | ||
}); | ||
const { | ||
selectedDay, | ||
focusedDay, | ||
slots, | ||
availableDays, | ||
slotFetchCount, | ||
...newState | ||
} = result; | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.availableDays; | ||
delete oldState.slotFetchCount; | ||
delete oldState.slotInjectionPoint; | ||
// These values have been updated | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSlotsObject); | ||
expect(availableDays).toStrictEqual([ | ||
"2021-09-29", | ||
"2021-09-30", | ||
"2021-10-01", | ||
"2021-10-04", | ||
]); | ||
expect(slotFetchCount).toBe(1); | ||
const { | ||
selectedDay, | ||
focusedDay, | ||
slots, | ||
availableDays, | ||
slotFetchCount, | ||
slotInjectionPoint, | ||
...newState | ||
} = result; | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
// These values have been updated | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSlotsObject); | ||
expect(availableDays).toStrictEqual([ | ||
"2021-09-29", | ||
"2021-09-30", | ||
"2021-10-01", | ||
"2021-10-04", | ||
]); | ||
expect(slotFetchCount).toBe(1); | ||
expect(slotInjectionPoint).toBe("2021-09-29"); | ||
it("SET_INITIAL_SLOTS when there is only one available slot", async () => { | ||
const oldState = { | ||
...startingState, | ||
selectedDay: false, | ||
focusedDay: false, | ||
slots: {}, | ||
availableDays: [], | ||
slotFetchCount: 0, | ||
}; | ||
const result = statusReducer(oldState, { | ||
type: "SET_INITIAL_SLOTS", | ||
slots: testSingleSlotsArray, | ||
tzid: "Europe/London", | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.availableDays; | ||
delete oldState.slotFetchCount; | ||
it("sets slots when there is only one available slot", () => { | ||
const oldState = { | ||
...startingState, | ||
selectedDay: false, | ||
focusedDay: false, | ||
slots: {}, | ||
availableDays: [], | ||
slotFetchCount: 0, | ||
slotInjectionPoint: undefined, | ||
}; | ||
const { | ||
selectedDay, | ||
focusedDay, | ||
slots, | ||
availableDays, | ||
slotFetchCount, | ||
...newState | ||
} = result; | ||
const result = statusReducer(oldState, { | ||
type: "SET_SLOTS", | ||
slots: testSingleSlotsArray, | ||
tzid: "Europe/London", | ||
}); | ||
// These values have been updated | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSingleSlotsObject); | ||
expect(availableDays).toStrictEqual(["2021-09-29"]); | ||
expect(slotFetchCount).toBe(1); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.availableDays; | ||
delete oldState.slotFetchCount; | ||
delete oldState.slotInjectionPoint; | ||
delete oldState.daySlots; | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
const { | ||
selectedDay, | ||
focusedDay, | ||
slots, | ||
availableDays, | ||
slotFetchCount, | ||
slotInjectionPoint, | ||
daySlots, | ||
...newState | ||
} = result; | ||
it("SET_DEFAULT_SLOTS", async () => { | ||
const oldState = { | ||
...startingState, | ||
selectedDay: false, | ||
focusedDay: false, | ||
slots: {}, | ||
availableDays: [], | ||
slotFetchCount: 0, | ||
}; | ||
const result = statusReducer(oldState, { | ||
type: "SET_DEFAULT_SLOTS", | ||
slots: {}, | ||
tzid: "Europe/London", | ||
}); | ||
// These values have been updated | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSingleSlotsObject); | ||
expect(availableDays).toStrictEqual(["2021-09-29"]); | ||
expect(slotFetchCount).toBe(1); | ||
expect(slotInjectionPoint).toBe("2021-09-29"); | ||
expect(daySlots).toStrictEqual(testSingleSlotsArray); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.slotFetchCount; | ||
const { selectedDay, focusedDay, slots, slotFetchCount, ...newState } = result; | ||
// These values have been updated | ||
expect(selectedDay).toBe(false); | ||
expect(focusedDay).toBe(false); | ||
expect(slots).toStrictEqual({}); | ||
expect(slotFetchCount).toBe(1); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
it("SET_DEFAULT_SLOTS when there is only one available slot", async () => { | ||
const oldState = { | ||
...startingState, | ||
selectedDay: false, | ||
focusedDay: false, | ||
slots: {}, | ||
slotFetchCount: 0, | ||
}; | ||
const result = statusReducer(oldState, { | ||
type: "SET_DEFAULT_SLOTS", | ||
slots: testSingleSlotsArray, | ||
tzid: "Europe/London", | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.slotFetchCount; | ||
it("sets additional slots", () => { | ||
const oldState = { | ||
...startingState, | ||
slots: testSlotsObjectPartial, | ||
availableDays: ["2021-09-29", "2021-09-30"], | ||
}; | ||
const { selectedDay, focusedDay, slots, slotFetchCount, ...newState } = result; | ||
const result = statusReducer(oldState, { | ||
type: "SET_SLOTS", | ||
slots: testSlotsArrayAdditional, | ||
tzid: "Europe/London", | ||
}); | ||
// These values have been updated | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSingleSlotsObject); | ||
expect(slotFetchCount).toBe(1); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.slotFetchCount; | ||
delete oldState.slotInjectionPoint; | ||
delete oldState.availableDays; | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
const { | ||
selectedDay, | ||
focusedDay, | ||
slots, | ||
slotFetchCount, | ||
slotInjectionPoint, | ||
availableDays, | ||
...newState | ||
} = result; | ||
it("SET_ADDITIONAL_SLOTS", async () => { | ||
const oldState = { | ||
...startingState, | ||
slots: testSlotsObjectPartial, | ||
}; | ||
const result = statusReducer(oldState, { | ||
type: "SET_ADDITIONAL_SLOTS", | ||
slots: testSlotsArrayAdditional, | ||
tzid: "Europe/London", | ||
}); | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSlotsObject); | ||
expect(slotFetchCount).toBe(2); | ||
expect(slotInjectionPoint).toBe("2021-10-01"); | ||
expect(availableDays).toStrictEqual([ | ||
"2021-09-29", | ||
"2021-09-30", | ||
"2021-10-01", | ||
"2021-10-04", | ||
]); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.slotFetchCount; | ||
const { selectedDay, focusedDay, slots, slotFetchCount, ...newState } = result; | ||
// These values have been updated | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSlotsObject); | ||
expect(slotFetchCount).toBe(2); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
it("SET_ADDITIONAL_SLOTS when there is only one available slot", async () => { | ||
const oldState = { | ||
...startingState, | ||
selectedDay: false, | ||
focusedDay: false, | ||
slots: {}, | ||
slotFetchCount: 0, | ||
}; | ||
const result = statusReducer(oldState, { | ||
type: "SET_ADDITIONAL_SLOTS", | ||
slots: testSingleSlotsArray, | ||
tzid: "Europe/London", | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.slotFetchCount; | ||
const { selectedDay, focusedDay, slots, slotFetchCount, ...newState } = result; | ||
// These values have been updated | ||
expect(selectedDay).toBe("2021-09-29"); | ||
expect(focusedDay).toBe("2021-09-29"); | ||
expect(slots).toStrictEqual(testSingleSlotsObject); | ||
expect(slotFetchCount).toBe(1); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
@@ -396,57 +335,2 @@ | ||
it("SET_FOCUS_FOR_NEW_MONTH", async () => { | ||
const oldState = { ...startingState }; | ||
const date = "2021-10-01"; | ||
const month = "2021-10"; | ||
const result = statusReducer(oldState, { | ||
type: "SET_FOCUS_FOR_NEW_MONTH", | ||
focusedDay: date, | ||
month: month, | ||
}); | ||
const expectedResultForMonths = [ | ||
{ | ||
month: "2021-09", | ||
current: false, | ||
query: { | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-29T08:00:00Z", | ||
end: "2021-09-30T22:59:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
max_results: 512, | ||
}, | ||
}, | ||
{ | ||
month: "2021-10", | ||
current: true, | ||
query: { | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-30T23:00:00Z", | ||
end: "2021-10-04T18:00:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
max_results: 512, | ||
}, | ||
}, | ||
]; | ||
delete oldState.focusedDay; | ||
delete oldState.months; | ||
const { focusedDay, months, ...newState } = result; | ||
// These values have been updated | ||
expect(focusedDay).toBe(date); | ||
expect(JSON.stringify(months)).toBe(JSON.stringify(expectedResultForMonths)); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
it("SELECT_DAY", async () => { | ||
@@ -506,55 +390,120 @@ const oldState = { ...startingState }; | ||
it("SELECT_MONTH", async () => { | ||
const oldState = { ...startingState }; | ||
const month = "2021-10"; | ||
const result = statusReducer(oldState, { | ||
type: "SELECT_MONTH", | ||
month: month, | ||
describe("SELECT_MONTH", () => { | ||
it("selects month", () => { | ||
const oldState = { ...startingState }; | ||
const month = "2021-10"; | ||
const result = statusReducer(oldState, { | ||
type: "SELECT_MONTH", | ||
month: month, | ||
tzid: "Europe/London", | ||
}); | ||
const expectedResultForMonths = [ | ||
{ | ||
month: "2021-09", | ||
current: false, | ||
query: { | ||
max_results: 512, | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-29T08:00:00Z", | ||
end: "2021-09-30T22:59:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
}, | ||
}, | ||
{ | ||
month: "2021-10", | ||
current: true, | ||
query: { | ||
max_results: 512, | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-30T23:00:00Z", | ||
end: "2021-10-04T18:00:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
}, | ||
}, | ||
]; | ||
delete oldState.months; | ||
delete oldState.focusedDay; | ||
delete oldState.monthlyView; | ||
const { focusedDay, months, monthlyView, ...newState } = result; | ||
// These values have been updated | ||
expect(focusedDay).toBe(false); | ||
expect(monthlyView).toStrictEqual(testMonthlySlots[1]); | ||
expect(months).toStrictEqual(expectedResultForMonths); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
const expectedResultForMonths = [ | ||
{ | ||
month: "2021-09", | ||
current: false, | ||
query: { | ||
max_results: 512, | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-29T08:00:00Z", | ||
end: "2021-09-30T22:59:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
it("selects month with focusedDay", () => { | ||
const oldState = { ...startingState }; | ||
const month = "2021-10"; | ||
const date = "2021-10-09"; | ||
const result = statusReducer(oldState, { | ||
type: "SELECT_MONTH", | ||
month: month, | ||
focusedDay: date, | ||
tzid: "Europe/London", | ||
}); | ||
const expectedResultForMonths = [ | ||
{ | ||
month: "2021-09", | ||
current: false, | ||
query: { | ||
max_results: 512, | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-29T08:00:00Z", | ||
end: "2021-09-30T22:59:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
month: "2021-10", | ||
current: true, | ||
query: { | ||
max_results: 512, | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-30T23:00:00Z", | ||
end: "2021-10-04T18:00:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
{ | ||
month: "2021-10", | ||
current: true, | ||
query: { | ||
max_results: 512, | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
query_periods: [ | ||
{ | ||
start: "2021-09-30T23:00:00Z", | ||
end: "2021-10-04T18:00:00Z", | ||
}, | ||
], | ||
required_duration: { minutes: 60 }, | ||
}, | ||
}, | ||
}, | ||
]; | ||
]; | ||
delete oldState.months; | ||
delete oldState.focusedDay; | ||
delete oldState.months; | ||
delete oldState.focusedDay; | ||
delete oldState.monthlyView; | ||
const { focusedDay, months, ...newState } = result; | ||
const { focusedDay, months, monthlyView, ...newState } = result; | ||
// These values have been updated | ||
expect(focusedDay).toBe(false); | ||
expect(months).toStrictEqual(expectedResultForMonths); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
// These values have been updated | ||
expect(date).toBe(focusedDay); | ||
expect(monthlyView).toStrictEqual(testMonthlySlots[1]); | ||
expect(months).toStrictEqual(expectedResultForMonths); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
}); | ||
it("SELECT_SLOT", async () => { | ||
@@ -602,5 +551,5 @@ const oldState = { ...startingState }; | ||
delete oldState.daySlots; | ||
delete oldState.monthlySlots; | ||
delete oldState.monthlyView; | ||
const { availableDays, daySlots, monthlySlots, ...newState } = result; | ||
const { availableDays, daySlots, monthlyView, ...newState } = result; | ||
@@ -615,3 +564,3 @@ // These values have been updated | ||
expect(daySlots).toStrictEqual(testDaySlots); | ||
expect(monthlySlots).toStrictEqual(testMonthlySlots); | ||
expect(monthlyView).toStrictEqual(testMonthlyView); | ||
// All other values are unchanged | ||
@@ -618,0 +567,0 @@ expect(newState).toStrictEqual(oldState); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3215734
26099