Plugins can add pages to the sidebar, VM tabs, Settings and dialogs. Their pages can now use host forms and navigation, VM and settings access, authorized file I/O, task progress, controlled HTTP requests, events and private storage. Plugin pages cannot change allow_ai_access, which stays the user's per-VM consent. Closing a page cancels its unfinished tasks, and running plugin tasks no longer block changing the data folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestViewsRegisterSortFindAndDispose(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
manifest := Manifest{
|
|
Schema: 1, ID: "vendor.views", Version: "1.0.0", Name: LocalizedText{EnUS: "Views"},
|
|
Permissions: []string{"ui:slot"},
|
|
Contributes: Contributes{Views: []ViewContribution{
|
|
{ID: "z", Title: LocalizedText{EnUS: "Z"}, Location: "sidebar", Entry: "z.html", Order: 2},
|
|
{ID: "a", Title: LocalizedText{EnUS: "A"}, Location: "sidebar", Entry: "a.html", Order: 1},
|
|
{ID: "tab", Title: LocalizedText{EnUS: "Tab"}, Location: "vm.tab", Entry: "tab.html"},
|
|
}},
|
|
}
|
|
if err := reg.Register(PluginDef{Manifest: manifest, Source: SourceBuiltin, Desired: true}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reg.Reconcile(context.Background())
|
|
views := reg.Views("sidebar")
|
|
if len(views) != 2 || views[0].ID != "a" || views[1].ID != "z" {
|
|
t.Fatalf("sidebar views = %+v", views)
|
|
}
|
|
if view, ok := reg.View("vendor.views", "tab"); !ok || view.Location != "vm.tab" {
|
|
t.Fatalf("find tab: %+v, %v", view, ok)
|
|
}
|
|
if err := reg.SetDesired(context.Background(), "vendor.views", false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := reg.Views(""); len(got) != 0 {
|
|
t.Fatalf("views were not disposed: %+v", got)
|
|
}
|
|
if err := reg.SetDesired(context.Background(), "vendor.views", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := reg.Views(""); len(got) != 3 {
|
|
t.Fatalf("views were not restored: %+v", got)
|
|
}
|
|
ids := []string{reg.Views("")[0].ID, reg.Views("")[1].ID, reg.Views("")[2].ID}
|
|
if !reflect.DeepEqual(ids, []string{"tab", "a", "z"}) {
|
|
t.Fatalf("view order = %v", ids)
|
|
}
|
|
}
|