test: get new availability

This commit is contained in:
Max Hohlfeld 2025-08-02 13:19:34 +02:00
parent 98e42e20c8
commit 94143f54d7
3 changed files with 169 additions and 1 deletions

View File

@ -0,0 +1,133 @@
---
source: web/src/endpoints/availability/get_new.rs
expression: body
snapshot_kind: text
---
<section class="section">
<div class="container">
<form hx-post="/availability/new" hx-target="body"
hx-target-422="#error">
<h1 class="title">Neue Vefügbarkeit für Mittwoch, 01.01.2025</h1>
<input type="hidden" name="startdate" value="2025-01-01">
<input type="hidden" name="enddate" value="2025-01-01" id="enddate">
<div class="field is-horizontal">
<div class="field-label">
<label class="label">Dauer Von - Bis</label>
</div>
<div class="field-body">
<div class="field">
<input class="input" type="time" name="starttime" required value="10:00"
_="on change put the value of me into #st then put '' into #error">
<p class="help">noch mögliche Zeiträume:</p>
<div class="tags help">
<span class="tag">
01.01. 00:00 Uhr - 01.01. 10:00 Uhr
</span>
<span class="tag">
01.01. 20:00 Uhr - 02.01. 23:59 Uhr
</span>
</div>
</div>
<div class="field">
<input class="input" type="time" name="endtime" required value="20:00"
_='on change put the value of me into #et then put "" into #error
then if (value of the previous <input/>) is greater than (value of me)
then set the value of #enddate to "2025-01-02"
then put "Donnerstag, 02.01." into #ed
then set checked of #radionextday to true
end' />
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label">
<label class="label">Verfügbarkeitsende</label>
</div>
<div class="field-body">
<div class="field is-narrow">
<div class="control">
<label class="radio">
<input type="radio" name="isovernight" checked
_='on click set the value of #enddate to "2025-01-01"
then put "Mittwoch, 01.01." into #ed
then put "" into #error'>
am selben Tag
</label>
<label class="radio ml-3">
<input type="radio" id="radionextday" name="isovernight"
_='on click set the value of #enddate to "2025-01-02"
then put "Donnerstag, 02.01." into #ed
then put "" into #error'>
am Tag darauf
</label>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label">
<label class="label">Kommentar</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<textarea class="textarea" name="comment" placeholder="nur Posten, nur Wachhabender, etc.."></textarea>
</div>
<p class="help is-info">
<svg class="icon is-small">
<use href="/static/feather-sprite.svg#info" />
</svg>
verfügbar von Mittwoch, 01.01.
<span id="st">10:00</span>
Uhr bis
<span id="ed">Mittwoch, 01.01.</span>
<span id="et">20:00</span>
Uhr
</p>
<p id="error" class="help is-danger"></p>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label"></div>
<div class="field-body">
<div class="field is-grouped">
<div class="control">
<button class="button is-success" _="on click put '' into #error">
<svg class="icon">
<use href="/static/feather-sprite.svg#check-circle" />
</svg>
<span>Erstellen</span>
</button>
</div>
<div class="control">
<a class="button is-link is-light" hx-boost="true" href="/calendar?date=2025-01-01">
<svg class="icon">
<use href="/static/feather-sprite.svg#arrow-left" />
</svg>
<span>Zurück</span>
</a>
</div>
</div>
</div>
</div>
</form>
</div>
</section>

View File

@ -41,3 +41,33 @@ pub async fn get(
Ok(template.to_response()?)
}
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt, StatusCode,
};
use brass_db::models::{Availability, AvailabilityChangeset};
use brass_macros::db_test;
use chrono::NaiveDate;
#[db_test]
async fn produces_template_when_user_is_admin(context: &DbTestContext) {
let config = RequestConfig::new("/availability/new?date=2025-01-01");
create_test_login_user(&context.db_pool, &config).await;
let date = NaiveDate::from_ymd_opt(2025, 01, 01).unwrap();
let changeset = AvailabilityChangeset::create_for_test(&date, 10, 20);
Availability::create(&context.db_pool, 1, &changeset)
.await
.unwrap();
let response = test_get(context.app().await, &config).await;
let (status, body) = response.into_status_and_body().await;
assert_eq!(StatusCode::OK, status);
assert_snapshot!(body);
}
}

View File

@ -19,7 +19,12 @@ pub mod post_update;
pub mod put_cross_areal;
#[derive(Template)]
#[template(path = "availability/new_or_edit.html")]
#[cfg_attr(not(test), template(path = "availability/new_or_edit.html"))]
#[cfg_attr(
test,
template(path = "availability/new_or_edit.html", block = "content"),
allow(dead_code)
)]
struct NewOrEditAvailabilityTemplate<'a> {
user: User,
date: NaiveDate,