Skip to content
quarry Artifact [c570d219fb]
Login

Artifact [c570d219fb]

Artifact c570d219fbbec699149ba6588b15179c07c2317b3d96bbeadabf46e91ecd02db:


package web

import (
	"html/template"
	"os"
	"path/filepath"
	"strings"
	"testing"
)

// The new-repository form, which had no fixture and therefore no way to
// be looked at without a running forge and a session. It was the one
// page never given a phone pass: a bare <fieldset> takes the UA's
// min-inline-size: min-content, and two size="52" inputs held it at
// 491px inside a 390px viewport with nothing to scroll.
func TestWriteNewRepoShot(t *testing.T) {
	out := os.Getenv("QUARRY_SHOT_NEWREPO")
	if out == "" {
		t.Skip("QUARRY_SHOT_NEWREPO unset")
	}
	if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
		[]byte(sheet), 0o644); err != nil {
		t.Fatal(err)
	}
	var buf strings.Builder
	// Narrow is what renderStatus stamps for this template; the
	// fixture says so itself rather than rendering a page nobody is
	// served.
	if err := newRepoPage.Execute(&buf, pageData{
		Title: "New repository", SheetURL: "quarry.css", Narrow: true}); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
		t.Fatal(err)
	}
}

// The form fits a phone. Asserted on the one rule that makes it
// possible rather than on a screenshot: a <fieldset> takes the UA's
// min-inline-size: min-content, which is what held this form 491px
// wide inside a 390px viewport. Without it back to 0, no width the
// inputs are given can shrink the box.
func TestNewRepoFormCanShrink(t *testing.T) {
	if !strings.Contains(sheet, ".newrepo-form fieldset{min-inline-size:0") &&
		!strings.Contains(sheet, ".newrepo-form fieldset { min-inline-size: 0") {
		t.Errorf("FAIL: the Contents fieldset can still refuse to shrink")
	}
	var buf strings.Builder
	if err := newRepoPage.Execute(&buf, pageData{Title: "New repository"}); err != nil {
		t.Fatal(err)
	}
	// The URL and its interval are one wrapping row, not a line that
	// squeezes both.
	if !strings.Contains(buf.String(), `class="clone-row"`) {
		t.Errorf("FAIL: the clone row is not a row")
	}
	// The column is a form's width, answered by the template and not
	// by whichever handler happened to render it.
	for _, p := range []*template.Template{newRepoPage, loginPage, invitePage} {
		if !narrowPages[p] {
			t.Errorf("FAIL: a one-form page lost its narrow column")
		}
	}
}