Skip to content

test: add HTML-to-JSX tests#626

Open
ankit20012006 wants to merge 2 commits intoBashamega:mainfrom
ankit20012006:html-jsx-tests
Open

test: add HTML-to-JSX tests#626
ankit20012006 wants to merge 2 commits intoBashamega:mainfrom
ankit20012006:html-jsx-tests

Conversation

@ankit20012006
Copy link
Copy Markdown

@ankit20012006 ankit20012006 commented Apr 10, 2026

Description

This PR adds test cases for the HTML-to-JSX conversion module.

  • Added Jest tests for conversion logic
  • Covered attribute transformation and nested elements
  • Ensured correct JSX output

This PR focuses only on the HTML-to-JSX module for better review.

Summary by CodeRabbit

  • New Features

    • Resume form now supports pre-filled initial data for seamless form population.
  • Tests

    • Added comprehensive test suites for HTML-to-JSX conversion and resume builder components.
  • Documentation

    • Updated README with instructions for running tests and generating coverage reports.
  • Refactor

    • Improved caching mechanism and centralized form data synchronization logic.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

@ankit20012006 is attempting to deploy a commit to the bashamega's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

This PR adds comprehensive Jest test suites for HTML-to-JSX and resume builder components, refactors the ResumeForm component to accept initial data and centralize state updates, extracts resume default data into a separate module, replaces cache state with a mutable ref in the HTML-JSX converter page, and extends README with test execution instructions.

Changes

Cohort / File(s) Summary
Documentation
README.md
Extended setup instructions with steps to run test suite and generate coverage report.
HTML-to-JSX Tests
__tests__/convert/html-jsx/htmlToJsx.test.js, __tests__/convert/html-jsx/page.test.jsx
Added test suites validating HTML attribute conversion (class to className), boolean attributes, self-closing tags, editor interactions, localStorage-based theme persistence, and conversion triggering.
Resume Builder Tests
__tests__/resume-builder/Preview.test.jsx, __tests__/resume-builder/ResumeForm.test.jsx
Added test suites verifying Preview component rendering of resume data and ResumeForm user interactions including field updates, array operations, and callback invocations.
HTML-JSX Converter
src/app/convert/html-jsx/page.jsx
Replaced React state-based cache with useRef mutable cache to avoid state updates during JSX generation.
Resume Builder Core
src/app/resume-builder/defaultResumeData.js, src/app/resume-builder/ResumeForm.jsx, src/app/resume-builder/page.jsx
Created defaultResumeData module, updated ResumeForm to accept initialData prop with centralized state update helper, and refactored page.jsx to use extracted defaults and pass initial data to form.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • Implement Jest Tests for HTML to jsx #396: The added Jest test suites for htmlToJsx transformer and its page component directly address the "Implement Jest Tests for HTML to jsx" requirement, providing coverage for conversion logic and editor interactions.

Poem

🐰 Tests bloom bright, defaultResumeData springs to life,
Refs replace state, no re-render strife!
Forms now listen, initial states take their flight,
Cache optimized, HTML to JSX shines so bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'test: add HTML-to-JSX tests' accurately reflects the primary objective of adding test cases for the HTML-to-JSX conversion module, which aligns with the commit message and PR summary.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/app/resume-builder/ResumeForm.jsx (2)

108-119: Consider removing or uncommenting the disabled addSkill functionality.

These commented-out blocks (here and lines 589-598) create noise. If the feature is planned, a TODO comment explaining intent would be clearer; otherwise, consider removing the dead code since it can be recovered from version control.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/resume-builder/ResumeForm.jsx` around lines 108 - 119, The
commented-out addSkill block is dead code and should be either removed or
restored with intent: either delete the commented addSkill (and the similar
block at lines ~589-598) to eliminate noise, or uncomment and reintroduce the
function (ensure you export/use addSkill where needed and it correctly calls
setFormData with formData.skills to add the default categories) and add a
single-line TODO comment above it explaining planned behavior; reference the
addSkill identifier and setFormData/formData.skills so you update the right code
paths.

10-14: Guard against unintended resets from reference changes.

If the parent component re-creates initialData on each render (e.g., inline object or computed value without memoization), every render will trigger this effect and overwrite user edits. Consider deep-comparing or expecting the parent to memoize initialData.

Additionally, if initialData becomes undefined after previously being set, local state won't revert to defaultResumeData.

💡 Possible approach: add a controlled vs uncontrolled mode
 useEffect(() => {
-  if (initialData) {
+  // Only sync on mount or when explicitly reset by parent
+  // Consider using a separate `resetKey` prop if reset behavior is needed
+  if (initialData && !hasUserEdited) {
     setFormData(initialData);
   }
 }, [initialData]);

Alternatively, document that initialData must be memoized by the parent or implement a comparison check.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/resume-builder/ResumeForm.jsx` around lines 10 - 14, The effect that
sets local state from initialData (useEffect that calls
setFormData(initialData)) currently overwrites user edits whenever the parent
provides a new object reference; change it to only update when initialData is
meaningfully different or when initializing: in the useEffect surrounding
setFormData, add a guard that (a) returns early if initialData is undefined, (b)
compares initialData against current formData with a deep-equality check (e.g.,
lodash/isEqual or JSON.stringify) and only calls setFormData when they differ,
and (c) optionally use a ref like hasInitialized to allow a one-time
initialization and reset to defaultResumeData if initialData becomes explicitly
undefined — update the effect that references initialData, setFormData,
formData, defaultResumeData, and add the hasInitialized ref and isEqual import
as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/app/convert/html-jsx/page.jsx`:
- Line 11: The current cacheRef uses a plain object (const cacheRef =
useRef({})) which allows inherited-property collisions (e.g., "toString") when
reading cacheRef.current[value]; replace it with a Map by initializing cacheRef
= useRef(new Map()) and update all accesses in this file (the cache get/set
calls around the conversion logic referenced as cacheRef.current[value] on lines
~27-33) to use cacheRef.current.get(value) and cacheRef.current.set(value,
result) so keys are treated safely and no inherited properties can be returned.

---

Nitpick comments:
In `@src/app/resume-builder/ResumeForm.jsx`:
- Around line 108-119: The commented-out addSkill block is dead code and should
be either removed or restored with intent: either delete the commented addSkill
(and the similar block at lines ~589-598) to eliminate noise, or uncomment and
reintroduce the function (ensure you export/use addSkill where needed and it
correctly calls setFormData with formData.skills to add the default categories)
and add a single-line TODO comment above it explaining planned behavior;
reference the addSkill identifier and setFormData/formData.skills so you update
the right code paths.
- Around line 10-14: The effect that sets local state from initialData
(useEffect that calls setFormData(initialData)) currently overwrites user edits
whenever the parent provides a new object reference; change it to only update
when initialData is meaningfully different or when initializing: in the
useEffect surrounding setFormData, add a guard that (a) returns early if
initialData is undefined, (b) compares initialData against current formData with
a deep-equality check (e.g., lodash/isEqual or JSON.stringify) and only calls
setFormData when they differ, and (c) optionally use a ref like hasInitialized
to allow a one-time initialization and reset to defaultResumeData if initialData
becomes explicitly undefined — update the effect that references initialData,
setFormData, formData, defaultResumeData, and add the hasInitialized ref and
isEqual import as needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 428dcaa4-33b8-457c-88a2-a4485de44f0c

📥 Commits

Reviewing files that changed from the base of the PR and between 5f5187a and 306021b.

📒 Files selected for processing (9)
  • README.md
  • __tests__/convert/html-jsx/htmlToJsx.test.js
  • __tests__/convert/html-jsx/page.test.jsx
  • __tests__/resume-builder/Preview.test.jsx
  • __tests__/resume-builder/ResumeForm.test.jsx
  • src/app/convert/html-jsx/page.jsx
  • src/app/resume-builder/ResumeForm.jsx
  • src/app/resume-builder/defaultResumeData.js
  • src/app/resume-builder/page.jsx

const [isDarkMode, setIsDarkMode] = useState(false);
const [value, setValue] = useState("");
const [cache, setCache] = useState({});
const cacheRef = useRef({});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use Map for cache keys to avoid inherited-property collisions.

At Line 27, cacheRef.current[value] can read inherited object properties (e.g., "toString"), returning non-JSX data and breaking conversion. This is user-input-driven and should be hardened.

🔧 Proposed fix
-  const cacheRef = useRef({});
+  const cacheRef = useRef(new Map());

   // Generate JSX from HTML with caching
   const generateJSX = () => {
-    if (cacheRef.current[value]) {
-      return cacheRef.current[value];
+    if (cacheRef.current.has(value)) {
+      return cacheRef.current.get(value);
     }

     const jsx = htmlToJsx(value);
     const jsxCode = `function component() { return (${jsx}) }`;
-    cacheRef.current[value] = jsxCode;
+    cacheRef.current.set(value, jsxCode);
     return jsxCode;
   };

Also applies to: 27-33

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/convert/html-jsx/page.jsx` at line 11, The current cacheRef uses a
plain object (const cacheRef = useRef({})) which allows inherited-property
collisions (e.g., "toString") when reading cacheRef.current[value]; replace it
with a Map by initializing cacheRef = useRef(new Map()) and update all accesses
in this file (the cache get/set calls around the conversion logic referenced as
cacheRef.current[value] on lines ~27-33) to use cacheRef.current.get(value) and
cacheRef.current.set(value, result) so keys are treated safely and no inherited
properties can be returned.

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.

1 participant