diff --git a/components/consultation/form.spec.ts b/components/consultation/form.spec.ts index 603c3aad5..f8b428377 100644 --- a/components/consultation/form.spec.ts +++ b/components/consultation/form.spec.ts @@ -238,111 +238,6 @@ describe.skip("Component: consultation/form", () => { const otherReasonField = wrapper.findComponent(".other-reason") expect(otherReasonField.exists()).toBeTruthy() }) - - it("should eliminate time options", async() => { - const roles = { - "data": [ - { - "id": 0, - "name": "Role A" - } - ] - } - const employees = { - "data": [ - { - "attributes": { - "email": "", - "kind": "reachable_employee", - "name": "Employee A", - roles - }, - "id": "2", - "type": "user" - } - ] - } - fetchMock.mockResponseOnce( - JSON.stringify(employees), - { "status": RequestEnvironment.status.OK } - ) - const schedules = { - "data": [ - { - "attributes": { - "dayName": "monday", - "scheduleEnd": convertTimeToMinutes("09:00"), - "scheduleStart": convertTimeToMinutes("08:00") - }, - "id": "1", - "type": "employee_schedule" - } - ], - "meta": { - "count": 1 - } - } - - const wrapper = shallowMount(Component, { - "global": { - "provide": { - "pageContext": { - "pageProps": { - "userProfile": { - "data": { - "id": "1", - "type": "user" - } - } - } - } - }, - "stubs": { - "Overlay": false, - "SearchableChip": false, - "SelectableOptionsField": false - } - }, - "props": { - "isShown": true - } - }) - - const consultorBox = wrapper.find(".consultor") - const consultorSearchField = consultorBox.findComponent({ - "name": "NonSensitiveTextField" - }) - await consultorSearchField.setValue(employees.data[0].attributes.name) - jest.advanceTimersByTime(DEBOUNCED_WAIT_DURATION) - - fetchMock.mockResponseOnce( - JSON.stringify(schedules), - { "status": RequestEnvironment.status.OK } - ) - // Display consultor chip - await flushPromises() - const employeeChip = wrapper.find(".chip") - await employeeChip.trigger("click") - - // Load selectable days and its options - await flushPromises() - const selectableDay = wrapper.find(".selectable-day") - expect(selectableDay.exists()).toBeTruthy() - const dayOptions = selectableDay.findAll("option") - expect(dayOptions).toHaveLength(3) - - // Load selectable times and its options - const castedWrapper = wrapper.vm as any - castedWrapper.dateToday = new Date(dayOptions[1].attributes("value") as string) - castedWrapper.dateToday.setHours(21) - await flushPromises() - const selectableDayField = selectableDay.find("select") - await selectableDayField.setValue(dayOptions[1].attributes("value")) - const selectedDayIsPast = wrapper.find(".selected-day-is-past") - - // Eliminate options that are after the current hour - expect(selectedDayIsPast.exists()).toBeTruthy() - }) }) describe("Form submission", () => { diff --git a/components/consultation/helpers/scheduler.spec.ts b/components/consultation/helpers/scheduler.spec.ts index 036ee6b8d..08ea351df 100644 --- a/components/consultation/helpers/scheduler.spec.ts +++ b/components/consultation/helpers/scheduler.spec.ts @@ -175,4 +175,54 @@ describe("Component: consultation/helpers/scheduler", () => { expect(emitted).toHaveProperty("update:chosenDay.0.0", defaultDay.toJSON()) expect(emitted).toHaveProperty("update:chosenTime.0.0", chosenTime) }) + + it("can determine if consultor is not available for the selected day", async() => { + const currentTime = new Date() + const currentHour = 10 + currentTime.setHours(currentHour) + currentTime.setMinutes(0) + currentTime.setSeconds(0) + currentTime.setMilliseconds(0) + + const schedules = { + "data": [ + { + "dayName": DayValues[currentTime.getDay()], + "id": "1", + "scheduleEnd": convertTimeToMinutes("09:00"), + "scheduleStart": convertTimeToMinutes("08:00"), + "type": "employee_schedule" + } + ], + "meta": { + "count": 1 + } + } as any + + const defaultDay = new Date(currentTime) + defaultDay.setHours(0) + + const wrapper = shallowMount(Component, { + "props": { + "chosenDay": defaultDay.toJSON(), + "chosenTime": "", + "consultorSchedules": schedules + } + }) + + // Load selectable days and its options + const castWrapper = wrapper.vm as any + castWrapper.dateToday = currentTime + + const selectableDay = wrapper + .find(".selectable-day") + .findComponent({ "name": "SelectableOptionsField" }) + await selectableDay.vm.$emit("update:modelValue", defaultDay.toJSON()) + await wrapper.setProps({ + "chosenDay": defaultDay.toJSON() + }) + + const selectedDayIsPast = wrapper.find(".selected-day-is-past") + expect(selectedDayIsPast.exists()).toBeTruthy() + }) })