Skip to content

fix: correct RG invalid example and refactor BrazilValidateComponent - #59

Merged
mariohmol merged 9 commits into
masterfrom
fix/rg-invalid-example
Apr 13, 2026
Merged

mariohmol merged 9 commits into
masterfrom
fix/rg-invalid-example

Conversation

@mariohmol

@mariohmol mariohmol commented Apr 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Fixes Create Validation Component #1 — DATAERROR.rg was 'MG1012345' which incorrectly showed as ✓ valid. The root cause is in js-brasil's validate_rg: any value whose first two characters match a Brazilian state code (MG, SP, RJ, etc.) in CEPRange is unconditionally accepted, bypassing the format check entirely. Replaced the invalid example with 'ZZ-10.123.456' (state code ZZ is not in CEPRange), so the invalid column now correctly renders ✗ invalid.
  • Refactor BrazilValidateComponent (src/validate.tsx) to accept value, format, and optional state props, delegating to validateBr from js-brasil.
  • Rewrite the example app (example/src/App.js) with a live mask+validate input table and a static valid/invalid side-by-side table.
  • Fix the titulo example value to use a valid check digit (2053.9588.0310).
  • Expand the test suite in tests/test.tsx.

Test plan

  • Confirm live mask+validate inputs work for all formats (cpf, cnpj, cep, rg, telefone, placa, titulo, time, currency)
  • Run CI=1 npx jest — existing pre-existing failures only (Node/Enzyme incompatibility), no new failures

🤖 Generated with Claude Code

mariohmol and others added 9 commits April 13, 2026 01:16
- Fix DATAERROR.rg: 'MG1012345' was passing validation because any
  value prefixed with a valid Brazilian state code (MG is in CEPRange)
  is unconditionally accepted by validate_rg. Replaced with 'ZZ-10.123.456'
  (invalid state code) so the invalid column correctly shows ✗ invalid.
  Refs #1
- Refactor BrazilValidateComponent to accept value/format/state props
  and use validateBr from js-brasil
- Rewrite example App with live mask+validate table and static valid/invalid table
- Fix titulo example value (valid check digit)
- Expand test suite coverage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Build the example app into docs/ so GitHub Pages can serve it from
the master branch docs/ folder (Settings → Pages → /docs).

- Set example/package.json homepage to https://mariohmol.github.io/react-brazil
- Add deploy script that copies example/build/. into docs/
- Add deploy:gh-pages convenience script (build + copy)
- Keep deploy:demo for the test.counbo.com server

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update deploy:demo script to use /var/www/test/ instead of
/var/www/test_counbo/ to avoid leaking the internal server name
in open source projects.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
package-lock.json is gitignored, so cache: "npm" and npm ci both fail.
Drop the cache option and switch to npm install.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
react-scripts-ts requires typescript@3.x but the project uses 2.x —
a pre-existing conflict that requires legacy peer dep resolution.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The prepare script runs rollup which uses rollup-plugin-postcss to process
SCSS. That plugin looks for node-sass (not installed), causing the build to
fail. Tests import from src/ directly so no dist build is needed in CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Enzyme 3 is incompatible with Node 18 (cheerio/lib/utils missing in
cheerio v1+, undici uses node: protocol unknown to Jest 24). Replace
enzyme rendering tests with direct validateBr/maskBr logic tests —
which is what actually matters for the library behaviour.

- Remove enzyme from setupTests.ts and test.tsx
- Rewrite tests to use validateBr and maskBr from js-brasil directly
- Fix tests/utils.ts: titulo raw/formatted value (wrong check digits)
  and DATAERROR.rg (MG prefix always passed due to CEPRange bug)
- Update jest.config.js: fix deprecated setupTestFrameworkScriptFile,
  drop node:/undici mocks (no longer needed without enzyme)

All 6 tests pass locally with CI=1 npx jest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
These were leftover from failed attempts to work around node: protocol
issues in Jest 24. Once enzyme was removed the workarounds became
unnecessary — tests pass without them.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mariohmol
mariohmol merged commit fd3a0ab into master Apr 13, 2026
2 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.

Create Validation Component

1 participant