Skip to content

Conversation

@adnaan
Copy link
Contributor

@adnaan adnaan commented Jan 25, 2026

Summary

  • Add comprehensive E2E test for WebSocket CRUD operations with DOM verification

Dependencies

This PR depends on the following PRs being merged first:

After those PRs are merged and a new library version is published, this repo's go.mod will need to be updated to use the new version.

Test Details

TestProgressiveEnhancement_WebSocketCRUD validates:

  1. Initial page load shows 3 todos
  2. Adding a new todo increases count to 4
  3. Deleting the todo decreases count back to 3

This test verifies that the auto-generated keys feature works end-to-end, ensuring DOM updates correctly reflect server-side state changes.

Test plan

  • Test passes with local library changes (verified during development)

🤖 Generated with Claude Code

Adds TestProgressiveEnhancement_WebSocketCRUD that verifies add and delete
operations work correctly with DOM updates. This test validates that the
auto-generated keys feature works end-to-end.

Test sequence:
1. Navigate to page and count initial todos (3)
2. Add a new todo, verify count increases (4)
3. Delete the added todo, verify count returns to initial (3)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 25, 2026 11:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an end-to-end test (TestProgressiveEnhancement_WebSocketCRUD) to validate WebSocket-based CRUD operations with DOM verification in the progressive-enhancement example. The test ensures that adding and deleting todos via WebSocket correctly updates the DOM without page reloads, verifying the auto-generated range keys feature works correctly.

Changes:

  • Add comprehensive E2E test for WebSocket CRUD operations
  • Test validates initial todo count, add operation (count increases), and delete operation (count decreases back)
  • Includes DOM verification to ensure UI updates match server-side state changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 505 to 506
ctx, cancel = context.WithTimeout(ctx, 15*time.Second)
defer cancel()
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second context.WithTimeout at line 505 reassigns the cancel variable, which means the first cancel function created at line 502 will never be called. This creates a resource leak where the browser context won't be properly cleaned up.

The pattern used in other tests like TestProgressiveEnhancement_JSFormSubmission (lines 100-102) uses a separate variable name (timeoutCancel) for the timeout cancel function to avoid this issue.

Suggested change
ctx, cancel = context.WithTimeout(ctx, 15*time.Second)
defer cancel()
ctx, timeoutCancel := context.WithTimeout(ctx, 15*time.Second)
defer timeoutCancel()

Copilot uses AI. Check for mistakes.
err := chromedp.Run(ctx,
chromedp.Navigate(server.URL),
chromedp.WaitReady(`body`, chromedp.ByQuery),
chromedp.Sleep(1*time.Second), // Wait for WebSocket to connect
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using chromedp.Sleep with arbitrary durations (1 second) makes tests slower and potentially flaky. While chromedp.Sleep is used elsewhere in this file, other examples in the codebase (e.g., todos-components/todos_test.go:140 and todos/todos_test.go:177) use more robust patterns like e2etest.WaitFor with conditions to verify DOM changes have occurred.

Consider replacing the sleep with a condition-based wait, such as: e2etest.WaitFor to check when the WebSocket client is ready before performing operations. For DOM updates after form submissions, consider using e2etest.WaitFor with a condition that checks for the expected todo count change.

Copilot uses AI. Check for mistakes.
Comment on lines 512 to 522
// Step 1: Navigate and count initial todos
err := chromedp.Run(ctx,
chromedp.Navigate(server.URL),
chromedp.WaitReady(`body`, chromedp.ByQuery),
chromedp.Sleep(1*time.Second), // Wait for WebSocket to connect
chromedp.Evaluate(`document.querySelectorAll('.todo-item').length`, &initialCount),
)
if err != nil {
t.Fatalf("Step 1 (navigate) error: %v", err)
}
t.Logf("Initial todo count: %d", initialCount)
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test description says it validates "3 todos" initially, but it doesn't actually verify that initialCount equals 3. If the initial state changes (e.g., setupServer adds more or fewer todos), the test would still pass even though the assumptions documented in the PR description would be wrong.

Consider adding an explicit assertion like:
if initialCount != 3 {
t.Fatalf("Expected 3 initial todos, got %d", initialCount)
}

Copilot uses AI. Check for mistakes.
}
}

// TestProgressiveEnhancement_WebSocketCRUD tests add, toggle, and delete operations via WebSocket
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test comment states it tests "add, toggle, and delete operations" but the implementation only tests add and delete operations. There is no toggle operation being tested. Either the comment should be updated to match the actual test implementation, or a toggle test should be added to match the description.

Suggested change
// TestProgressiveEnhancement_WebSocketCRUD tests add, toggle, and delete operations via WebSocket
// TestProgressiveEnhancement_WebSocketCRUD tests add and delete operations via WebSocket

Copilot uses AI. Check for mistakes.
adnaan and others added 3 commits January 25, 2026 12:58
Expands TestProgressiveEnhancement_WebSocketCRUD to verify all operations:
1. Add new todo (count: 3 → 4)
2. Toggle to mark complete (verify .completed class added)
3. Toggle again to mark incomplete (verify .completed class removed)
4. Delete the todo (count: 4 → 3)

This comprehensive test validates that the auto-generated keys feature
correctly handles in-place updates, not just additions and deletions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Verifies that auto-generated keys work correctly after item deletion.
The test deletes one item and then toggles a different item to ensure
key-based DOM updates work correctly after range modifications.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix context cancel variable shadowing (use timeoutCancel)
- Replace chromedp.Sleep with e2etest.WaitFor for robust waiting
- Wait for WebSocket ready before operations
- Wait for DOM changes using condition-based waits

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@adnaan adnaan merged commit 0faa44f into main Jan 26, 2026
9 checks passed
@adnaan adnaan deleted the feat/auto-generated-range-keys branch January 26, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants