Skip to content
quarry Artifact [7e2d330b47]
Login

Artifact [7e2d330b47]

Artifact 7e2d330b47dc1be5ef8a8ed162068625a2203c2b61aabf2c9bca690095aca811:


package web

import (
	"os"
	"regexp"
	"strings"
	"testing"
)

// A table that stacks on a phone hides its header and labels its cells.
//
// The phone rules turned .caps-table, its tbody and its td into
// blocks and left THEAD out of the list. A thead still in table
// layout inside a blocked-out table renders as one bold heading per
// column, above the whole table: /me's Access section showed
// "Repository" and "You are" as two headings stacked over the rows,
// with no column under either.
//
// So the header goes, and the cells say what they are through the
// data-lbl mechanism the sheet already had. Any caps-table with a
// thead needs a label on every cell, or a stacked row is values with
// nothing naming them.
func fileSource(t *testing.T, name string) string {
	t.Helper()
	b, err := os.ReadFile(name)
	if err != nil {
		t.Fatal(err)
	}
	return string(b)
}

func TestAStackedTableHidesItsHeaderAndLabelsItsCells(t *testing.T) {
	if !strings.Contains(styleSource, ".set-body .caps-table thead { display: none; }") {
		t.Error("FAIL: the stacked table keeps its header row, which renders as one " +
			"heading per column above the table")
	}
	src := webSource(t) + fileSource(t, "prefs.go")
	for _, tbl := range regexp.MustCompile(`(?s)<table class="caps-table[^"]*">.*?</table>`).FindAllString(src, -1) {
		if !strings.Contains(tbl, "<thead>") {
			continue
		}
		heads := len(regexp.MustCompile(`<th\b`).FindAllString(tbl, -1))
		// One row is enough to check: every row of a table has the same
		// cells, so the first tells us whether they are labelled.
		row := regexp.MustCompile(`(?s)<tbody>.*?</tr>`).FindString(tbl)
		lbls := len(regexp.MustCompile(`data-lbl=`).FindAllString(row, -1))
		if lbls < heads {
			t.Errorf("FAIL: a caps-table has %d columns and %d labelled cells; once the "+
				"rows stack the unlabelled ones are values with nothing naming them", heads, lbls)
		}
	}
}

// And a mark's inset is its own geometry, not a share of whatever it
// sits in.
//
// .idn-mark carried padding: 12%, and percentage padding resolves
// against the CONTAINING BLOCK's width. In a narrow table cell that
// was about 2px. Once the cell became a full-width block at phone
// width it was about 43px a side, which swamped the 14px box and left
// the glyph invisible with the name shoved across the row. The inset
// belongs in the viewBox, where nothing outside can move it.
func TestAMarksInsetDoesNotDependOnWhatItSitsIn(t *testing.T) {
	if regexp.MustCompile(`\.idn-mark[^}]*padding:\s*\d+%`).MatchString(styleSource) {
		t.Error("FAIL: .idn-mark takes a percentage padding, which is a share of its " +
			"container's width and not of its own box; put the inset in the viewBox")
	}
	for name, mark := range builtinMark {
		if !strings.Contains(string(mark), "viewBox=\"-") {
			t.Errorf("FAIL: the %q mark has no margin in its viewBox, so it will sit "+
				"edge to edge where an identicon does not", name)
		}
	}
}