cronofy-elements
Advanced tools
Comparing version 1.39.1 to 1.39.2
{ | ||
"name": "cronofy-elements", | ||
"version": "1.39.1", | ||
"version": "1.39.2", | ||
"description": "Fast track scheduling with Cronofy's embeddable UI Elements", | ||
@@ -5,0 +5,0 @@ "main": "build/npm/CronofyElements.js", |
@@ -63,7 +63,7 @@ import { | ||
case "SET_INITIAL_SLOTS": { | ||
const hasNewSlots = Object.keys(action.slots).length > 1; | ||
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 hasAnySlots = Object.keys(slotsObject).length >= 1; | ||
const selectedDay = hasAnySlots | ||
@@ -84,10 +84,11 @@ ? getFirstAvailableDay(slotsObject, state.selectedTzid.tzid) | ||
case "SET_ADDITIONAL_SLOTS": { | ||
const hasNewSlots = Object.keys(action.slots).length > 1; | ||
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, state.selectedTzid.tzid) | ||
: false; | ||
const hasAnySlots = Object.keys(slotsObject).length >= 1; | ||
const selectedDay = | ||
hasAnySlots && !state.selectedDay | ||
? getFirstAvailableDay(slotsObject, state.selectedTzid.tzid) | ||
: state.selectedDay; | ||
return { | ||
@@ -94,0 +95,0 @@ ...state, |
@@ -48,3 +48,5 @@ import React, { useEffect, useRef } from "react"; | ||
)}{" "} | ||
{`(${moment.tz(status.selectedTzid.tzid).format("z")})`} | ||
{`(${moment(slot.start, "YYYY-MM-DDTHH:mm:00Z") | ||
.tz(status.selectedTzid.tzid) | ||
.format("z")})`} | ||
</button> | ||
@@ -51,0 +53,0 @@ ); |
import { statusReducer } from "../../../src/js/components/DateTimePicker/contexts/status-reducer"; | ||
import { | ||
testSingleSlotsArray, | ||
testSingleSlotsObject, | ||
testSlotsObject, | ||
@@ -215,2 +217,42 @@ testSlotsObjectPartial, | ||
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, | ||
}); | ||
delete oldState.selectedDay; | ||
delete oldState.focusedDay; | ||
delete oldState.slots; | ||
delete oldState.availableDays; | ||
delete oldState.slotFetchCount; | ||
const { | ||
selectedDay, | ||
focusedDay, | ||
slots, | ||
availableDays, | ||
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(availableDays).toStrictEqual(["2021-09-29"]); | ||
expect(slotFetchCount).toBe(1); | ||
// All other values are unchanged | ||
expect(newState).toStrictEqual(oldState); | ||
}); | ||
it("SET_DEFAULT_SLOTS", async () => { | ||
@@ -247,2 +289,32 @@ const 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, | ||
}); | ||
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); | ||
}); | ||
it("SET_ADDITIONAL_SLOTS", async () => { | ||
@@ -275,2 +347,32 @@ const 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, | ||
}); | ||
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); | ||
}); | ||
it("SET_FOCUS", async () => { | ||
@@ -277,0 +379,0 @@ const oldState = { ...startingState }; |
@@ -92,2 +92,18 @@ export const rawSlots = { | ||
export const testSingleSlotsArray = [ | ||
{ | ||
start: "2021-09-29T08:00:00Z", | ||
end: "2021-09-29T09:00:00Z", | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
}, | ||
]; | ||
export const testSingleSlotsObject = { | ||
"2021-09-29T08:00:00Z": { | ||
start: "2021-09-29T08:00:00Z", | ||
end: "2021-09-29T09:00:00Z", | ||
participants: [{ sub: "acc_5f35432b3f07d06753082354" }], | ||
}, | ||
}; | ||
export const testSlotsArray = [ | ||
@@ -94,0 +110,0 @@ { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
25874
3198433