Skip to content

Commit

Permalink
content/static: add deprecated and retracted banners
Browse files Browse the repository at this point in the history
When a module is deprecated or retracted, add a banner to the main
page.

Test with an integration test to verify that the
deprecation/retraction information makes it through the entire
pipeline.

For golang/go#43265
For golang/go#41321

Change-Id: I0ffd1a9d1617e2865a10f0b0a8a8a3af6ed4d420
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/296815
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
  • Loading branch information
jba committed Feb 26, 2021
1 parent 4ae3818 commit e8cda2f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
15 changes: 13 additions & 2 deletions content/static/css/unit_header.css
Expand Up @@ -109,13 +109,24 @@
}

.UnitHeader-majorVersionBanner,
.UnitHeader-redirectedFromBanner {
background-color: var(--gray-10);
.UnitHeader-redirectedFromBanner,
.UnitHeader-deprecatedBanner,
.UnitHeader-retractedBanner {
display: flex;
margin: -0.5rem 0 1rem 0;
padding: 0.75rem 0;
}

.UnitHeader-majorVersionBanner,
.UnitHeader-redirectedFromBanner {
background-color: var(--gray-10);
}

.UnitHeader-deprecatedBanner,
.UnitHeader-retractedBanner {
background-color: var(--yellow);
}

.UnitHeader-detailIcon {
color: var(--gray-3);
flex-shrink: 0;
Expand Down
13 changes: 13 additions & 0 deletions content/static/html/helpers/_unit_header.tmpl
Expand Up @@ -46,6 +46,19 @@
</span>
</div>
{{end}}

{{if .Unit.Deprecated}}
<div class="UnitHeader-deprecatedBanner">
Deprecated{{with .Unit.DeprecationComment}}: {{.}}{{end}}
</div>
{{end}}

{{if .Unit.Retracted}}
<div class="UnitHeader-retractedBanner">
Retracted{{with .Unit.RetractionRationale}}: {{.}}{{end}}
</div>
{{end}}

{{if .LatestMajorVersion}}
<div class="UnitHeader-majorVersionBanner" data-test-id="UnitHeader-majorVersionBanner">
<img height="19px" width="16px" class="UnitHeader-detailIcon" src="/static/img/pkg-icon-info_19x16.svg" alt="">
Expand Down
32 changes: 22 additions & 10 deletions internal/testing/integration/integration_test.go
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/safehtml/template"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/experiment"
"golang.org/x/pkgsite/internal/godoc/dochtml"
"golang.org/x/pkgsite/internal/index"
"golang.org/x/pkgsite/internal/middleware"
Expand All @@ -39,6 +40,7 @@ func TestMain(m *testing.M) {
func TestEndToEndProcessing(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx = experiment.NewContext(ctx, internal.ExperimentRetractions)

defer postgres.ResetTestDB(testDB, t)

Expand Down Expand Up @@ -76,16 +78,20 @@ func TestEndToEndProcessing(t *testing.T) {
{"example.com/single", "This is the README"},
{"example.com/single/pkg", "hello"},
{"example.com/single@v1.0.0/pkg", "hello"},
{"example.com/deprecated", "UnitHeader-deprecatedBanner"},
{"example.com/retractions@v1.1.0", "UnitHeader-retractedBanner"},
} {
wantKeys = append(wantKeys, "/"+test.url)
body, err := doGet(frontendHTTP.URL + "/" + test.url)
if err != nil {
t.Fatalf("%s: %v", test.url, err)
}
if !strings.Contains(string(body), test.want) {
t.Errorf("%q not found in body", test.want)
t.Logf("%s", body)
}
t.Run(strings.ReplaceAll(test.url, "/", "_"), func(t *testing.T) {
wantKeys = append(wantKeys, "/"+test.url)
body, err := doGet(frontendHTTP.URL + "/" + test.url)
if err != nil {
t.Fatalf("%s: %v", test.url, err)
}
if !strings.Contains(string(body), test.want) {
t.Errorf("%q not found in body", test.want)
t.Logf("%s", body)
}
})
}

// Test cache invalidation.
Expand All @@ -105,8 +111,14 @@ func TestEndToEndProcessing(t *testing.T) {
}

// All the keys with modulePath should be gone, but the others should remain.
wantKeys = nil
// Remove modulePath from the previous keys.
for _, k := range keys {
if !strings.Contains(k, modulePath) {
wantKeys = append(wantKeys, k)
}
}
keys = cacheKeys(t, redisCacheClient)
wantKeys = []string{"/example.com/basic", "/example.com/basic@v1.0.0"}
if !cmp.Equal(keys, wantKeys) {
t.Errorf("cache keys: got %v, want %v", keys, wantKeys)
}
Expand Down

0 comments on commit e8cda2f

Please sign in to comment.