Skip to content

refactor(chat.tsx): made a chat.utils and its related (unit) tests#48

Open
waqasshaukat wants to merge 2 commits intomainfrom
ws/agoric-chat-tests
Open

refactor(chat.tsx): made a chat.utils and its related (unit) tests#48
waqasshaukat wants to merge 2 commits intomainfrom
ws/agoric-chat-tests

Conversation

@waqasshaukat
Copy link
Contributor

@waqasshaukat waqasshaukat commented Dec 15, 2025

Extracted 8 pure utility functions from chat.tsx into a separate lib/chat-utils.ts module for improved testability and maintainability:
getApiBase - Determines API endpoint based on URL params
buildApiUrl - Constructs API URL with query parameters
decodeTitle - Safely decodes URL-encoded page titles
isLoadingState - Checks if chat is in loading state
parseMessageData - Safely parses JSON from message events
isOrbitChatSubmission - Type guard for ORBIT_CHAT messages
shouldSubmitCode - Validates code submission conditions
buildChatUrl - Builds chat navigation URLs
Added 35 unit tests covering all utility functions with edge cases.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 15, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ai ad63e63 Commit Preview URL

Branch Preview URL
Dec 15 2025, 08:44 AM

@waqasshaukat waqasshaukat changed the title refactor(chat.tsx): made a chat.utils and its related tests refactor(chat.tsx): made a chat.utils and its related (unit) tests Dec 15, 2025
@waqasshaukat waqasshaukat marked this pull request as ready for review December 15, 2025 08:58
Copy link
Contributor

@Muneeb147 Muneeb147 left a comment

Choose a reason for hiding this comment

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

Thanks for adding these.
I was curious if we had any GH issue or requirement for that? It's good to add tests but I'm curious about the way we are testing individual functions instead of the complete handler flow..

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