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

Commit

Permalink
unit(consultation): move unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lemredd committed Dec 9, 2022
1 parent f3e7bd7 commit a3456ad
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 105 deletions.
105 changes: 0 additions & 105 deletions components/consultation/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>(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", () => {
Expand Down
50 changes: 50 additions & 0 deletions components/consultation/helpers/scheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

0 comments on commit a3456ad

Please sign in to comment.