spec: show birthdays until a week out
This commit is contained in:
parent
4f141b01c3
commit
c12975926d
4 changed files with 65 additions and 44 deletions
|
|
@ -43,3 +43,41 @@ test('sidebar is sorted alphabetically', async ({ page }) => {
|
||||||
|
|
||||||
await expect(page.getByRole('navigation')).toHaveText(/Alfa\s*Golf\s*Zulu/);
|
await expect(page.getByRole('navigation')).toHaveText(/Alfa\s*Golf\s*Zulu/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('upcoming and recent show at least one birthday a week away', async ({ page }) => {
|
||||||
|
const monthday = d => d.toISOString().split("T")[0].replace(/^\d{4}-/, '');
|
||||||
|
const today = monthday(new Date());
|
||||||
|
const yesterday = monthday((() => {
|
||||||
|
let date = new Date();
|
||||||
|
date.setDate(date.getDate() - 1);
|
||||||
|
return date;
|
||||||
|
})());
|
||||||
|
const tomorrow = monthday((() => {
|
||||||
|
let date = new Date();
|
||||||
|
date.setDate(date.getDate() + 1);
|
||||||
|
return date;
|
||||||
|
})());
|
||||||
|
const aMonthAgo = monthday((() => {
|
||||||
|
let date = new Date();
|
||||||
|
date.setDate(date.getDate() - 28);
|
||||||
|
return date;
|
||||||
|
})());
|
||||||
|
const inAMonth = monthday((() => {
|
||||||
|
let date = new Date();
|
||||||
|
date.setDate(date.getDate() + 28);
|
||||||
|
return date;
|
||||||
|
})());
|
||||||
|
await verifyCreateUser(page, { names: ['Alfa'], birthday: today });
|
||||||
|
await verifyCreateUser(page, { names: ['Beta'], birthday: yesterday });
|
||||||
|
await verifyCreateUser(page, { names: ['Echo'], birthday: today });
|
||||||
|
await verifyCreateUser(page, { names: ['Golf'], birthday: yesterday });
|
||||||
|
await verifyCreateUser(page, { names: ['Lima'], birthday: tomorrow });
|
||||||
|
await verifyCreateUser(page, { names: ['Mike'], birthday: yesterday });
|
||||||
|
await verifyCreateUser(page, { names: ['Xray'], birthday: inAMonth });
|
||||||
|
await verifyCreateUser(page, { names: ['Zulu'], birthday: aMonthAgo });
|
||||||
|
|
||||||
|
await page.goto('/');
|
||||||
|
|
||||||
|
await expect(page.locator('#upcoming').getByRole('link')).toHaveCount(4);
|
||||||
|
await expect(page.locator('#recent').getByRole('link')).toHaveCount(4);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,10 @@ pub enum Birthday {
|
||||||
|
|
||||||
impl Display for Birthday {
|
impl Display for Birthday {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
let str = match self {
|
match self {
|
||||||
Birthday::Date(date) => date.to_string(),
|
Birthday::Date(date) => write!(f, "{}", date),
|
||||||
Birthday::Text(t) => t.value.clone(),
|
Birthday::Text(t) => write!(f, "{}", t.value),
|
||||||
};
|
}
|
||||||
write!(f, "{}", str)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,13 +55,6 @@ impl Birthday {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize(&self) -> String {
|
|
||||||
match &self {
|
|
||||||
Birthday::Text(text) => text.value.clone(),
|
|
||||||
Birthday::Date(date) => date.serialize(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Birthday {
|
impl FromStr for Birthday {
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,6 @@ impl YearOptionalDate {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize(&self) -> String {
|
|
||||||
format!(
|
|
||||||
"{}{:0>2}{:0>2}",
|
|
||||||
self.year.map_or("--".to_string(), |y| format!("{:0>4}", y)),
|
|
||||||
self.month,
|
|
||||||
self.day
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for YearOptionalDate {
|
impl Display for YearOptionalDate {
|
||||||
|
|
@ -110,6 +101,6 @@ where
|
||||||
&self,
|
&self,
|
||||||
buf: &mut <Sqlite as Database>::ArgumentBuffer<'r>,
|
buf: &mut <Sqlite as Database>::ArgumentBuffer<'r>,
|
||||||
) -> Result<IsNull, Box<dyn std::error::Error + Sync + Send>> {
|
) -> Result<IsNull, Box<dyn std::error::Error + Sync + Send>> {
|
||||||
<String as Encode<'r, Sqlite>>::encode(self.serialize(), buf)
|
<String as Encode<'r, Sqlite>>::encode(self.to_string(), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ fn birthdays_section(
|
||||||
div id="birthdays" {
|
div id="birthdays" {
|
||||||
h2 { "Birthdays" }
|
h2 { "Birthdays" }
|
||||||
#birthday-sections {
|
#birthday-sections {
|
||||||
.datelist {
|
.datelist #upcoming {
|
||||||
h3 { "upcoming" }
|
h3 { "upcoming" }
|
||||||
@for contact in &upcoming_birthdays[0..std::cmp::min(3, upcoming_birthdays.len())] {
|
@for contact in &upcoming_birthdays[0..std::cmp::min(3, upcoming_birthdays.len())] {
|
||||||
a href=(format!("/contact/{}", contact.contact_id)) {
|
a href=(format!("/contact/{}", contact.contact_id)) {
|
||||||
|
|
@ -68,7 +68,7 @@ fn birthdays_section(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.datelist {
|
.datelist #recent {
|
||||||
h3 { "recent" }
|
h3 { "recent" }
|
||||||
@for contact in &prev_birthdays[0..std::cmp::min(3, prev_birthdays.len())] {
|
@for contact in &prev_birthdays[0..std::cmp::min(3, prev_birthdays.len())] {
|
||||||
a href=(format!("/contact/{}", contact.contact_id)) {
|
a href=(format!("/contact/{}", contact.contact_id)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue