diff --git a/roles/web-app-nextcloud/files/playwright.spec.js b/roles/web-app-nextcloud/files/playwright.spec.js index a1870be687..7d15b0b751 100644 --- a/roles/web-app-nextcloud/files/playwright.spec.js +++ b/roles/web-app-nextcloud/files/playwright.spec.js @@ -521,29 +521,42 @@ const talkTestServerErrorPatterns = [ /Testing server seems to be broken/i ]; -// Positive success markers emitted by the spreed admin UI. The HPB signaling -// server and the recording backend both auto-run their reachability check on -// mount (HTTPS/WebSocket handshake) and render "OK: Running version: X" once -// it succeeds. TURN/STUN require WebRTC-level UDP connectivity from the -// browser to the coturn host, which is not guaranteed from a Playwright -// container in a separate docker network, so those are only covered by the -// error-absence assertion below, not by a positive marker here. The -// "OK: Running version:" pattern is expected to appear at least twice -// (signaling + recording) on a fully configured stack. -const talkTestServerRequiredSuccessPatterns = [ - { - label: "HPB signaling and recording backend versions", - pattern: /OK:\s*Running version:\s*\S+[\s\S]*?OK:\s*Running version:\s*\S+/i - } -]; +// Positive success marker emitted by the spreed admin UI. Both the HPB +// signaling-server row (SignalingServer.vue) and the recording-backend row +// (RecordingServer.vue) render their reachability result inline via +// `{{ connectionState }}`, where +// connectionState becomes `"OK: Running version: "` once the +// auto-mounted check (or our explicit Test-button click) succeeds. +// +// We require at least ONE successful row, not two: is +// `v-if="server && checked"` AND its parent only renders +// when `hasSignalingServers === true`, so the recording row can legitimately +// be absent on a stack that does not yet have an HPB signaling row stored +// (typical first-deploy ordering). Asserting two OK markers in that +// situation would false-fail on a healthy install. +const talkTestServerRequiredOkPattern = /OK:\s*Running version:\s*\S+/i; async function clickAllTalkTestServerButtonsAndVerify(page) { - // Spreed labels its signaling-server button "Test server" and the - // STUN/TURN entries "Test this server". Match both. + // Spreed renders the test result inside `` + // and the explicit re-test button (icon-only NcButton with + // aria-label "Test this server") is `v-if="server && checked"` — i.e. it + // only appears AFTER the auto-mount `checkServerVersion()` call returns, + // and at that point the connectionState text is already in the span. + // Wait for the result span to exist before measuring buttons so we do not + // race the conditional render and silently click zero buttons. + const connectionSpans = page.locator("span.test-connection"); + await connectionSpans + .first() + .waitFor({ state: "attached", timeout: 60_000 }) + .catch(() => { + // Continue — the assertion below will surface the real diagnostic. + }); + + // Re-trigger the check by clicking every Test button we can find. Spreed's + // accessible name (English) is "Test this server" for both HPB signaling + // and recording rows; older releases used "Test server", so match both. const testButtons = page.getByRole("button", { name: /^test( this)? server$/i }); const total = await testButtons.count(); - - const clicked = []; for (let i = 0; i < total; i += 1) { const button = testButtons.nth(i); if (!(await button.isVisible().catch(() => false))) { @@ -551,36 +564,38 @@ async function clickAllTalkTestServerButtonsAndVerify(page) { } await button.scrollIntoViewIfNeeded().catch(() => {}); await button.click({ timeout: 5_000 }).catch(() => {}); - clicked.push(i); } - expect( - clicked.length, - "Expected at least one Talk 'Test server' / 'Test this server' button on the admin page" - ).toBeGreaterThan(0); + // Read the test-connection span texts directly instead of `document.body + // .innerText`. innerText can omit content inside collapsed admin panels + // and the explicit locator surfaces the exact element where spreed writes + // the result, so failure messages name the actual rendered string. + const readConnectionTexts = async () => + connectionSpans.allInnerTexts().catch(() => []); - // Poll until every required success marker has rendered somewhere in the - // Talk admin panel. `page.evaluate(() => document.body.innerText)` is used - // instead of `page.locator("body").innerText()` because the latter triggers - // visibility checks that return empty on this admin layout. - const readBodyText = async () => - page.evaluate(() => document.body ? document.body.innerText : "").catch(() => ""); + await expect + .poll(readConnectionTexts, { + timeout: 60_000, + message: + "Expected at least one Talk admin row (.test-connection span) to render " + + "'OK: Running version: ' after the auto-check / Test-button click. " + + "Empty array means the row was never rendered (HPB signaling server " + + "config missing); a 'Status: Checking connection' value means the " + + "auto-check is still pending; an 'Error:' value means HPB unreachable." + }) + .toEqual(expect.arrayContaining([expect.stringMatching(talkTestServerRequiredOkPattern)])); - for (const { label, pattern } of talkTestServerRequiredSuccessPatterns) { - await expect - .poll(readBodyText, { - timeout: 30_000, - message: `Expected Talk admin page to report ${label} test success after clicking its Test button` - }) - .toMatch(pattern); - } - - const bodyText = await readBodyText(); - for (const pattern of talkTestServerErrorPatterns) { - expect( - bodyText, - `Talk admin page reported an error after clicking the Test server buttons (pattern ${pattern})` - ).not.toMatch(pattern); + // Then assert NONE of the rendered rows reports a known spreed error. + // Iterate connection-span texts so the failure message points at the + // exact row that broke instead of dumping the whole admin chrome. + const texts = await readConnectionTexts(); + for (const text of texts) { + for (const pattern of talkTestServerErrorPatterns) { + expect( + text, + `Talk admin row reported a connection error matching ${pattern}: ${text}` + ).not.toMatch(pattern); + } } }