Skip to content

Conversation

@JotErFou
Copy link

@JotErFou JotErFou commented Nov 4, 2025

  • Install Vitest with @vitest/ui, @testing-library/preact, and happy-dom
  • Add vitest.config.js with Preact plugin and coverage configuration
  • Create comprehensive unit tests for date_formatter.js (13 tests)
    • Test relative date formatting (today, yesterday, tomorrow)
    • Test relative time formatting (seconds, minutes, hours)
    • Test locale support (de-DE, fr-FR, en fallback)
  • Add test scripts to package.json (test, test:ui, test:coverage)
  • Fix: Use browser locale instead of hardcoded 'en' in date_formatter.js

All tests passing (13/13) ✓

Related to #30

- Install Vitest with @vitest/ui, @testing-library/preact, and happy-dom
- Add vitest.config.js with Preact plugin and coverage configuration
- Create comprehensive unit tests for date_formatter.js (13 tests)
  - Test relative date formatting (today, yesterday, tomorrow)
  - Test relative time formatting (seconds, minutes, hours)
  - Test locale support (de-DE, fr-FR, en fallback)
- Add test scripts to package.json (test, test:ui, test:coverage)
- Fix: Use browser locale instead of hardcoded 'en' in date_formatter.js

All tests passing (13/13) ✓

Related to operaton#30
- Add 14 tests for URL builder functions (_url_server, _url_engine_rest)
- Test credential formatting (get_credentials)
- Test RESPONSE_STATE constants integrity
- All tests passing (27/27 total)

Related to operaton#30
- Extract createMockState helper function to reduce duplication
- Simplify test setup by reusing mock state builder
- Reduces code duplication from 4.4% to comply with SonarQube threshold

Related to operaton#30
@JotErFou
Copy link
Author

JotErFou commented Nov 4, 2025

📋 SonarQube Security Hotspots

The 4 Security Hotspots flagged by SonarCloud are all test credentials in src/api/helper.test.js:

  1. Line 5: Default test credentials in createMockState helper function
  2. Line 44: { username: 'demo', password: 'demo' } - test fixture
  3. Line 50: { username: 'admin', password: 'secret123' } - test fixture
  4. Line 56: { username: '[email protected]', password: 'p@ssw0rd!' } - test fixture

These are dummy credentials for unit testing the get_credentials() function. They:

  • Are not used in production code
  • Are only in test files
  • Are intentionally hardcoded to verify credential formatting logic

✅ These hotspots don't block the PR - they are safe test fixtures.

Maintainers can mark these as "Safe" during review.

- Add 18 unit tests for TaskForm helper functions
- Test parse_html, build_form_data, prepare_form_data logic
- Fix required field marking (removed TODO at line 115):
  - Add null-check for previousElementSibling
  - Add fallback for nested inputs (parent label)
  - Support date fields for required marking
  - Prevent duplicate asterisks

All 45 tests passing (27 existing + 18 new)

related to operaton#30
Refactored TaskForm.test.jsx to eliminate code duplication:
- Extracted helper functions: parse_html_from_string, mark_required_fields, build_data, group_by_row
- Consolidated 7 duplicate test setups into reusable functions
- Reduced file size from 417 to ~206 lines (50% reduction)
- All 16 tests passing

This addresses SonarCloud Quality Gate failure (13.1% duplication → <3% target)

related to operaton#53
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
4 Security Hotspots

See analysis details on SonarQube Cloud

@JotErFou
Copy link
Author

Hi @kthoms 👋

Just a friendly ping - this PR has been ready for review for a few weeks now. The SonarQube security hotspots are false positives (dummy credentials in test fixtures like demo/demo).

Would appreciate a review when you have time. Let me know if there's anything I should adjust!

@javahippie
Copy link
Contributor

Hi @JotErFou,

thanks for your contribution and sorry for the delay! Unfortunately our main developer on this repo, @lambdaschmied2 is on leave right now, so he had no chance of reviewing. My knowledge of the ecosystem is limited, so I don't feel comfortable approving this PR. Please be assured that your contribution is valuable to us, I will try and find a way / a committer who can start a review on this asap

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