Skip to content

Commit 85a61ef

Browse files
aerosolzoldar
andauthored
Bugfix: Enter on team creation form should submit, not crash (#6153)
* fix * Revert "fix" This reverts commit 24c1b0d. * Reapply "fix" This reverts commit 98298f3. * Test * Remove unused import * await lv * err * Fix e2e regressiont test --------- Co-authored-by: Adrian Gruntkowski <github@todo.computer>
1 parent 0121fc9 commit 85a61ef

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { test, expect } from '@playwright/test'
2+
import { setupSite } from '../fixtures'
3+
import { expectLiveViewConnected } from '../test-utils'
4+
5+
test('submitting team name via Enter key does not crash', async ({
6+
page,
7+
request
8+
}) => {
9+
await setupSite({ page, request })
10+
await page.goto('/team/setup')
11+
12+
await expectLiveViewConnected(page)
13+
14+
await expect(page.getByRole('button', { name: 'Create Team' })).toBeVisible()
15+
16+
const nameInput = page.locator('input[name="team[name]"]')
17+
18+
await nameInput.clear()
19+
await nameInput.fill('My New Team')
20+
21+
await nameInput.press('Enter')
22+
23+
await expect(nameInput).toHaveValue('My New Team')
24+
25+
// the form had no phx-submit handler and plain HTTP POST fallback was made
26+
await page.getByRole('button', { name: 'Create Team' }).click()
27+
28+
await expect(page).toHaveURL(/\/settings\/team\/general/)
29+
30+
await expectLiveViewConnected(page)
31+
32+
const nameInput2 = page.locator('input[name="team[name]"]')
33+
34+
await expect(nameInput2).toHaveValue('My New Team')
35+
})

e2e/tests/test-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import type { Locator, Page } from '@playwright/test'
22
import { expect } from '@playwright/test'
33

44
export async function expectLiveViewConnected(page: Page) {
5-
return expect(page.locator('.phx-connected')).toHaveCount(1)
5+
await expect
6+
.poll(() => page.locator('.phx-connected').count())
7+
.toBeGreaterThan(0)
68
}
79

810
export function randomID() {

lib/plausible_web/live/team_setup.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ defmodule PlausibleWeb.Live.TeamSetup do
8484
for={@team_name_form}
8585
method="post"
8686
phx-change="update-team"
87+
phx-submit="update-team"
8788
phx-blur="update-team"
8889
id="update-team-form"
8990
class="mt-4 mb-8"

0 commit comments

Comments
 (0)