Skip to content

Commit bea806e

Browse files
committed
vis melding p\u00e5 feedback-siden n\u00e5r kanalen ikke er \u00e5pen enda
N\u00e5r channel.isOpen er false, viser session-siden en notis ("Feedback is not open yet" / "Please check again closer to when the session starts") i stedet for skjemaet, og feedback.js lastes ikke.
1 parent 1995ac2 commit bea806e

3 files changed

Lines changed: 151 additions & 37 deletions

File tree

core/src/main/kotlin/no/javazone/feedback/pages/FeedbackPage.kt

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,57 +71,66 @@ fun HTML.feedbackPage(channel: FeedbackChannel) {
7171
+channel.speakers.joinToString(", ")
7272
}
7373

74-
form {
75-
id = "feedback-form"
76-
attributes["data-channel-id"] = channel.externalId
74+
if (!channel.isOpen) {
75+
div("channel-closed-notice") {
76+
h2 { +"Feedback is not open yet" }
77+
p { +"Please check again closer to when the session starts" }
78+
}
79+
} else {
80+
form {
81+
id = "feedback-form"
82+
attributes["data-channel-id"] = channel.externalId
7783

78-
channel.ratingCategories.forEach { category ->
79-
fieldSet("rating-group") {
80-
legend { +category.name }
81-
div("rating-buttons") {
82-
for (score in 1..5) {
83-
input(InputType.radio) {
84-
name = "rating-${category.id}"
85-
value = "$score"
86-
id = "rating-${category.id}-$score"
87-
required = true
88-
}
89-
label {
90-
htmlFor = "rating-${category.id}-$score"
91-
+"$score"
84+
channel.ratingCategories.forEach { category ->
85+
fieldSet("rating-group") {
86+
legend { +category.name }
87+
div("rating-buttons") {
88+
for (score in 1..5) {
89+
input(InputType.radio) {
90+
name = "rating-${category.id}"
91+
value = "$score"
92+
id = "rating-${category.id}-$score"
93+
required = true
94+
}
95+
label {
96+
htmlFor = "rating-${category.id}-$score"
97+
+"$score"
98+
}
9299
}
93100
}
94101
}
95102
}
96-
}
97103

98-
div("comment-group") {
99-
label {
100-
htmlFor = "detailed-comment"
101-
+"Comments (optional)"
102-
}
103-
textArea {
104-
id = "detailed-comment"
105-
name = "detailedComment"
106-
rows = "4"
107-
placeholder = "Share your thoughts..."
104+
div("comment-group") {
105+
label {
106+
htmlFor = "detailed-comment"
107+
+"Comments (optional)"
108+
}
109+
textArea {
110+
id = "detailed-comment"
111+
name = "detailedComment"
112+
rows = "4"
113+
placeholder = "Share your thoughts..."
114+
}
108115
}
109-
}
110116

111-
button(type = ButtonType.submit) {
112-
id = "submit-btn"
113-
+"Submit Feedback"
114-
}
117+
button(type = ButtonType.submit) {
118+
id = "submit-btn"
119+
+"Submit Feedback"
120+
}
115121

116-
p("error-message") {
117-
id = "error-message"
118-
attributes["aria-live"] = "polite"
122+
p("error-message") {
123+
id = "error-message"
124+
attributes["aria-live"] = "polite"
125+
}
119126
}
120127
}
121128
}
122129
}
123130

124-
script { src = "/static/js/feedback.js" }
131+
if (channel.isOpen) {
132+
script { src = "/static/js/feedback.js" }
133+
}
125134
}
126135
}
127136

core/src/main/resources/static/css/feedback.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,27 @@ button[type="submit"]:disabled {
185185
color: #666;
186186
}
187187

188+
.channel-closed-notice {
189+
text-align: center;
190+
padding: 2rem 1rem;
191+
background: #f9fafb;
192+
border: 1px solid #e5e7eb;
193+
border-radius: 8px;
194+
margin-top: 1rem;
195+
}
196+
197+
.channel-closed-notice h2 {
198+
font-size: 1.1rem;
199+
font-weight: 600;
200+
margin-bottom: 0.5rem;
201+
color: #1a1a1a;
202+
}
203+
204+
.channel-closed-notice p {
205+
color: #666;
206+
font-size: 0.95rem;
207+
}
208+
188209
/* Landing page */
189210

190211
.landing {

core/src/test/kotlin/no/javazone/feedback/FeedbackEndpointsTest.kt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ class FeedbackEndpointsTest {
523523
)
524524
}.body<FeedbackChannelDTO>()
525525

526+
jsonClient.patch("/v1/feedback/channel/${channel.channelId}") {
527+
adminAuth()
528+
contentType(ContentType.Application.Json)
529+
setBody(FeedbackChannelUpdateDTO(isOpen = true))
530+
}
531+
526532
val response = client.get("/session/${channel.channelId}")
527533

528534
assertEquals(HttpStatusCode.OK, response.status)
@@ -570,6 +576,78 @@ class FeedbackEndpointsTest {
570576
assertEquals(HttpStatusCode.BadRequest, response.status)
571577
}
572578

579+
@Test
580+
fun `feedback page shows closed notice when channel is not open`() = testApplication {
581+
application {
582+
module(TestDatabase.config(), testAuthConfig)
583+
}
584+
585+
val jsonClient = createClient {
586+
install(ContentNegotiation) {
587+
json()
588+
}
589+
}
590+
591+
val channel = jsonClient.post("/v1/feedback/channel") {
592+
adminAuth()
593+
contentType(ContentType.Application.Json)
594+
setBody(
595+
FeedbackChannelCreationDTO(
596+
title = "Not yet open",
597+
speakers = listOf("Speaker"),
598+
ratingCategories = listOf(FeedbackChannelRatingCategoryDTO(id = null, title = "Rating"))
599+
)
600+
)
601+
}.body<FeedbackChannelDTO>()
602+
603+
val response = client.get("/session/${channel.channelId}")
604+
605+
assertEquals(HttpStatusCode.OK, response.status)
606+
val body = response.bodyAsText()
607+
assertTrue(body.contains("Feedback is not open yet"))
608+
assertTrue(body.contains("Please check again closer to when the session starts"))
609+
assertTrue(!body.contains("feedback-form"))
610+
assertTrue(!body.contains("submit-btn"))
611+
assertTrue(!body.contains("/static/js/feedback.js"))
612+
}
613+
614+
@Test
615+
fun `feedback page shows form after channel is opened`() = testApplication {
616+
application {
617+
module(TestDatabase.config(), testAuthConfig)
618+
}
619+
620+
val jsonClient = createClient {
621+
install(ContentNegotiation) {
622+
json()
623+
}
624+
}
625+
626+
val channel = jsonClient.post("/v1/feedback/channel") {
627+
adminAuth()
628+
contentType(ContentType.Application.Json)
629+
setBody(
630+
FeedbackChannelCreationDTO(
631+
title = "Opened",
632+
speakers = listOf("Speaker"),
633+
ratingCategories = listOf(FeedbackChannelRatingCategoryDTO(id = null, title = "Rating"))
634+
)
635+
)
636+
}.body<FeedbackChannelDTO>()
637+
638+
jsonClient.patch("/v1/feedback/channel/${channel.channelId}") {
639+
adminAuth()
640+
contentType(ContentType.Application.Json)
641+
setBody(FeedbackChannelUpdateDTO(isOpen = true))
642+
}
643+
644+
val body = client.get("/session/${channel.channelId}").bodyAsText()
645+
646+
assertTrue(body.contains("feedback-form"))
647+
assertTrue(body.contains("submit-btn"))
648+
assertTrue(!body.contains("Feedback is not open yet"))
649+
}
650+
573651
@Test
574652
fun `test thank you page returns HTML fragment`() = testApplication {
575653
application {
@@ -635,6 +713,12 @@ class FeedbackEndpointsTest {
635713
)
636714
}.body<FeedbackChannelDTO>()
637715

716+
jsonClient.patch("/v1/feedback/channel/${channel.channelId}") {
717+
adminAuth()
718+
contentType(ContentType.Application.Json)
719+
setBody(FeedbackChannelUpdateDTO(isOpen = true))
720+
}
721+
638722
val body = client.get("/session/${channel.channelId}").bodyAsText()
639723

640724
// Each rating category should have a fieldset with 5 radio inputs

0 commit comments

Comments
 (0)