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"])
	}
}
