74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
package dyzurbot
|
||
|
||
import (
|
||
"testing"
|
||
"time"
|
||
)
|
||
|
||
// rows mirrors the real "Dyżury" sheet: cols A–C are the duty schedule,
|
||
// cols E–F are the person roster, with UNFORMATTED_VALUE rendering the
|
||
// week date and duty count as float64 and trailing empty cells dropped.
|
||
func sampleRows() [][]interface{} {
|
||
return [][]interface{}{
|
||
// row 0: header — must be skipped
|
||
{"Tydzień zaczynający się od", "Osoba 1", "Osoba 2", "", "Lista osób", "Liczba dyżurów"},
|
||
// full week + roster entry
|
||
{float64(46027), "Jan Kowalski", "Anna Nowak", "", "Piotr Wiśniewski", float64(1)},
|
||
// empty week (no one assigned) + roster entry
|
||
{float64(46034), "", "", "", "Maria Wójcik", float64(0)},
|
||
// one-person week, ragged row (no roster columns at all)
|
||
{float64(46041), "Tomasz Zieliński"},
|
||
// week present, blank roster slot with a count -> person skipped
|
||
{float64(46048), "", "", "", "", float64(0)},
|
||
// roster-only row (week column empty) -> person added, no week
|
||
{"", "", "", "", "Katarzyna Lewandowska", float64(3)},
|
||
}
|
||
}
|
||
|
||
func TestParseRotaSkipsHeaderAndCountsWeeks(t *testing.T) {
|
||
rota := ParseRota(sampleRows())
|
||
|
||
// rows 1..4 carry a week serial; row 5's week column is empty
|
||
if got := len(rota.Weeks); got != 4 {
|
||
t.Fatalf("weeks: got %d, want 4", got)
|
||
}
|
||
}
|
||
|
||
func TestParseRotaDecodesWeekStartToMonday(t *testing.T) {
|
||
rota := ParseRota(sampleRows())
|
||
|
||
want := time.Date(2026, 1, 5, 0, 0, 0, 0, time.UTC) // serial 46027 = Mon 2026-01-05
|
||
if got := rota.Weeks[0].WeekStart; !got.Equal(want) {
|
||
t.Errorf("week0 start: got %v, want %v", got, want)
|
||
}
|
||
}
|
||
|
||
func TestParseRotaWeekPersons(t *testing.T) {
|
||
rota := ParseRota(sampleRows())
|
||
|
||
if w := rota.Weeks[0]; w.Person1 != "Jan Kowalski" || w.Person2 != "Anna Nowak" {
|
||
t.Errorf("full week persons: got %q/%q", w.Person1, w.Person2)
|
||
}
|
||
if w := rota.Weeks[1]; w.Person1 != "" || w.Person2 != "" {
|
||
t.Errorf("empty week should keep blank persons: got %q/%q", w.Person1, w.Person2)
|
||
}
|
||
if w := rota.Weeks[2]; w.Person1 != "Tomasz Zieliński" || w.Person2 != "" {
|
||
t.Errorf("one-person ragged week: got %q/%q", w.Person1, w.Person2)
|
||
}
|
||
}
|
||
|
||
func TestParseRotaRosterSkipsBlankSlots(t *testing.T) {
|
||
rota := ParseRota(sampleRows())
|
||
|
||
// Piotr Wiśniewski, Maria Wójcik, Katarzyna Lewandowska — the blank-name slot is skipped
|
||
if got := len(rota.People); got != 3 {
|
||
t.Fatalf("people: got %d, want 3", got)
|
||
}
|
||
if p := rota.People[0]; p.Name != "Piotr Wiśniewski" || p.DutyCount != 1 {
|
||
t.Errorf("person0: got %+v, want {Piotr Wiśniewski 1}", p)
|
||
}
|
||
if p := rota.People[2]; p.Name != "Katarzyna Lewandowska" || p.DutyCount != 3 {
|
||
t.Errorf("person2: got %+v, want {Katarzyna Lewandowska 3}", p)
|
||
}
|
||
}
|