content,internal: check latest minor version in tests
Previously, UnitHeader was not validating that the header had the
correct latest minor version. This check is now added and tests are
updated accordingly.
Change-Id: Ia46914a38c71a74130d5b5801b03539ad67a4c83
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/277692
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/content/static/html/helpers/_unit_header.tmpl b/content/static/html/helpers/_unit_header.tmpl
index 33b8955..6170fc8 100644
--- a/content/static/html/helpers/_unit_header.tmpl
+++ b/content/static/html/helpers/_unit_header.tmpl
@@ -42,19 +42,26 @@
The highest tagged major version is <a href="/$$GODISCOVERY_LATESTMAJORVERSIONURL$$">$$GODISCOVERY_LATESTMAJORVERSION$$</a>.
</span>
</div>
+
<div class="js-fixedHeaderSentinel"></div>
{{if (eq .SelectedTab.Name "")}}
<div class="UnitHeader-detail">
+
<span class="UnitHeader-detailItem" data-test-id="UnitHeader-version">
<img class="UnitHeader-detailItemLarge" height="16px" width="16px" src="/static/img/pkg-icon-arrowBranch_16x16.svg" alt="">
<a href="?tab=versions">Version {{.DisplayVersion}}</a>
<!-- Do not reformat the data attributes of the following div: the server uses a regexp to extract them. -->
<div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$"
- data-version="{{.LinkVersion}}" data-mpath="{{.Unit.ModulePath}}" data-ppath="{{.Unit.Path}}" data-pagetype="{{.PageType}}">
+ data-test-id="UnitHeader-minorVersionBanner"
+ data-version="{{.LinkVersion}}"
+ data-mpath="{{.Unit.ModulePath}}"
+ data-ppath="{{.Unit.Path}}"
+ data-pagetype="{{.PageType}}">
<span>Latest</span>
<a href="{{.LatestURL}}">Go to latest</a>
</div>
</span>
+
<span class="UnitHeader-detailItem" data-test-id="UnitHeader-commitTime">
<img height="16px" width="16px" src="/static/img/pkg-icon-circularArrows_16x16.svg" alt="">
{{.Details.CommitTime}}
diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go
index 3c1c14d..5f22c09 100644
--- a/internal/frontend/server_test.go
+++ b/internal/frontend/server_test.go
@@ -325,7 +325,7 @@
Suffix: sample.Suffix,
IsLatestMinor: true,
IsLatestMajor: true,
- LatestLink: "/" + sample.ModulePath + "@" + sample.VersionString + "/" + sample.Suffix,
+ LatestLink: "/" + sample.ModulePath + "/" + sample.Suffix,
LatestMajorVersionLink: "/" + sample.ModulePath + "/" + sample.Suffix,
LicenseType: sample.LicenseType,
LicenseFilePath: sample.LicenseFilePath,
@@ -341,7 +341,7 @@
Suffix: "bar",
IsLatestMinor: true,
IsLatestMajor: false,
- LatestLink: "/github.com/v2major/module_name@v1.0.0/bar",
+ LatestLink: "/github.com/v2major/module_name/bar",
LatestMajorVersion: "v2",
LatestMajorVersionLink: "/github.com/v2major/module_name/v2/bar",
LicenseType: sample.LicenseType,
@@ -355,7 +355,7 @@
v2pkgV1Buz.Suffix = "buz"
v2pkgV1Buz.IsLatestMajor = false
v2pkgV1Buz.IsLatestMinor = true
- v2pkgV1Buz.LatestLink = "/github.com/v2major/module_name@v1.0.0/buz"
+ v2pkgV1Buz.LatestLink = "/github.com/v2major/module_name/buz"
v2pkgV1Buz.LatestMajorVersionLink = "/github.com/v2major/module_name/v2"
v2pkgV1Buz.PackageURLFormat = "/github.com/v2major/module_name%s/buz"
@@ -367,7 +367,7 @@
Suffix: "bar",
IsLatestMinor: true,
IsLatestMajor: true,
- LatestLink: "/github.com/v2major/module_name/v2@v2.0.0/bar",
+ LatestLink: "/github.com/v2major/module_name/v2/bar",
LatestMajorVersion: "v2",
LatestMajorVersionLink: "/github.com/v2major/module_name/v2/bar",
LicenseType: sample.LicenseType,
@@ -398,7 +398,7 @@
Suffix: "dir/inc",
IsLatestMinor: true,
IsLatestMajor: true,
- LatestLink: "/github.com/incompatible@v1.0.0+incompatible/dir/inc",
+ LatestLink: "/github.com/incompatible/dir/inc",
LatestMajorVersionLink: "/github.com/incompatible/dir/inc",
LicenseType: "MIT",
LicenseFilePath: "LICENSE",
@@ -414,7 +414,7 @@
Suffix: "bar",
IsLatestMinor: true,
IsLatestMajor: true,
- LatestLink: "/github.com/non_redistributable@v1.0.0/bar",
+ LatestLink: "/github.com/non_redistributable/bar",
LatestMajorVersionLink: "/github.com/non_redistributable/bar",
LicenseType: "",
PackageURLFormat: "/github.com/non_redistributable%s/bar",
@@ -434,6 +434,7 @@
ModuleURL: "/" + sample.ModulePath,
PackageURLFormat: "/" + sample.ModulePath + "%s/foo/directory",
LatestMajorVersionLink: "/github.com/valid/module_name/foo/directory",
+ LatestLink: "/github.com/valid/module_name/foo/directory",
}
mod := &pagecheck.Page{
@@ -459,7 +460,7 @@
ModulePath: "github.com/pseudo",
Title: "dir/",
ModuleURL: "/github.com/pseudo",
- LatestLink: "/github.com/pseudo@" + pseudoVersion + "/dir",
+ LatestLink: "/github.com/pseudo/dir",
LatestMajorVersionLink: "/github.com/pseudo/dir",
Suffix: "dir",
Version: pseudoVersion,
@@ -482,6 +483,7 @@
IsLatestMajor: true,
IsLatestMinor: true,
ModuleURL: "/std",
+ LatestLink: "/cmd",
PackageURLFormat: "/cmd%s",
LatestMajorVersionLink: "/cmd",
}
@@ -497,7 +499,7 @@
PackageURLFormat: "/net/http%s",
IsLatestMinor: true,
IsLatestMajor: true,
- LatestLink: "/net/http@go1.13",
+ LatestLink: "/net/http",
LatestMajorVersionLink: "/net/http",
}
diff --git a/internal/testing/pagecheck/pagecheck.go b/internal/testing/pagecheck/pagecheck.go
index 802e740..f456750 100644
--- a/internal/testing/pagecheck/pagecheck.go
+++ b/internal/testing/pagecheck/pagecheck.go
@@ -142,6 +142,7 @@
}
return in("header.UnitHeader",
+ versionBadge(p),
in(`[data-test-id="UnitHeader-breadcrumbCurrent"]`, text(curBreadcrumb)),
in(`[data-test-id="UnitHeader-title"]`, text(p.Title)),
in(`[data-test-id="UnitHeader-majorVersionBanner"]`,
@@ -235,7 +236,7 @@
} else {
class += "--goToLatest"
}
- return in("div.DetailsHeader-badge",
+ return in(`[data-test-id="UnitHeader-minorVersionBanner"]`,
attr("class", `\b`+regexp.QuoteMeta(class)+`\b`), // the badge has this class too
in("a", href(p.LatestLink), exactText("Go to latest")))
}