| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestRepositoryNavigationKeepsSelectedRef(t *testing.T) { |
| 9 | query := url.Values{"owner" : {"alice" }, "repo" : {"notes" }, "ref" : {"refs/heads/feature/x" }, "path" : {"src/lib/main.go" }, "offset" : {"50" }} |
| 10 | crumbs := repoBreadcrumbs(query) |
| 11 | if len(crumbs) != 4 || crumbs[2].Label != "lib" { |
| 12 | t.Fatalf("breadcrumbs = %#v" , crumbs) |
| 13 | } |
| 14 | for _, crumb := range crumbs[:3] { |
| 15 | link, err := url.Parse(crumb.URL) |
| 16 | if err != nil || link.Query().Get("ref" ) != query.Get("ref" ) || link.Query().Get("offset" ) != "" { |
| 17 | t.Fatalf("breadcrumb lost ref or kept page offset: %#v" , crumb) |
| 18 | } |
| 19 | } |
| 20 | link, _ := url.Parse(repoURL(query, "history" , "" )) |
| 21 | if link.Query().Get("ref" ) != query.Get("ref" ) || link.Query().Get("path" ) != "" { |
| 22 | t.Fatal("history navigation changed selected ref" ) |
| 23 | } |
| 24 | } |