diff options
| author | chrislu <chris.lu@gmail.com> | 2024-07-03 17:40:55 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2024-07-03 17:40:55 -0700 |
| commit | 7c06306857feb2ef90452460735ad9c253c47f35 (patch) | |
| tree | 40ff63c6a7614683c7c650cc91bdcbdfae6e0f07 | |
| parent | 7ee1f520a4b1b200fa7ff71e9d22dff903ae59a4 (diff) | |
| download | seaweedfs-7c06306857feb2ef90452460735ad9c253c47f35.tar.xz seaweedfs-7c06306857feb2ef90452460735ad9c253c47f35.zip | |
fix breadcrumb
| -rw-r--r-- | weed/server/filer_ui/breadcrumb.go | 3 | ||||
| -rw-r--r-- | weed/server/filer_ui/breadcrumb_test.go | 74 |
2 files changed, 77 insertions, 0 deletions
diff --git a/weed/server/filer_ui/breadcrumb.go b/weed/server/filer_ui/breadcrumb.go index abb6cce9a..638638196 100644 --- a/weed/server/filer_ui/breadcrumb.go +++ b/weed/server/filer_ui/breadcrumb.go @@ -13,6 +13,9 @@ type Breadcrumb struct { func ToBreadcrumb(fullpath string) (crumbs []Breadcrumb) { parts := strings.Split(fullpath, "/") + if fullpath == "/" { + parts = []string{""} + } for i := 0; i < len(parts); i++ { name := parts[i] diff --git a/weed/server/filer_ui/breadcrumb_test.go b/weed/server/filer_ui/breadcrumb_test.go new file mode 100644 index 000000000..aac3c7de6 --- /dev/null +++ b/weed/server/filer_ui/breadcrumb_test.go @@ -0,0 +1,74 @@ +package filer_ui + +import ( + "reflect" + "testing" +) + +func TestToBreadcrumb(t *testing.T) { + type args struct { + fullpath string + } + tests := []struct { + name string + args args + wantCrumbs []Breadcrumb + }{ + { + name: "test1", + args: args{ + fullpath: "/", + }, + wantCrumbs: []Breadcrumb{ + { + Name: "/", + Link: "/", + }, + }, + }, + { + name: "test2", + args: args{ + fullpath: "/abc", + }, + wantCrumbs: []Breadcrumb{ + { + Name: "/", + Link: "/", + }, + { + Name: "abc", + Link: "/abc/", + }, + }, + }, + { + name: "test3", + args: args{ + fullpath: "/abc/def", + }, + wantCrumbs: []Breadcrumb{ + { + Name: "/", + Link: "/", + }, + { + Name: "abc", + Link: "/abc/", + }, + { + Name: "def", + Link: "/abc/def/", + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if gotCrumbs := ToBreadcrumb(tt.args.fullpath); !reflect.DeepEqual(gotCrumbs, tt.wantCrumbs) { + t.Errorf("ToBreadcrumb() = %v, want %v", gotCrumbs, tt.wantCrumbs) + } + }) + } +} |
