package integration_test
import (
"testing"
"time"
)
func TestNormalFlows(t *testing.T) {
h, err := NewHarness()
noErr(t, err)
defer h.Cleanup(t)
nw := newWord
t.Run("Can see recipes page when logged out", func(t *testing.T) {
p := h.b.MustPage(h.r.Idx).Timeout(5 * time.Second)
defer p.MustClose()
p.MustElementR("summary", "Navigate")
p.MustElementR("summary", "Search options")
p.MustNavigate(h.r.Recipes)
p.MustElementR("summary", "Navigate")
p.MustElementR("summary", "Search options")
})
t.Run("Admin can create recipes", func(t *testing.T) {
h.loginUser(h.admin)
p := h.b.MustPage(h.r.RecipeNew).Timeout(5 * time.Second)
defer p.MustClose()
// add recipe
tit, ing, ins, by, src := nw(8), nw(8), nw(8), nw(8), nw(8)
p.MustElement(`[name="title"]`).MustInput(tit)
p.MustElement(`[name="ingredients"]`).MustInput(ing)
p.MustElement(`[name="instructions"]`).MustInput(ins)
p.MustElement(`[name="by"]`).MustInput(by)
p.MustElement(`[name="source"]`).MustInput(src)
if !p.MustHas(`[name="groups"][value="1"][checked]`) {
p.MustElement(`[name="groups"][value="1"]`).MustClick()
}
p.MustElement(`[type="submit"]`).MustClick()
// check on recipe details page
p.MustElementR("h1", tit)
p.MustElementR("button", "🗑️")
p.MustElementR("a", "✏️")
p.MustElementR("h2", "Ingredients")
p.MustElementR("div", ing)
p.MustElementR("h2", "Instructions")
p.MustElementR("div", ins)
p.MustElementR("h2", "About")
p.MustElementR("div", by)
p.MustElementR("div", src)
// edit recipe
by2 := nw(8)
p.MustElementR("a", "✏️").MustClick()
p.MustElement(`[name="by"]`).MustInput(by2)
p.MustElement(`[type="submit"]`).MustClick()
// check on recipe details page with new and old info
p.MustElementR("h1", tit)
p.MustElementR("a", "✏️")
p.MustElementR("h2", "About")
p.MustElementR("div", by2)
// Find recipe on recipes listing page
p.MustNavigate(h.r.Idx)
p.MustElement(`[name="s"]`).MustInput(tit).MustBlur()
p.WaitRequestIdle(300*time.Millisecond, nil, nil, nil)
p.MustElementR("li", tit).MustElementR("a", "More").MustClick()
// check on recipe details page
p.MustElementR("h1", tit)
p.MustElementR("a", "✏️")
})
t.Run("Private recipes are searchable by owner", func(t *testing.T) {
h.loginUser(h.admin)
p := h.b.MustPage(h.r.RecipeNew).Timeout(5 * time.Second)
defer p.MustClose()
// add recipe
tit, ing, ins, by, src := nw(8), nw(8), nw(8), nw(8), nw(8)
p.MustElement(`[name="title"]`).MustInput(tit)
p.MustElement(`[name="ingredients"]`).MustInput(ing)
p.MustElement(`[name="instructions"]`).MustInput(ins)
p.MustElement(`[name="by"]`).MustInput(by)
p.MustElement(`[name="source"]`).MustInput(src)
if p.MustHas(`[name="groups"][value="1"][checked]`) {
p.MustElement(`[name="groups"][value="1"][checked]`).MustClick()
}
p.MustElement(`[type="submit"]`).MustClick()
// check on recipe details page
p.MustElementR("h1", tit)
p.MustElementR("button", "🗑️")
p.MustElementR("a", "✏️")
// Find recipe on recipes listing page
p.MustNavigate(h.r.Idx)
p.MustElement(`[name="s"]`).MustInput(tit).MustBlur()
p.WaitRequestIdle(300*time.Millisecond, nil, nil, nil)
p.MustElementR("li", tit).MustElementR("a", "More").MustClick()
// check on recipe details page
p.MustElementR("h1", tit)
p.MustElementR("a", "✏️")
})
h.CleanupSuccess(t)
}