refactor: reduce cyclomatic complexity in template tests
This commit is contained in:
@@ -33,7 +33,12 @@ func TestManifestIconDimensions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, icon := range manifest.Icons {
|
for _, icon := range manifest.Icons {
|
||||||
t.Run(icon.Sizes, func(t *testing.T) {
|
t.Run(icon.Sizes, checkManifestIcon(icon))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkManifestIcon(icon manifestIcon) func(*testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
width, height := parseIconSize(t, icon.Sizes)
|
width, height := parseIconSize(t, icon.Sizes)
|
||||||
assetURL, err := url.Parse(icon.Src)
|
assetURL, err := url.Parse(icon.Src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -56,7 +61,6 @@ func TestManifestIconDimensions(t *testing.T) {
|
|||||||
if config.Width != width || config.Height != height {
|
if config.Width != width || config.Height != height {
|
||||||
t.Fatalf("icon dimensions = %dx%d, manifest declares %s", config.Width, config.Height, icon.Sizes)
|
t.Fatalf("icon dimensions = %dx%d, manifest declares %s", config.Width, config.Height, icon.Sizes)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ func TestRenderUsesPurposeSizedBrandAssets(t *testing.T) {
|
|||||||
t.Fatalf("parse rendered html: %v", err)
|
t.Fatalf("parse rendered html: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertBrandAssetLinks(t, doc)
|
||||||
|
assertNavigationLogo(t, doc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertBrandAssetLinks(t *testing.T, doc *goquery.Document) {
|
||||||
assets := map[string]string{
|
assets := map[string]string{
|
||||||
`link[rel="manifest"]`: "/static/assets/manifest.json",
|
`link[rel="manifest"]`: "/static/assets/manifest.json",
|
||||||
`link[rel="icon"][sizes="32x32"]`: "/static/assets/favicon-32.png",
|
`link[rel="icon"][sizes="32x32"]`: "/static/assets/favicon-32.png",
|
||||||
@@ -94,7 +99,9 @@ func TestRenderUsesPurposeSizedBrandAssets(t *testing.T) {
|
|||||||
t.Fatalf("%s href = %q, want %q", selector, path, want)
|
t.Fatalf("%s href = %q, want %q", selector, path, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertNavigationLogo(t *testing.T, doc *goquery.Document) {
|
||||||
logo := doc.Find(`a[title="Home"] img`)
|
logo := doc.Find(`a[title="Home"] img`)
|
||||||
if logo.Length() != 1 {
|
if logo.Length() != 1 {
|
||||||
t.Fatalf("navigation logo count = %d, want 1", logo.Length())
|
t.Fatalf("navigation logo count = %d, want 1", logo.Length())
|
||||||
|
|||||||
Reference in New Issue
Block a user