package idtest // Every route and state of the sign-in door, standalone and with Home. import ( "html" "net/http" "net/url" "regexp" "strings" "testing" ) func TestDoorRoutesAndStates(t *testing.T) { t.Parallel() modes(t, func(t *testing.T, f *fixture, home bool) { for _, c := range []struct { path, title string oficina bool // offers Continue with Oficina ID, as the one way or a row has []string }{ {"/signin", "Sign in to Equipo", home, nil}, {"/signin?return_to=%2Fwork", "Sign in to Equipo", home, nil}, {"/signin?ways=1", "Other ways to sign in to Equipo", false, nil}, {"/signin?way=email", "Sign in to Equipo", false, []string{`name="address"`}}, {"/signin?err=expired", "Problem signing in to Equipo", false, []string{`name="address"`}}, {"/signin?force=1", "Sign in to Equipo", false, []string{`name="address"`}}, {"/signin?sent=1", "Check your email to sign in to Equipo", false, nil}, {"/signin?reauth=1", "Sign in to Equipo", false, nil}, } { w := f.request("GET", c.path, "", nil) body := w.Body.String() if w.Code != http.StatusOK || title(body) != c.title { t.Errorf("%s: %d %q, want 200 %q", c.path, w.Code, title(body), c.title) } if got := strings.Contains(body, `href="/signin/oficina`); got != c.oficina { t.Errorf("%s: Continue with Oficina ID %v, want %v", c.path, got, c.oficina) } for _, want := range c.has { if !strings.Contains(body, want) { t.Errorf("%s: missing %s", c.path, want) } } if !regexp.MustCompile(`src="/static/rastrillo\.[0-9a-f]+\.js">\n