Skip to content

Comments

Feat add basic testing#81

Merged
BrayanMQ merged 5 commits intomainfrom
feat-add-basic-testing
Jan 10, 2026
Merged

Feat add basic testing#81
BrayanMQ merged 5 commits intomainfrom
feat-add-basic-testing

Conversation

@BrayanMQ
Copy link
Owner

📝 Description

This PR adds a comprehensive testing infrastructure to the project using Jest and React Testing Library. It includes unit tests for critical logic functions and component tests for key UI elements, along with CI automation via GitHub Actions.

🔗 Related Issue

Closes #28

🏷️ Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Dependency update

🔄 Changes Made

  • Installed Jest, React Testing Library, and related dependencies
  • Created jest.config.ts and jest.setup.ts for Next.js configuration
  • Added unit tests for lib/streaks.ts (streak calculation logic)
  • Added unit tests for lib/stats.ts (statistics functions)
  • Added component tests for HabitCard and AddHabitModal
  • Added integration tests for CalendarPage and StatsPage
  • Created GitHub Actions workflow (.github/workflows/tests.yml) to run tests on push/PR

🧪 Testing

All tests pass locally:

Test Suites: 6 passed, 6 total
Tests:       38 passed, 38 total
Snapshots:   0 total
Time:        2.617 s
  • Manual testing completed
  • Unit tests added/updated
  • Integration tests added/updated

✅ Checklist

  • My code follows the project's code style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (if applicable)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

📸 Screenshots (if applicable)

N/A - This PR adds testing infrastructure, no UI changes.

📌 Additional Notes

New Files

File Purpose
jest.config.ts Jest configuration for Next.js
jest.setup.ts Jest setup with testing-library matchers
lib/__tests__/streaks.test.ts Unit tests for streak calculations
lib/__tests__/stats.test.ts Unit tests for statistics functions
components/habits/__tests__/HabitCard.test.tsx Component tests for HabitCard
components/habits/__tests__/AddHabitModal.test.tsx Component tests for AddHabitModal
app/dashboard/calendar/__tests__/page.test.tsx Integration tests for CalendarPage
app/dashboard/stats/__tests__/page.test.tsx Integration tests for StatsPage
.github/workflows/tests.yml GitHub Actions workflow for CI

New Scripts

  • npm test - Run all tests
  • npm run test:watch - Run tests in watch mode

- Introduced Jest configuration in jest.config.ts for testing Next.js applications.
- Added jest.setup.ts to include custom matchers from @testing-library/jest-dom.
- Updated package.json to include test scripts and added necessary testing libraries in devDependencies.
- Updated package-lock.json to reflect new dependencies for testing.
- Introduced comprehensive Jest tests for the stats and streaks utilities, covering functions such as getCompletionRate, getBestStreak, getTotalDaysTracked, and getAverageCompletionRate.
- Added tests for calculating streaks, including handling gaps and incomplete days.
- Ensured proper date formatting and logging behavior in test scenarios.
- Introduced Jest tests for AddHabitModal, covering rendering, input validation, and form submission.
- Added tests for HabitCard, validating rendering of habit details and interaction in different modes.
- Mocked necessary dependencies to ensure isolated testing of components.
- Introduced Jest tests for CalendarPage, covering loading states, empty states, habit selection, and month navigation.
- Added Jest tests for StatsPage, validating loading, error handling, empty states, and stats rendering.
- Mocked necessary dependencies and data to ensure isolated testing of components.
- Introduced a new GitHub Actions workflow to automate testing on push and pull request events for the main and develop branches.
- Configured the workflow to set up Node.js, install dependencies, and run tests using npm.
- Ensured the testing environment runs on the latest Ubuntu version.
@BrayanMQ BrayanMQ linked an issue Jan 10, 2026 that may be closed by this pull request
@BrayanMQ BrayanMQ merged commit da22aa0 into main Jan 10, 2026
1 check passed
@BrayanMQ BrayanMQ deleted the feat-add-basic-testing branch January 10, 2026 21:37
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.

Add basic testing

1 participant