Skip to content
quarry Artifact [20d5ec6077]
Login

Artifact [20d5ec6077]

Artifact 20d5ec6077bd770d8a949357b0a75d4722557b3fc6d6e0ff00bd323a94cb710b:


package web

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

// The repository listing, which is where a repository's own mark was
// missing: every other named thing on the forge carried one.
func TestWriteFleetShot(t *testing.T) {
	out := os.Getenv("QUARRY_SHOT_FLEET")
	if out == "" {
		t.Skip("QUARRY_SHOT_FLEET unset")
	}
	if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
		[]byte(sheet), 0o644); err != nil {
		t.Fatal(err)
	}
	rows := []repoInfo{
		{Name: "quarry", Description: "a forge front-end for zit", Checkins: 1642,
			Contributors: 4, LastActive: "2026-09-14T12:00:00Z"},
		{Name: "zit", Description: "the version control system underneath", Checkins: 903,
			Contributors: 3, LastActive: "2026-09-13T18:00:00Z"},
		{Name: "orchard", Description: "small tools that grew here", Checkins: 71,
			Contributors: 1, LastActive: "2026-09-02T09:00:00Z"},
	}
	var buf strings.Builder
	if err := explorePage.Execute(&buf, pageData{Title: "Home", SheetURL: "quarry.css",
		Fleet: rows, FleetTotal: len(rows), Served: len(rows)}); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
		t.Fatal(err)
	}
}

// Every repository in the listing carries its own mark, and the mark
// is the same identicon every other named thing on the forge gets.
func TestTheRepositoryListingCarriesAMarkPerRepository(t *testing.T) {
	rows := []repoInfo{{Name: "quarry"}, {Name: "zit"}, {Name: "orchard"}}
	var buf strings.Builder
	if err := explorePage.Execute(&buf, pageData{Title: "Home",
		Fleet: rows, FleetTotal: len(rows), Served: len(rows)}); err != nil {
		t.Fatal(err)
	}
	body := buf.String()
	if n := strings.Count(body, `class="r-mark"`); n != len(rows) {
		t.Errorf("FAIL: %d marks for %d repositories", n, len(rows))
	}
	// Each one is that repository's own, not a shared glyph: the
	// identicon is derived from the name, so two rows must differ.
	for _, r := range rows {
		if !strings.Contains(body, string(repoIcon(r.Name))) {
			t.Errorf("FAIL: %s does not carry its own mark", r.Name)
		}
	}
	// The folder glyph a DIRECTORY listing uses is gone from the row:
	// a repository and a folder looked alike, two clicks apart.
	if strings.Contains(body, `class="ic t-glyph" aria-hidden="true"><use href="#i-dir"`) {
		t.Errorf("FAIL: a repository row still wears the directory glyph")
	}
}

// One seam, so an uploaded avatar later is one change rather than a
// listing somebody forgets.
func TestARepositoryMarkComesFromOneFunction(t *testing.T) {
	// "zit", because quarry's repository carries a built-in mark and is
	// the one name this would not answer for.
	if repoIcon("zit") != identicon("zit") {
		t.Errorf("FAIL: repoIcon no longer renders what it says it renders")
	}
}