Skip to content

Add comprehensive unit tests for frontend certificate.js #29

@Hemavathi15sg

Description

@Hemavathi15sg

Summary

Add thorough unit test coverage for frontend/certificate.js to ensure certificate verification flows are resilient, including edge cases, API failures, and invalid data scenarios.

Scope

  • Cover success and failure paths for certificate verification logic (including fetch/HTTP error handling, non-200 responses, and malformed JSON).
  • Validate behavior when inputs are missing/invalid (empty certificate ID/serial, whitespace-only, excessively long values, special characters).
  • Ensure UI state updates are tested (loading indicators, error/success messages, button disabled states, cleared/retained inputs on submit/retry).
  • Test handling of timeout/abort scenarios (e.g., fetch aborted or delayed responses) if supported in code.
  • Verify rendering of certificate details uses safe defaults when optional fields are absent (expiry date null, missing holder/course fields).
  • Add regression tests for QR/verification URL rendering if applicable in certificate.js.

Approach

  • Use a JS test runner suitable for the frontend bundle (e.g., Jest + jsdom, or the project’s preferred runner) and mock fetch and DOM APIs.
  • Add fixtures for valid/invalid certificate payloads and error responses.
  • Include negative tests: network failure, 500s/404s, invalid JSON, signature mismatch payloads if applicable.
  • Ensure tests run via CI (document command in README if new).

Definition of Done

  • New tests added under frontend/ (or existing tests folder) with clear arrange/act/assert structure.
  • Tests deterministic and not relying on live network calls.
  • Test command documented if new.
  • CI passes with added coverage improvements noted.

/cc @CanarysPlayground

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions