Files
mesh-catalog/modules/mesh-mail-web/internal/web/modes_test.go
T
jochen f554928ce1 issue 1859: modes by account, and the reading pane with its corrections; name a nameless sender (1859.4, 1850)
ADR 0515 §4, §5: the trusted setting modes names the accounts Work and Personal show, Everything shows every
granted account; /read shows one mail as escaped text with its tasks, promises and attachments as downloads,
records it opened, and offers its corrections (mark and group, not a task, not a promise, read later), each
calling correct. Issue 1850: a sender with no display name is named by its address, on the list, the pane and
All mail.
2026-10-22 20:09:29 +02:00

81 lines
3.1 KiB
Go

package web
// Issue 1859/AC2 (novox/hq ADR 0515 §4): Work and Personal each show the accounts the setting modes names
// for them; Everything shows every granted account.
import (
"os"
"path/filepath"
"strings"
"testing"
"time"
)
// 1859/AC2.
func TestAModeShowsItsOwnAccountsAlone(t *testing.T) {
list := fullList()
list["later"] = append(list["later"].([]any), line(11, "task 1", "task", "Pay the Hostco bill", "account", "personal"))
reading := &readingStandIn{list: list}
b := reading.bundle(time.Now())
path := filepath.Join(t.TempDir(), "modes.json")
if err := os.WriteFile(path, []byte(`{"modes": {"work": ["work"], "personal": ["personal"]}}`), 0o600); err != nil {
t.Fatal(err)
}
b.Env.Modes = path
s := NewServer(testHost, nil, b)
_, work, _ := get(t, s, "/?mode=work")
if !strings.Contains(work, "Plan the kick-off") || strings.Contains(work, "Pay the Hostco bill") {
t.Fatalf("Work shows another account's line, or not its own:\n%s", work)
}
_, personal, _ := get(t, s, "/?mode=personal")
if strings.Contains(personal, "Plan the kick-off") || !strings.Contains(personal, "Pay the Hostco bill") {
t.Fatalf("Personal shows another account's line, or not its own:\n%s", personal)
}
_, everything, _ := get(t, s, "/?mode=everything")
if !strings.Contains(everything, "Plan the kick-off") || !strings.Contains(everything, "Pay the Hostco bill") {
t.Fatalf("Everything does not show every account:\n%s", everything)
}
calls := reading.callsOf("list")
if len(calls) != 3 || calls[0].Args["mode"] != "work" || calls[2].Args["accounts"] != nil {
t.Fatalf("list asks %v, want work with its accounts, then personal, then everything with none named", calls)
}
if !strings.Contains(work, `class="mode on" aria-current="page">Work`) {
t.Fatalf("the page does not show Work as the mode it is in:\n%s", work)
}
}
// 1859/AC2: a mode the setting names no account for says so, and shows nothing of another mode.
func TestAModeTheSettingNamesNothingForSaysSo(t *testing.T) {
reading := &readingStandIn{list: fullList()}
b := reading.bundle(time.Now())
path := filepath.Join(t.TempDir(), "modes.json")
if err := os.WriteFile(path, []byte(`{"modes": {"work": ["work"]}}`), 0o600); err != nil {
t.Fatal(err)
}
b.Env.Modes = path
_, body, _ := get(t, NewServer(testHost, nil, b), "/?mode=personal")
if !strings.Contains(body, "names no account for Personal") || strings.Contains(body, "Plan the kick-off") {
t.Fatalf("an empty mode:\n%s", body)
}
if len(reading.callsOf("list")) != 0 {
t.Fatal("an empty mode asked list, which would answer every account")
}
}
// The setting is read as the module's own shape; anything else is refused, naming why.
func TestReadModesRefusesAnotherShape(t *testing.T) {
dir := t.TempDir()
for name, content := range map[string]string{
"unknown field": `{"modes": {}, "other": 1}`,
"unknown mode": `{"modes": {"holiday": ["a"]}}`,
"not names": `{"modes": {"work": [1]}}`,
} {
path := filepath.Join(dir, strings.ReplaceAll(name, " ", "-")+".json")
_ = os.WriteFile(path, []byte(content), 0o600)
if _, err := ReadModes(path); err == nil {
t.Errorf("%s: no error", name)
}
}
}