Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
unit(consultation): ensure updating of time
Browse files Browse the repository at this point in the history
  • Loading branch information
lemredd committed Nov 14, 2022
1 parent dfdfdf1 commit 061164f
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion components/consultation/chat_window/rescheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,83 @@ describe("Component: consultation rescheduler", () => {
})
})

it.todo("can emit new set schedule")
it("can update schedule time", async() => {
const schedules = {
"data": [
{
"attributes": {
"dayName": "monday",
"scheduleEnd": convertTimeToMinutes("09:00"),
"scheduleStart": convertTimeToMinutes("08:00")
},
"id": "1",
"type": "employee_schedule"
}
],
"meta": {
"count": 1
}
}
fetchMock.mockResponseOnce(
JSON.stringify(schedules),
{ "status": RequestEnvironment.status.OK }
)

fetchMock.mockResponseOnce("", { "status": RequestEnvironment.status.NO_CONTENT })

const wrapper = shallowMount(Component, {
"global": {
"provide": {
"pageContext": {
"pageProps": {
"consultation": {
"data": {
"scheduledStartAt": new Date("2022-10-09 07:00")
}
}
}
}
},
"stubs": {
"Overlay": false
}
},
"props": {
"isShown": true
}
})
// Load consultant schedules
await flushPromises()

// Change day
const scheduler = wrapper.findComponent({ "name": "Scheduler" })
const newDate = new Date("2022-10-10").toJSON()
const newTime = convertTimeToMinutes("08:00")
await scheduler.vm.$emit("update:chosenDay", newDate)
await scheduler.vm.$emit("update:chosenTime", newTime)

// Submit changes
const rescheduleBtn = wrapper.find(".reschedule-btn")
await rescheduleBtn.trigger("click")
await flushPromises()

const mockedFetch = fetch as jest.Mock<any, any>
const [
[ unusedRequestForFetchingConsultantSchedule ],
[ requestForUpdatingConsultationSchedule ]
] = mockedFetch.mock.calls
expect(requestForUpdatingConsultationSchedule).toHaveProperty("method", "PATCH")
expect(await requestForUpdatingConsultationSchedule.json()).toStrictEqual({
"data": {
"attributes": {
"actionTaken": null,
"deletedAt": null,
"finishedAt": null,
"scheduledStartAt": newDate,
"startedAt": null
},
"type": "consultation"
}
})
})
})

0 comments on commit 061164f

Please sign in to comment.