Repository navigation
fix(booking): cap the host face stack so it cannot spill into the calendar (#166) #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package handler_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // The info panel is 240px wide with 1.5rem padding (192px of content). Each face | ||
| // is 56px and the stack overlaps by 16px, so six hosts is 256px — it spilled into | ||
| // the calendar column (#166). The page must draw at most three faces plus a "+N" | ||
| // chip, matching the label which already names only three hosts. | ||
| func TestBookPageCapsHostFacesAtThree(t *testing.T) { | ||
| h, database, key, ownerID := setupWorkspaceWithDB(t) | ||
| slug, _ := seedEventTypeHTTP(t, h, key) | ||
|
|
||
| parts := []string{ | ||
| fmt.Sprintf(`{"user_id":%q,"role":"required","priority":0}`, ownerID), | ||
| } | ||
| for i := 2; i <= 6; i++ { | ||
| hostID := fmt.Sprintf("u%d", i) | ||
| if _, err := database.Exec( | ||
| `INSERT INTO users (id,email,name,iana_timezone,is_admin) VALUES (?,?,?, 'UTC',0)`, | ||
| hostID, hostID+"@example.com", "Host "+hostID); err != nil { | ||
| t.Fatalf("seed %s: %v", hostID, err) | ||
| } | ||
| parts = append(parts, fmt.Sprintf(`{"user_id":%q,"role":"required","priority":%d}`, hostID, i-1)) | ||
| } | ||
| if rec := putHosts(t, h, slug, key, `{"hosts":[`+strings.Join(parts, ",")+`]}`); rec.Code != http.StatusOK { | ||
| t.Fatalf("set hosts: %d — %s", rec.Code, rec.Body.String()) | ||
| } | ||
|
|
||
| req := httptest.NewRequest(http.MethodGet, "/book/"+slug, nil) | ||
| req.SetPathValue("slug", slug) | ||
| rec := httptest.NewRecorder() | ||
| h.BookPage(rec, req) | ||
| if rec.Code != http.StatusOK { | ||
| t.Fatalf("book page: %d", rec.Code) | ||
| } | ||
|
|
||
| block := hostFacesBlock(t, rec.Body.String()) | ||
| if got := strings.Count(block, `class="face"`); got != 3 { | ||
| t.Errorf("rendered %d avatar faces; want 3", got) | ||
| } | ||
| if !strings.Contains(block, `class="face face-more"`) { | ||
| t.Error("missing the \"+N\" overflow chip for 6 hosts") | ||
| } | ||
| if !strings.Contains(block, ">+3</span>") { | ||
| t.Error("overflow chip should read +3 for 6 hosts") | ||
| } | ||
| } | ||
|
|
||
| // hostFacesBlock returns the rendered #host-faces element only — the page's inline | ||
| // script contains the same class names in template literals. | ||
| func hostFacesBlock(t *testing.T, page string) string { | ||
| t.Helper() | ||
| start := strings.Index(page, `id="host-faces"`) | ||
| if start < 0 { | ||
| t.Fatal("no #host-faces element in rendered page") | ||
| } | ||
| end := strings.Index(page[start:], "</div>") | ||
| if end < 0 { | ||
| t.Fatal("unterminated #host-faces element") | ||
| } | ||
| return page[start : start+end] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| // mkHosts builds n placeholder faces. | ||
| func mkHosts(n int) []hostDisplay { | ||
| out := make([]hostDisplay, n) | ||
| for i := range out { | ||
| name := string(rune('A' + i)) | ||
| out[i] = hostDisplay{Name: name, Initial: name, Z: (n - i) * 10} | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func TestCapHostFaces(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| n int | ||
| wantFaces int | ||
| wantOverflow int | ||
| }{ | ||
| {"none", 0, 0, 0}, | ||
| {"single", 1, 1, 0}, | ||
| {"at the limit", maxHostFaces, maxHostFaces, 0}, | ||
| {"one over", maxHostFaces + 1, maxHostFaces, 1}, | ||
| {"six hosts (issue #166)", 6, maxHostFaces, 3}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| hosts := mkHosts(tc.n) | ||
| if got := capHostFaces(hosts, maxHostFaces); len(got) != tc.wantFaces { | ||
| t.Errorf("capHostFaces len = %d; want %d", len(got), tc.wantFaces) | ||
| } | ||
| if got := hostsOverflow(hosts, maxHostFaces); got != tc.wantOverflow { | ||
| t.Errorf("hostsOverflow = %d; want %d", got, tc.wantOverflow) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.face-moreis fixed at 56px, but the embed widget's compact container query (@container (max-width:719px),embed.js:142) shrinks.info .avatar-img/.avatar-initialsto 46px and has no.face-moreoverride. At that breakpoint the chip renders 10px larger than the faces beside it and extends below their baseline, so the stack looks off on mobile embeds.Technical details