Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): improve hash parsing + setup unit test - WF-72 #655

Merged
merged 2 commits into from
Nov 29, 2024

Conversation

madeindjs
Copy link
Collaborator

It's possible to use URLSearchParams instead of complex Regex. As it's a very testable part of the code, it was a good opportunity to introduce Vitest and cover it.

This improvement made me realise that a bug was present, and we didn't serialize the params when converting back the object to hash (.key = length was not called).

@madeindjs madeindjs self-assigned this Nov 27, 2024
const { pageKey, routeVars } = parsedHash;

let hash = "";
if (pageKey) {
hash += `${encodeURIComponent(pageKey)}`;
}

if (routeVars.keys.length > 0) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a bug, since we need to use .size

> const map = new Map()
undefined
> map.keys.length
0
> map.set('a','b')
Map(1) { 'a' => 'b' }
> map.keys.length
0
> map.size
1

@madeindjs madeindjs changed the title chore(ui): improve hash parsing + test - WF-72 chore(ui): improve hash parsing + setup unit test - WF-72 Nov 28, 2024
@madeindjs madeindjs marked this pull request as ready for review November 28, 2024 08:31
@madeindjs madeindjs marked this pull request as draft November 28, 2024 08:55
It's possible to use `URLSearchParams` instead of complex Regex. As
it'sa very testable part of the code, it was a good opportunity to
introduceVitest and cover it.This improvement made me realise that a bug
was present, and we didn'tserialize the params when converting back the
object to hash (`.key =length` was not called).
@madeindjs madeindjs marked this pull request as ready for review November 28, 2024 09:17
@ramedina86 ramedina86 merged commit 66eaa60 into writer:dev Nov 29, 2024
16 checks passed
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