Add nested posts UI (#5)
## Summary - Cut hunt, question, submission, voting, hiding, and profile flows over to unified posts - Render nested replies with permission-aware inline Reply/Edit controls and edited markers - Add post profile queries and the author index migration they depend on Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #5.
This commit is contained in:
@@ -258,6 +258,93 @@ func TestEditPostRoutePermissions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuestionPageRendersNestedPostControls(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
srv, mem := newTestServer(t, Config{})
|
||||
handler := srv.Handler()
|
||||
homeowner := seedUser(t, mem, uniq("homeowner"), "hunter22", store.RoleUser)
|
||||
admin := seedUser(t, mem, uniq("admin"), "hunter22", store.RoleAdmin)
|
||||
homeownerCookies := loginUser(t, handler, homeowner.Username, "hunter22")
|
||||
adminCookies := loginUser(t, handler, admin.Username, "hunter22")
|
||||
|
||||
root := &store.Post{
|
||||
AuthorID: homeowner.ID,
|
||||
Title: "Leaky sink",
|
||||
Body: "Water under the cabinet.",
|
||||
City: "Oakland",
|
||||
PostDate: pacific.Today(),
|
||||
}
|
||||
if err := mem.CreatePost(context.Background(), root); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
homeownerReply := &store.Post{
|
||||
ParentID: &root.ID,
|
||||
AuthorID: homeowner.ID,
|
||||
Body: "The model number is 123.",
|
||||
}
|
||||
if err := mem.CreatePost(context.Background(), homeownerReply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
adminReply := &store.Post{
|
||||
ParentID: &homeownerReply.ID,
|
||||
AuthorID: admin.ID,
|
||||
Body: "Replace the cartridge.",
|
||||
}
|
||||
if err := mem.CreatePost(context.Background(), adminReply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
homeownerReply.Body = "The model number is 123A."
|
||||
if err := mem.UpdatePost(context.Background(), homeownerReply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, "/questions/"+root.ID, nil)
|
||||
for _, cookie := range homeownerCookies {
|
||||
req.AddCookie(cookie)
|
||||
}
|
||||
handler.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("question page status = %d: %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
body := rec.Body.String()
|
||||
for _, want := range []string{
|
||||
`id="post-` + root.ID + `"`,
|
||||
`id="post-` + homeownerReply.ID + `"`,
|
||||
`id="post-` + adminReply.ID + `"`,
|
||||
`class="thread-post thread-post-branch`,
|
||||
`class="thread-post thread-post-deep is-shop"`,
|
||||
"Homeowner",
|
||||
"Shop response",
|
||||
"Edited",
|
||||
`action="/posts"`,
|
||||
`action="/posts/` + root.ID + `/edit"`,
|
||||
`action="/posts/` + homeownerReply.ID + `/edit"`,
|
||||
`>The model number is 123A.</textarea>`,
|
||||
`removeAttribute('open')`,
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("question page missing %q: %s", want, body)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, `action="/posts/`+adminReply.ID+`/edit"`) {
|
||||
t.Fatalf("homeowner can edit admin reply: %s", body)
|
||||
}
|
||||
|
||||
rec = httptest.NewRecorder()
|
||||
req = httptest.NewRequest(http.MethodGet, "/questions/"+root.ID, nil)
|
||||
for _, cookie := range adminCookies {
|
||||
req.AddCookie(cookie)
|
||||
}
|
||||
handler.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK ||
|
||||
!strings.Contains(rec.Body.String(), `action="/posts/`+adminReply.ID+`/edit"`) ||
|
||||
strings.Contains(rec.Body.String(), `action="/posts/`+root.ID+`/edit"`) {
|
||||
t.Fatalf("admin edit controls are incorrect: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func csrfForCookies(t *testing.T, handler http.Handler, cookies []*http.Cookie) string {
|
||||
t.Helper()
|
||||
req := httptest.NewRequest(http.MethodGet, "/submit", nil)
|
||||
|
||||
Reference in New Issue
Block a user