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 test to component
Browse files Browse the repository at this point in the history
  • Loading branch information
lemredd committed Nov 14, 2022
1 parent fe124e6 commit 2730463
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 113 deletions.
109 changes: 0 additions & 109 deletions components/consultation/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,115 +239,6 @@ describe.skip("Component: consultation/form", () => {
expect(otherReasonField.exists()).toBeTruthy()
})

it("can select within employee's schedules", 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 consultantBox = wrapper.find(".consultant")
const consultantSearchField = consultantBox.findComponent({
"name": "NonSensitiveTextField"
})
await consultantSearchField.setValue(employees.data[0].attributes.name)
jest.advanceTimersByTime(DEBOUNCED_WAIT_DURATION)

fetchMock.mockResponseOnce(
JSON.stringify(schedules),
{ "status": RequestEnvironment.status.OK }
)
// Display consultant chip
await flushPromises()
const employeeChip = wrapper.find(".chip")
await employeeChip.trigger("click")

// Load selectable days and its options
const castedWrapper = wrapper.vm as any
castedWrapper.dateToday = new Date().setHours(7)
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
await flushPromises()
const selectableDayField = selectableDay.find("select")
await selectableDayField.setValue(dayOptions[1].attributes("value"))
const selectableTime = wrapper.find(".selectable-time")
const timeOptions = selectableTime.findAll("option")
expect(selectableTime.exists()).toBeTruthy()
expect(timeOptions.length).toBeGreaterThan(0)

// Customizable date
await selectableDayField.setValue(dayOptions[2].attributes("value"))
expect(selectableTime.exists()).toBeTruthy()
expect(timeOptions.length).toBeGreaterThan(0)
})

it("should eliminate time options", async() => {
const roles = {
"data": [
Expand Down
67 changes: 67 additions & 0 deletions components/consultation/helpers/scheduler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import convertTimeToMinutes from "$/time/convert_time_to_minutes"
import { shallowMount } from "@vue/test-utils"

import Component from "./scheduler.vue"

describe.skip("Component: consultation/helpers/scheduler", () => {
it("can select within employee's schedules", async() => {
const schedules = {
"data": [
{
"attributes": {
"dayName": "monday",
"scheduleEnd": convertTimeToMinutes("09:00"),
"scheduleStart": convertTimeToMinutes("08:00")
},
"id": "1",
"type": "employee_schedule"
}
],
"meta": {
"count": 1
}
} as any

const wrapper = shallowMount(Component, {
"global": {
"stubs": {
"SelectableOptionsField": false
}
},
"props": {
"chosenDay": "",
"chosenTime": "",
"consultantSchedules": schedules
}
})

// Load selectable days and its options
const currentHour = 8
const castedWrapper = wrapper.vm as any
castedWrapper.dateToday = new Date()
castedWrapper.dateToday.setHours(currentHour)
console.log(castedWrapper.dateToday)
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 chosenDay = dayOptions[1].attributes("value")
const selectableDayField = selectableDay.find("select")
console.log(selectableDayField.html(), "\n\n\n")
await selectableDayField.setValue(chosenDay)
await wrapper.setProps({ chosenDay })
console.log(wrapper.html(), "\n\n\n")
const selectableTime = wrapper.find(".selectable-time")
expect(selectableTime.exists()).toBeTruthy()
// const timeOptions = selectableTime.findAll("option")
// expect(selectableTime.exists()).toBeTruthy()
// expect(timeOptions.length).toBeGreaterThan(0)

// Customizable date
// await selectableDayField.setValue(dayOptions[2].attributes("value"))
// expect(selectableTime.exists()).toBeTruthy()
// expect(timeOptions.length).toBeGreaterThan(0)
})
})
5 changes: 1 addition & 4 deletions components/consultation/helpers/scheduler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ const reorderedDays = [ ...DayValues.slice(dayIndex), ...DayValues.slice(0, dayI
const chosenDay = computed({
get() { return props.chosenDay },
set(newValue: string) {
console.log("set new value", newValue)
emit("update:chosenDay", newValue)
}
set(newValue: string) { emit("update:chosenDay", newValue) }
})
const customDate = ref("")
const isCustomDate = computed(() => chosenDay.value === "custom")
Expand Down

0 comments on commit 2730463

Please sign in to comment.