- Updated publicOfficeSessionRequest to include a new DisplayName field. - Modified PublicEditorConfig to accept and utilize the display name for editor configuration. - Implemented editorLabelPath function to determine the correct file name for single-file public shares. - Added unit tests for editor label path and build editor config functionalities.
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package office
|
|
|
|
import "testing"
|
|
|
|
func TestEditorLabelPath(t *testing.T) {
|
|
t.Parallel()
|
|
tests := []struct {
|
|
filePath string
|
|
displayName string
|
|
want string
|
|
}{
|
|
{filePath: "/docs/report.xlsx", displayName: "", want: "/docs/report.xlsx"},
|
|
{filePath: "/docs/report.xlsx", displayName: "other.docx", want: "/docs/report.xlsx"},
|
|
{filePath: "/", displayName: "testtable.xlsx", want: "testtable.xlsx"},
|
|
{filePath: "/", displayName: "", want: "/"},
|
|
}
|
|
for _, tc := range tests {
|
|
got := editorLabelPath(tc.filePath, tc.displayName)
|
|
if got != tc.want {
|
|
t.Errorf("editorLabelPath(%q, %q) = %q, want %q", tc.filePath, tc.displayName, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildEditorConfigSingleFileShareSpreadsheet(t *testing.T) {
|
|
t.Parallel()
|
|
cfg, err := buildEditorConfig(buildEditorConfigInput{
|
|
filePath: "/",
|
|
displayName: "testtable.xlsx",
|
|
mode: "edit",
|
|
documentKey: "key",
|
|
downloadURL: "http://example/doc",
|
|
callbackURL: "http://example/cb",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("buildEditorConfig: %v", err)
|
|
}
|
|
if cfg["documentType"] != "cell" {
|
|
t.Fatalf("documentType = %v, want cell", cfg["documentType"])
|
|
}
|
|
doc, ok := cfg["document"].(map[string]any)
|
|
if !ok {
|
|
t.Fatalf("document missing")
|
|
}
|
|
if doc["fileType"] != "xlsx" {
|
|
t.Fatalf("fileType = %v, want xlsx", doc["fileType"])
|
|
}
|
|
if doc["title"] != "testtable.xlsx" {
|
|
t.Fatalf("title = %v, want testtable.xlsx", doc["title"])
|
|
}
|
|
}
|