Artifact [63e66acffe]
Not logged in

Artifact 63e66acffe1dd3277545057da2f48bda640f0fd3e86bf693ddd66ecb4f43f0fd:


package web

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

	"craftdesign.group/quarry/internal/diff"
)

// TestWriteDiffTreeShot is a LOOKING aid: writes the changed-file tree
// for a fossil-sized check-in so it can be seen. Off unless
// QUARRY_SHOT names a file.
func TestWriteDiffTreeShot(t *testing.T) {
	out := os.Getenv("QUARRY_SHOT")
	if out == "" {
		t.Skip("QUARRY_SHOT unset")
	}
	var files []diff.FileDiff
	add := func(dir string, n int, kind diff.ChangeKind) {
		for i := 0; i < n; i++ {
			files = append(files, diff.FileDiff{
				Path:   fmt.Sprintf("%s/file%02d.c", dir, i),
				Change: kind,
			})
		}
	}
	if os.Getenv("QUARRY_SHOT_SMALL") != "" {
		// Under the collapse threshold: groups open, and one long
		// enough to go to columns.
		add("internal/web", 14, diff.Change)
		add("docs", 3, diff.Added)
		files = append(files, diff.FileDiff{Path: "README.md", Change: diff.Change})
	} else {
		add("src", 40, diff.Change)
		add("compat/zlib", 30, diff.Change)
		add("www/json-api", 20, diff.Added)
		add("test", 12, diff.Deleted)
		files = append(files, diff.FileDiff{Path: "README.md", Change: diff.Change})
	}

	d := diffDetail{Repo: "fossil", To: "62b3833204b8", Structured: files}
	var buf strings.Builder
	if err := noHooks.template(diffPage).Execute(&buf, pageData{Title: "Check-in", Repo: "fossil",
		Section: "timeline", Diff: d, SheetURL: "quarry.css"}); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"), []byte(sheet), 0o644); err != nil {
		t.Fatal(err)
	}
	t.Logf("ok: wrote %s", out)
}