Skip to content

Commit 1e0c181

Browse files
committed
fix/qg-235: исправлена ошибка с отображением статуса приема
1 parent 8f0f60b commit 1e0c181

File tree

6 files changed

+59
-46
lines changed

6 files changed

+59
-46
lines changed

app/src/main/resources/templates/therapist/appointments/appointment-edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h1 class="mt-4 pb-2 mb-3 border-bottom d-flex justify-content-between align-ite
3737
id="editAppointmentForm"
3838
th:attr="hx-post=${pageMode == 'CREATE' ? '/therapist/appointments/new' : null},hx-put=${pageMode == 'EDIT' ? '/therapist/appointments/' + appointmentId : null}"
3939
th:fragment="editAppointmentForm"
40-
th:x-data="|{'dateTime': '${appointment?.dateTime ?: dateTime}', 'status': 'PENDING', canChangeStatus() { return Date.parse(this.dateTime) <= new Date() } }|"
40+
th:x-data="|{'dateTime': '${appointment?.dateTime ?: dateTime}', 'status': '${appointment?.appointmentStatus ?: 'PENDING'}', canChangeStatus() { return Date.parse(this.dateTime) <= new Date() } }|"
4141
>
4242

4343
<input id="externalId"

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/appointments/core/EditAppointmentPageTest.kt

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import pro.azhidkov.platform.spring.sdj.ergo.hydration.ref
99
import pro.azhidkov.platform.spring.sdj.ergo.hydration.resolveOrThrow
1010
import pro.azhidkov.timezones.TimeZones
1111
import pro.qyoga.app.therapist.appointments.core.schedule.SchedulePageController
12+
import pro.qyoga.core.appointments.core.model.AppointmentStatus
1213
import pro.qyoga.core.appointments.core.toEditRequest
1314
import pro.qyoga.tests.assertions.shouldBePage
1415
import pro.qyoga.tests.assertions.shouldHave
1516
import pro.qyoga.tests.assertions.shouldHaveElement
1617
import pro.qyoga.tests.assertions.shouldMatch
17-
import pro.qyoga.tests.clients.TherapistClient
18+
import pro.qyoga.tests.fixture.backgrounds.AppointmentsBackgrounds
1819
import pro.qyoga.tests.fixture.data.randomCyrillicWord
1920
import pro.qyoga.tests.fixture.object_mothers.appointments.AppointmentsObjectMother
2021
import pro.qyoga.tests.fixture.object_mothers.appointments.AppointmentsObjectMother.aAppointmentId
@@ -36,16 +37,15 @@ import java.time.ZoneId
3637
class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
3738

3839
private val timeZones = getBean<TimeZones>()
40+
private val appointmentBackgrounds = getBean<AppointmentsBackgrounds>()
3941

