Skip to content

[QA] Add Client Unit Tests and Enhance Workflow Summary Reporting#74

Merged
GravityDarkLab merged 10 commits intomainfrom
72-client-add-unit-tests-for-frontend-services
Jul 13, 2025
Merged

[QA] Add Client Unit Tests and Enhance Workflow Summary Reporting#74
GravityDarkLab merged 10 commits intomainfrom
72-client-add-unit-tests-for-frontend-services

Conversation

@GravityDarkLab
Copy link
Collaborator

@GravityDarkLab GravityDarkLab commented Jul 13, 2025

✅ What's Implemented

🧪 Client-Side Tests

  • Added unit tests for core frontend logic using the testing framework (e.g., Vitest, Jest).
  • Captured and saved test outputs to test-output.txt for further analysis.

🔁 GitHub Actions Workflow Enhancements

  • Improved the Post workflow summary step in the CI workflow to:

    • Display the status, commit hash, branch, and Node version.
    • Automatically summarize test results (pass/fail, statistics, and coverage) from the test output.
    • Show detailed build status and artifact size.
    • Report linting results and flag failures without stopping the workflow.

📊 Automated Summary in GitHub Actions Includes:

  • Test Results

    • Pass/fail status
    • Test file and case counts
    • Code coverage output (from V8 or other source)
  • Build Results

    • Build status and size of dist/ folder
  • Code Quality

    • Linting outcome (success or warning)

🎯 Goal

To establish robust, verifiable testing for the frontend and provide enhanced visibility into test coverage, build integrity, and code quality directly in the GitHub Actions summary.

- Introduced Vitest configuration file to set up testing environment with JSDOM.
- Added global mocks for fetch, console methods, and local/session storage.
- Created mock API responses for user and course data to facilitate unit testing.
- Implemented comprehensive unit tests for the AI Chat Service, covering methods such as setAuthToken, getAIChatResponse, and confirmCourse.
- Included tests for various command scenarios, error handling, and response formatting.
- Utilized Vitest for mocking dependencies and simulating asynchronous behavior.
- Implemented comprehensive unit tests for the dashboard service, covering methods such as setAuthToken and getDashboardData.
- Included tests for various scenarios including successful data retrieval, handling of empty course lists, and error management.
- Utilized Vitest for mocking dependencies and ensuring accurate test coverage.
- Implemented comprehensive unit tests for the achievement service, covering functions such as calculateUserAchievements, getAchievementProgress, and getAllAchievementDefinitions.
- Included tests for various scenarios including achievement calculations based on completed, enrolled, and bookmarked courses.
- Utilized Vitest for mocking dependencies and ensuring accurate test coverage.
- Added steps to capture test results and output in the workflow summary.
- Implemented conditional logic to check for test files and report their execution status.
- Included sections for displaying build results and linting outcomes in the summary.
@GravityDarkLab GravityDarkLab self-assigned this Jul 13, 2025
@GravityDarkLab GravityDarkLab linked an issue Jul 13, 2025 that may be closed by this pull request
7 tasks
@GravityDarkLab GravityDarkLab changed the title 72 client add unit tests for frontend services [QA] Add Client Unit Tests and Enhance Workflow Summary Reporting Jul 13, 2025
- Enhanced the workflow summary to include stripped ANSI codes from test output for clearer reporting.
- Updated the workflow to filter and display coverage summary specifically for src/services.
@GravityDarkLab GravityDarkLab marked this pull request as ready for review July 13, 2025 21:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a full suite of frontend unit tests with supporting mocks and updates the CI workflow to capture and summarize test results, coverage, build output, and linting directly in GitHub Actions.

  • Introduces Vitest configuration and global test setup (mocks for fetch, console, storage, timers)
  • Adds comprehensive service-level unit tests under client/src/services/__tests__
  • Enhances the build-and-test-client GitHub Actions workflow to capture test output, code coverage, build size, and lint outcomes in the workflow summary

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
client/vitest.config.ts Configures Vitest with jsdom, coverage reporting, and path aliasing
client/src/test/setup.ts Sets up global mocks for fetch, console, localStorage, sessionStorage, and timers
client/src/test/mocks/api.ts Provides mock API response objects for user, course, and error scenarios
client/src/services/tests/* (multiple files) Adds unit tests for user.service, course.service, dashboard.service, aiChat.service, and achievement.service
client/package.json Adds jsdom dependency for test environment
.github/workflows/build-and-test-client.yml Captures test output, extracts stats/coverage, logs build status/size, and reports lint results in summary
Files not reviewed (1)
  • client/package-lock.json: Language not supported
Comments suppressed due to low confidence (2)

.github/workflows/build-and-test-client.yml:52

  • Consider adding continue-on-error: true to the 'Run tests' step so test failures don't stop the workflow and the summary step under if: always() still runs as intended.
        run: |

.github/workflows/build-and-test-client.yml:132

  • The grep pattern includes leading spaces when filtering for src/services. Coverage lines may not have those spaces—adjust the regex (e.g., grep -E '^src/services') to reliably extract the coverage summary.
              COVERAGE_INFO=$(awk '/Coverage report from v8/,0' test-clean.txt | grep -E '^All files|^ src/services|^  src/services' | head -n 20)

Copy link
Collaborator

@mahdibayouli mahdibayouli left a comment

Choose a reason for hiding this comment

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

✅ Approved! Client-side unit tests and enhanced GitHub Actions summary reporting were added. Coverage reporting and failure summaries are handled properly in the workflow! Great work 🚀🚀

@GravityDarkLab GravityDarkLab merged commit 65f65ba into main Jul 13, 2025
6 checks passed
@GravityDarkLab GravityDarkLab deleted the 72-client-add-unit-tests-for-frontend-services branch July 13, 2025 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Client] Add Unit Tests for Frontend Services

3 participants