Use viewport width for adaptive layout

This commit is contained in:
Joe Julian
2026-04-08 23:49:07 -07:00
parent b256a77d0c
commit 07a071503a
6 changed files with 115 additions and 39 deletions
+61
View File
@@ -1334,6 +1334,67 @@ func TestUIPhoneBackClosesSettingsDialog(t *testing.T) {
}
}
func TestUIWidePhoneViewportUsesDesktopLayout(t *testing.T) {
t.Parallel()
u := newUIWithModel("phone", vault.Model{
Entries: []vault.Entry{{ID: "entry-1", Title: "Vault Console"}},
})
u.state.ShowSection(appstate.SectionEntries)
u.updateViewportLayoutMode(layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(1200, 900)),
Metric: unit.Metric{PxPerDp: 1, PxPerSp: 1},
})
if u.usesCompactViewport() {
t.Fatal("usesCompactViewport() = true, want false for wide phone viewport")
}
if !u.shouldShowDesktopWorkingHeader() {
t.Fatal("shouldShowDesktopWorkingHeader() = false, want true for wide phone viewport")
}
}
func TestUINarrowDesktopViewportUsesCompactLayout(t *testing.T) {
t.Parallel()
u := newUIWithModel("desktop", vault.Model{
Entries: []vault.Entry{{ID: "entry-1", Title: "Vault Console"}},
})
u.state.ShowSection(appstate.SectionEntries)
u.updateViewportLayoutMode(layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(540, 900)),
Metric: unit.Metric{PxPerDp: 1, PxPerSp: 1},
})
if !u.usesCompactViewport() {
t.Fatal("usesCompactViewport() = false, want true for narrow desktop viewport")
}
if u.shouldShowDesktopWorkingHeader() {
t.Fatal("shouldShowDesktopWorkingHeader() = true, want false for narrow desktop viewport")
}
}
func TestUIWidePhoneViewportKeepsAndroidBackBehavior(t *testing.T) {
t.Parallel()
u := newUIWithModel("phone", vault.Model{})
u.securityDialogOpen = true
u.updateViewportLayoutMode(layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(1200, 900)),
Metric: unit.Metric{PxPerDp: 1, PxPerSp: 1},
})
if !u.handlePhoneBack() {
t.Fatal("handlePhoneBack() = false, want true for wide phone viewport")
}
if u.securityDialogOpen {
t.Fatal("securityDialogOpen = true after back, want false")
}
}
func TestUISecurityDialogContentDoesNotPanicWithSmallViewport(t *testing.T) {
t.Parallel()