4042
@Test
4143
fun `Страница редактирования только с обязательными полями записи на прием должна корректно отображаться и заполняться`() {
4244
// Сетап
43-
val appointment = backgrounds.appointments.create()
44-
45-
val therapist = TherapistClient.loginAsTheTherapist()
45+
val appointment = appointmentBackgrounds.create()
4646

4747
// Действие
48-
val document = therapist.appointments.getEditAppointmentPage(appointment.ref())
48+
val document = theTherapist.appointments.getEditAppointmentPage(appointment.ref())
4949

5050
// Проверка
5151
document shouldBePage EditAppointmentPage
@@ -55,12 +55,10 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
5555
@Test
5656
fun `Страница редактирования со всеми заполененными полями записи на прием должна корректно отображаться и заполняться`() {
5757
// Сетап
58-
val appointment = backgrounds.appointments.createFull()
59-
60-
val therapist = TherapistClient.loginAsTheTherapist()
58+
val appointment = appointmentBackgrounds.createFull()
6159

6260
// Действие
63-
val document = therapist.appointments.getEditAppointmentPage(appointment.ref())
61+
val document = theTherapist.appointments.getEditAppointmentPage(appointment.ref())
6462

6563
// Проверка
6664
document shouldBePage EditAppointmentPage
@@ -70,7 +68,7 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
7068
@Test
7169
fun `Отредактированная запись на прием только с обязательными полями должна сохраняться`() {
7270
// Сетап
73-
val appointment = backgrounds.appointments.create()
71+
val appointment = appointmentBackgrounds.create()
7472
val newAppointmentType = backgrounds.appointmentTypes.createAppointmentType()
7573
val therapeuticTask = backgrounds.therapeuticTasks.createTherapeuticTask()
7674
val editedAppointment =
@@ -85,24 +83,22 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
8583
comment = randomCyrillicWord()
8684
)
8785

88-
val therapist = TherapistClient.loginAsTheTherapist()
89-
9086
// Действие
91-
val response = therapist.appointments.editAppointment(appointment.ref(), editedAppointment)
87+
val response = theTherapist.appointments.editAppointment(appointment.ref(), editedAppointment)
9288

9389
// Проверка
9490
response.statusCode() shouldBe HttpStatus.OK.value()
9591
response shouldBePage CalendarPage
9692

9793
val persistedAppointment =
98-
backgrounds.appointments.getDaySchedule(editedAppointment.dateTime.toLocalDate()).single()
94+
appointmentBackgrounds.getDaySchedule(editedAppointment.dateTime.toLocalDate()).single()
9995
persistedAppointment.shouldMatch(editedAppointment)
10096
}
10197

10298
@Test
10399
fun `Отредактированная запись на прием со всеми полями должна сохраняться`() {
104100
// Сетап
105-
val appointment = backgrounds.appointments.createFull()
101+
val appointment = appointmentBackgrounds.createFull()
106102
val editedAppointment =
107103
AppointmentsObjectMother.appointmentPatchRequest(
108104
appointment,
@@ -115,27 +111,22 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
115111
comment = null
116112
)
117113

118-
val therapist = TherapistClient.loginAsTheTherapist()
119-
120114
// Действие
121-
val response = therapist.appointments.editAppointment(appointment.ref(), editedAppointment)
115+
val response = theTherapist.appointments.editAppointment(appointment.ref(), editedAppointment)
122116

123117
// Проверка
124118
response.statusCode() shouldBe HttpStatus.OK.value()
125119
response shouldBePage CalendarPage
126120

127-
val persistedAppointment = backgrounds.appointments.findAll().single()
121+
val persistedAppointment = appointmentBackgrounds.findAll().single()
128122
persistedAppointment shouldMatch editedAppointment
129123
}
130124

131125
@Test
132126
fun `При запросе страницы редактирования несуществующего приема должна возвращаться страница с ошибкой 404`() {
133-
// Сетап
134-
val therapist = TherapistClient.loginAsTheTherapist()
135-
136127
// Действие
137128
val document =
138-
therapist.appointments.getEditAppointmentPage(aAppointmentId(), expectedStatus = HttpStatus.NOT_FOUND)
129+
theTherapist.appointments.getEditAppointmentPage(aAppointmentId(), expectedStatus = HttpStatus.NOT_FOUND)
139130

140131
// Проверка
141132
document shouldBePage (NotFoundErrorPage as HtmlPage)
@@ -144,12 +135,10 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
144135
@Test
145136
fun `При запросе на редактировании несуществующего приема должна возвращаться страница с ошибкой 404`() {
146137
// Сетап
147-
val therapist = TherapistClient.loginAsTheTherapist()
148-
149138
val editAppointmentRequest = randomEditAppointmentRequest()
150139

151140
// Действие
152-
val response = therapist.appointments.editAppointment(
141+
val response = theTherapist.appointments.editAppointment(
153142
aAppointmentId(), editAppointmentRequest
154143
)
155144

@@ -166,23 +155,21 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
166155
val zoneId = ZoneId.of("Asia/Novosibirsk")
167156
val existingAppointmentDuration = Duration.ofHours(1)
168157

169-
val existingAppointment = backgrounds.appointments.create(
158+
val existingAppointment = appointmentBackgrounds.create(
170159
dateTime = appointmentsDate.atTime(appointmentsBaseTime),
171160
timeZone = zoneId,
172161
duration = existingAppointmentDuration
173162
)
174-
val nextNotRescheduledAppointment = backgrounds.appointments.create(
163+
val nextNotRescheduledAppointment = appointmentBackgrounds.create(
175164
dateTime = appointmentsDate.atTime(appointmentsBaseTime).plus(existingAppointmentDuration),
176165
timeZone = zoneId,
177166
duration = existingAppointmentDuration
178167
)
179168
val rescheduleAppointmentRequest = nextNotRescheduledAppointment.copy(dateTime = existingAppointment.dateTime)
180169
.toEditRequest(timeZones::findById)
181170

182-
val therapist = TherapistClient.loginAsTheTherapist()
183-
184171
// Действие
185-
val document = therapist.appointments.editAppointmentForError(
172+
val document = theTherapist.appointments.editAppointmentForError(
186173
nextNotRescheduledAppointment.ref(),
187174
rescheduleAppointmentRequest
188175
)
@@ -192,18 +179,17 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
192179
document shouldHave EditAppointmentForm.formPrefilledWith(rescheduleAppointmentRequest)
193180
document shouldHaveElement CreateAppointmentForm.appointmentsIntersectionErrorMessage
194181

195-
val storedNextAppointment = backgrounds.appointments.findById(nextNotRescheduledAppointment.id)!!
182+
val storedNextAppointment = appointmentBackgrounds.findById(nextNotRescheduledAppointment.id)!!
196183
storedNextAppointment shouldMatch nextNotRescheduledAppointment
197184
}
198185

199186
@Test
200187
fun `Удаление записи на прием должно быть постоянным и перенаправлять на указанный календарный день`() {
201188
// Сетап
202-
val appointment = backgrounds.appointments.create()
203-
val therapist = TherapistClient.loginAsTheTherapist()
189+
val appointment = appointmentBackgrounds.create()
204190

205191
// Действие
206-
val response = therapist.appointments.delete(appointment.ref(), appointment.wallClockDateTime.toLocalDate())
192+
val response = theTherapist.appointments.delete(appointment.ref(), appointment.wallClockDateTime.toLocalDate())
207193

208194
// Проверка
209195
response.statusCode shouldBe HttpStatus.OK.value()
@@ -212,18 +198,16 @@ class EditAppointmentPageTest : QYogaAppIntegrationBaseTest() {
212198
appointment.wallClockDateTime.toLocalDate().toString()
213199
)
214200

215-
backgrounds.appointments.getDaySchedule(appointment.wallClockDateTime.toLocalDate()).shouldBeEmpty()
201+
appointmentBackgrounds.getDaySchedule(appointment.wallClockDateTime.toLocalDate()).shouldBeEmpty()
216202
}
217203

218204
@Test
219205
fun `Запись на прием со статусом 'Клиент пришел' должна отображаться корректно`() {
220206
// Сетап
221-
val appointment = backgrounds.appointments.create(appointmentStatus = AppointmentStatus.CLIENT_CAME)
222-
223-
val therapist = TherapistClient.loginAsTheTherapist()
207+
val appointment = appointmentBackgrounds.create(appointmentStatus = AppointmentStatus.CLIENT_CAME)
224208

225209
// Действие
226-
val document = therapist.appointments.getEditAppointmentPage(appointment.ref())
210+
val document = theTherapist.appointments.getEditAppointmentPage(appointment.ref())
227211

228212
// Проверка
229213
document shouldBePage EditAppointmentPage

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/appointments/core/SchedulePageTest.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ import io.kotest.matchers.shouldBe
66
import org.junit.jupiter.api.DisplayName
77
import org.junit.jupiter.api.Test
88
import pro.azhidkov.platform.spring.sdj.ergo.hydration.ref
9+
import pro.qyoga.core.appointments.core.model.AppointmentStatus
910
import pro.qyoga.core.calendar.ical.model.ICalCalendarItem
1011
import pro.qyoga.tests.assertions.shouldBePage
1112
import pro.qyoga.tests.clients.TherapistClient
1213
import pro.qyoga.tests.fixture.data.asiaNovosibirskTimeZone
1314
import pro.qyoga.tests.fixture.data.randomWorkingTime
1415
import pro.qyoga.tests.fixture.object_mothers.appointments.AppointmentsObjectMother
16+
import pro.qyoga.tests.fixture.object_mothers.appointments.DURATION_FOR_FULL_LABEL
1517
import pro.qyoga.tests.fixture.object_mothers.calendars.CalendarsObjectMother.aCalendarItem
1618
import pro.qyoga.tests.fixture.presets.CalendarsFixturePresets
1719
import pro.qyoga.tests.infra.web.QYogaAppIntegrationBaseTest
1820
import pro.qyoga.tests.pages.therapist.appointments.CalendarPage
1921
import pro.qyoga.tests.pages.therapist.appointments.appointmentCards
2022
import pro.qyoga.tests.pages.therapist.appointments.shouldMatch
2123
import pro.qyoga.tests.platform.instancio.KSelect.Companion.field
24+
import java.time.Duration
2225
import java.time.LocalDate
2326

2427

@@ -59,15 +62,18 @@ class SchedulePageTest : QYogaAppIntegrationBaseTest() {
5962
val appointments = listOf(
6063
backgrounds.appointments.create(
6164
dateTime = today.minusDays(1).atTime(randomWorkingTime()),
62-
timeZone = timeZone
65+
timeZone = timeZone,
66+
duration = DURATION_FOR_FULL_LABEL,
6367
),
6468
backgrounds.appointments.create(
6569
dateTime = today.atTime(randomWorkingTime()),
66-
timeZone = timeZone
70+
timeZone = timeZone,
71+
duration = DURATION_FOR_FULL_LABEL,
6772
),
6873
backgrounds.appointments.create(
6974
dateTime = today.plusDays(1).atTime(randomWorkingTime()),
70-
timeZone = timeZone
75+
timeZone = timeZone,
76+
duration = DURATION_FOR_FULL_LABEL,
7177
),
7278
)
7379

app/src/testFixtures/kotlin/pro/qyoga/tests/fixture/backgrounds/AppointmentsBackgrounds.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import pro.qyoga.app.therapist.appointments.core.schedule.GetCalendarAppointment
88
import pro.qyoga.core.appointments.core.AppointmentsRepo
99
import pro.qyoga.core.appointments.core.commands.EditAppointmentRequest
1010
import pro.qyoga.core.appointments.core.model.Appointment
11+
import pro.qyoga.core.appointments.core.model.AppointmentStatus
1112
import pro.qyoga.core.calendar.api.CalendarItem
1213
import pro.qyoga.core.therapy.therapeutic_tasks.model.TherapeuticTaskRef
1314
import pro.qyoga.core.users.auth.dtos.QyogaUserDetails
1415
import pro.qyoga.core.users.therapists.TherapistRef
1516
import pro.qyoga.core.users.therapists.ref
1617
import pro.qyoga.tests.fixture.data.faker
1718
import pro.qyoga.tests.fixture.data.randomCyrillicWord
19+
import pro.qyoga.tests.fixture.data.randomElement
1820
import pro.qyoga.tests.fixture.data.randomSentence
1921
import pro.qyoga.tests.fixture.data.randomTimeZone
2022
import pro.qyoga.tests.fixture.object_mothers.appointments.AppointmentsObjectMother
@@ -58,12 +60,13 @@ class AppointmentsBackgrounds(
5860
place: String? = randomCyrillicWord(),
5961
cost: Int? = randomAppointmentCost(),
6062
payed: Boolean? = faker.random().nextBoolean(),
63+
appointmentStatus: AppointmentStatus = AppointmentStatus.entries.randomElement(),
6164
comment: String? = randomSentence(),
6265
therapist: TherapistRef = THE_THERAPIST_REF,
6366
therapeuticTaskRef: TherapeuticTaskRef? = therapeuticTasksBackgrounds.createTherapeuticTask(therapist.id!!)
6467
.ref(),
6568
): Appointment {
66-
return create(dateTime, timeZone, duration, place, cost, payed, comment, therapist, therapeuticTaskRef)
69+
return create(dateTime, timeZone, duration, place, cost, payed, appointmentStatus, comment, therapist, therapeuticTaskRef)
6770
}
6871

6972
fun create(
@@ -73,9 +76,10 @@ class AppointmentsBackgrounds(
7376
place: String? = null,
7477
cost: Int? = null,
7578
payed: Boolean? = null,
79+
appointmentStatus: AppointmentStatus = AppointmentStatus.entries.randomElement(),
7680
comment: String? = null,
7781
therapist: TherapistRef = THE_THERAPIST_REF,
78-
therapeuticTaskRef: TherapeuticTaskRef? = null
82+
therapeuticTaskRef: TherapeuticTaskRef? = null,
7983
): Appointment {
8084
val clientRef = clientsBackgrounds.createClients(1, therapist.id!!).single().ref()
8185
val appointment = createAppointment(
@@ -89,6 +93,7 @@ class AppointmentsBackgrounds(
8993
place = place,
9094
cost = cost,
9195
payed = payed,
96+
appointmentStatus = appointmentStatus,
9297
comment = comment
9398
)
9499
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package pro.qyoga.tests.fixture.object_mothers.appointments
2+
3+
import java.time.Duration
4+
5+
val DURATION_FOR_FULL_LABEL = Duration.ofMinutes(25)

app/src/testFixtures/kotlin/pro/qyoga/tests/pages/therapist/appointments/AppointmentForm.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pro.qyoga.tests.pages.therapist.appointments
22

33
import io.kotest.matchers.shouldBe
4+
import org.jsoup.nodes.Element
45
import pro.azhidkov.platform.java.time.toLocalTimeString
56
import pro.azhidkov.platform.spring.sdj.ergo.hydration.resolveOrThrow
67
import pro.qyoga.core.appointments.core.commands.EditAppointmentRequest
@@ -78,8 +79,20 @@ object EditAppointmentForm : AppointmentForm(FormAction.hxPut("$PATH/{appointmen
7879
val payedEl = element.select(payed.selector()).single()
7980
payed.value(payedEl) shouldBe (editAppointmentRequest.payed == true).toString()
8081

82+
val status = statusFromXData(element)
83+
status shouldBe editAppointmentRequest.appointmentStatus.toString()
84+
8185
val commentEl = element.select(comment.selector()).single()
8286
comment.value(commentEl) shouldBe (editAppointmentRequest.comment ?: "")
8387
}
8488

89+
fun statusFromXData(element: Element): String? {
90+
val formElement = element.select("form[x-data]").single()
91+
val xDataValue = formElement?.attr("x-data") ?: return null
92+
val regex = """'status':\s'(.*)'""".toRegex()
93+
val matchResult = regex.find(xDataValue)
94+
95+
return matchResult?.groups?.get(1)?.value
96+
}
97+
8598
}

0 commit comments

Comments
 (0)