package mapatest import ( "net/http" "net/url" "regexp" "slices" "strings" "testing" "amadan.net/oficina/notion.git/notiontest" ) // File is the first menu, as in Docs and Slides, and is ordered the Mac // way (level-up build note 87): New first, then the import, then what // the page allows, then the lists, and Delete… last, set apart. func TestFileIsTheFirstMenuInTheMacOrder(t *testing.T) { rig, _ := newImportRig(t, notiontest.NewWorkspace("empty")) acme := rig.createPage(t, Ana, "Acme", "One.") pinned := rig.createPage(t, Ana, "Pinned", "Two.") if answer := rig.post(t, Ana, pinned+"/pin", url.Values{"pin": {"1"}}); answer.Code != http.StatusSeeOther { t.Fatalf("pinning: %d", answer.Code) } scratch := rig.post(t, Ana, "/scratch", url.Values{"body": {"Mine."}}). Header().Get("Location") for _, check := range []struct { who, at string want []string }{ {Ana, acme, []string{"New team page", "New scratch page", "—", "Import from Notion…", "—", "Rename…", "Icon and banner…", "Link to a block…", "History", "Pin to sidebar", "—", "Deleted pages", "—", "Delete…"}}, {Bo, acme, []string{"New team page", "New scratch page", "—", "Rename…", "Icon and banner…", "Link to a block…", "History", "Pin to sidebar", "—", "Deleted pages", "—", "Delete…"}}, {Ana, pinned, []string{"New team page", "New scratch page", "—", "Import from Notion…", "—", "Rename…", "Icon and banner…", "Link to a block…", "History", "Unpin from sidebar", "—", "Deleted pages", "—", "Delete…"}}, {Ana, scratch, []string{"New team page", "New scratch page", "—", "Import from Notion…", "—", "Make team page…", "History", "Pin to sidebar", "—", "Deleted pages", "—", "Delete…"}}, {Ana, "/pages", []string{"New team page", "New scratch page", "—", "Import from Notion…", "—", "Deleted pages"}}, {Bo, "/pages", []string{"New team page", "New scratch page", "—", "Deleted pages"}}, } { page := rig.page(t, check.who, check.at) if first := between(page, "", "<"); first != "File" { t.Errorf("%s as %s: the first menu is %q", check.at, check.who, first) } if strings.Contains(page, `id="mapa-menu-page"`) { t.Errorf("%s as %s: a Page menu is still drawn", check.at, check.who) } if got := menuRows(fileMenuOf(page)); !slices.Equal(got, check.want) { t.Errorf("%s as %s: File is\n%q\nwant\n%q", check.at, check.who, got, check.want) } } } // menuRow is a menu's row label or its divider. var menuRow = regexp.MustCompile(`
|([^<]*)<`) // menuRows is a menu's rows in order, a divider as "—". func menuRows(menu string) []string { var rows []string for _, match := range menuRow.FindAllStringSubmatch(menu, -1) { if match[0] == "
" { rows = append(rows, "—") continue } rows = append(rows, match[1]) } return rows }