package callstest import ( "net/http" "regexp" "strings" "testing" "time" ) func TestHoldingPageShowsTitleStandingAndFloor(t *testing.T) { x, sqid, _ := memberWithMeeting(t) c := x.browser(t) c.signIn("paul@example.com") rec := c.get("/m/" + sqid + "/join") body := rec.Body.String() for _, want := range []string{"Board meeting", "You’ll join as paul.", "Calls outside your network may not connect yet.", `rst-tone="warning"`, "End meeting for everyone"} { if !strings.Contains(body, want) { t.Errorf("holding page lacks %q", want) } } } // A meeting that exists, a person who is signed in, and no standing // toward it. The earlier version of this test asked for a meeting that // did not exist, so it passed before standingFor was ever called // (review C1-8). func TestHoldingPageIs404ForNoStanding(t *testing.T) { x, first, tok := memberWithMeeting(t) // A signed-in non-member: an outsider who followed the first // meeting's link, so they hold a grant for that meeting and none // for any other. g := x.browser(t) g.get("/j/" + tok) if dest := g.signIn("guest@example.com"); dest != "/m/"+first+"/join" { t.Fatalf("outsider landed on %s", dest) } member := x.browser(t) member.signIn("paul@example.com") second, _ := createMeeting(t, member, "A meeting they were not invited to", "") if rec := g.get("/m/" + second + "/join"); rec.Code != http.StatusNotFound { t.Fatalf("a real meeting with no grant: %d, want 404", rec.Code) } // And the meeting they do hold a grant for, once it has run out. x.advance(2*time.Hour + time.Minute) if rec := g.get("/m/" + first + "/join"); rec.Code != http.StatusNotFound { t.Fatalf("a real meeting with an expired grant: %d, want 404", rec.Code) } } // Fix round 1, Important 12: once this session already holds a peer in // the room, the holding page points at the takeover confirm page rather // than offering a plain join that would collide with it. func TestHoldingPageOffersTakeoverWhenThisSessionIsAlreadyInTheRoom(t *testing.T) { x, sqid, _ := memberWithMeeting(t) m := x.browser(t) m.signIn("paul@example.com") if rec := m.get("/m/" + sqid + "/join"); strings.Contains(rec.Body.String(), "already open in another tab") { t.Fatal("holding page offers takeover before any stream is open") } s := m.stream("/m/" + sqid + "/stream") defer s.close() s.hello() rec := m.get("/m/" + sqid + "/join") body := rec.Body.String() if !strings.Contains(body, "already open in another tab") || !strings.Contains(body, "/m/"+sqid+"/takeover") { t.Fatalf("holding page lacks the takeover offer once a peer is live: %s", body) } // devices.js's own join button must not offer a fresh stream that // would 409: once this session already has a peer here, the // #devices block's join target is the takeover confirm page, not // the room. if !strings.Contains(body, `data-join-href="/m/`+sqid+`/takeover"`) { t.Fatalf("holding page's join target should switch to takeover once a peer is live: %s", body) } } // Task 7: devices.js takes over the region the slice-1 placeholder // held. The script tag lives in (the room page's own pattern, // and the CSP's default-src 'self' wants no inline script), the // #devices block still carries the sqid the script reads, and its // default join target is the room itself — not the takeover page, // which is only for a session that already has a peer here (the next // test). func TestHoldingPageHasDevicesScriptAndNoLegacyPlaceholder(t *testing.T) { x, sqid, _ := memberWithMeeting(t) c := x.browser(t) c.signIn("paul@example.com") rec := c.get("/m/" + sqid + "/join") body := rec.Body.String() headEnd := strings.Index(body, "") // asset() fingerprints the filename (static/devices..js), so // the literal "devices.js" never appears — match the stable prefix, // as room_test.go does for calls.css. script := strings.Index(body, "/static/devices.") if headEnd < 0 || script < 0 || script > headEnd { t.Fatalf("devices.js is not inside : head ends at %d, script at %d\n%s", headEnd, script, body) } if !strings.Contains(body, `id="devices" data-sqid="`+sqid+`"`) { t.Fatalf("holding page lacks the devices block's data-sqid: %s", body) } if !strings.Contains(body, `data-join-href="/m/`+sqid+`"`) { t.Fatalf("holding page's default join target should be the room: %s", body) } if !strings.Contains(body, "