// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package presentation import ( "testing" "git.stormux.org/storm/cthulhu/internal/atspi" "git.stormux.org/storm/cthulhu/internal/config" ) func TestLibreOfficeCellValueCoordinatesAndDisplayedText(t *testing.T) { for _, value := range []string{"42", "", "é 猫"} { snapshot := atspi.Snapshot{Role: "table cell", Name: "B3", Text: value, ApplicationProcess: "soffice.bin", LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true, CellText: value, Coordinates: "B3"}} want := value + ", B3" if value == "" { want = "blank, B3" } if got := FocusText(snapshot); got != want { t.Fatalf("cell %q = %q, want %q", value, got, want) } reading := config.DefaultSettings().Reading reading.OnlySpeakDisplayedText = true options := DefaultOptions() options.Reading = &reading if got := FocusTextWithOptions(snapshot, options); got != value { t.Fatalf("displayed cell %q = %q", value, got) } if snapshot.Name != "B3" || snapshot.Text != value { t.Fatal("presentation mutated native semantics") } } } func TestLibreOfficePresentationRequiresVerifiedCellContext(t *testing.T) { for _, process := range []string{"", "chromium", "steamwebhelper"} { snapshot := atspi.Snapshot{Role: "table cell", Name: "B3", Text: "42", ApplicationProcess: process, LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true, CellText: "wrong", Coordinates: "wrong"}} if got := FocusText(snapshot); got != "B3, 42" { t.Fatalf("other process %q got LibreOffice policy: %q", process, got) } } } func TestLibreOfficeFormulaPresentation(t *testing.T) { for _, value := range []string{"43", ""} { snapshot := atspi.Snapshot{Role: "table cell", ApplicationProcess: "soffice.bin", LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true, Coordinates: "C1", CellText: value, Formula: "=B1+1"}} want := value + ", C1, has formula" if value == "" { want = "blank, C1, has formula" } if got := FocusText(snapshot); got != want { t.Fatalf("formula cell = %q, want %q", got, want) } if got := LibreOfficeFormulaText(snapshot); got != "=B1+1" { t.Fatalf("formula command = %q", got) } options := DefaultOptions() reading := config.DefaultSettings().Reading reading.OnlySpeakDisplayedText = true options.Reading = &reading if got := FocusTextWithOptions(snapshot, options); got != value { t.Fatalf("displayed text includes formula metadata: %q", got) } snapshot.LibreOffice.Formula = "" want = value if value == "" { want = "empty" } if got := LibreOfficeFormulaText(snapshot); got != want { t.Fatalf("non-formula command = %q, want %q", got, want) } } for _, snapshot := range []atspi.Snapshot{ {}, {Role: "paragraph", ApplicationProcess: "soffice.bin"}, {Role: "table cell", ApplicationProcess: "chromium", LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true, Formula: "wrong"}}, {Role: "table cell", Defunct: true, ApplicationProcess: "soffice.bin", LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true, Formula: "wrong"}}, } { if got := LibreOfficeFormulaText(snapshot); got != "Not in a table." { t.Fatalf("unverified cell = %q", got) } if got := LibreOfficeCellFormula(snapshot); got != "" { t.Fatalf("unverified formula = %q", got) } } }