Feat: Add unit tests for ToggleDarkMode component#737
Feat: Add unit tests for ToggleDarkMode component#737kartikrautan wants to merge 4 commits intoaccordproject:mainfrom
Conversation
✅ Deploy Preview for ap-template-playground ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@copilot please review this pull request |
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive unit test coverage for the ToggleDarkMode component, addressing Issue #728. The PR introduces 10 well-structured test cases using Vitest and React Testing Library, following established testing patterns in the codebase. The tests verify component rendering, state initialization, store integration, DOM updates, prop forwarding, and sequential toggle behavior.
Changes:
- Added
src/tests/components/ToggleDarkMode.test.tsxwith 10 unit tests covering all aspects of the ToggleDarkMode component functionality - Implemented comprehensive mocking strategy for Zustand store, react-dark-mode-toggle library, and styled-components
- Tests verify light/dark mode initialization, toggle interactions, store method calls, DOM attribute updates, and component props
| @@ -0,0 +1,150 @@ | |||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | |||
| import { render, screen, fireEvent } from '@testing-library/react'; | |||
There was a problem hiding this comment.
Consider adding import '@testing-library/jest-dom'; for consistency with other test files in the codebase (Navbar.test.tsx and PlaygroundSidebar.test.tsx). While the matchers are globally available via the setup file, explicit imports improve code clarity and align with established patterns in the project.
| import { render, screen, fireEvent } from '@testing-library/react'; | |
| import { render, screen, fireEvent } from '@testing-library/react'; | |
| import '@testing-library/jest-dom'; |
|
Hi @mttrbrts , just checking in on my PR review. Thanks! |
Signed-off-by: kartik <kartikrautan0@gmail.com>
|
@kartikrautan can you review the build failures? |
Signed-off-by: kartik <kartikrautan0@gmail.com>
Done @mttrbrts thanks for the patience, good to go |
All of the changes seem to have disappeared? |
Signed-off-by: kartik <kartikrautan0@gmail.com>
Oh my bad the ToggleDarkMode component was deleted in a commit that i made, which is already in upstream main. I have added 8 more tests as part of the WebAuthn encryption work |
|
This new component doesn't appear to be integrated into the app anywhere, and you explain how it is used? |
@mttrbrts The ToggleDarkMode component already exists in the app and is used in the layout to allow users to switch between light and dark themes. |
Add Unit Tests for ToggleDarkMode Component
Closes #728
Adds a comprehensive unit test suite for the
ToggleDarkModecomponent using Vitest and React Testing Library, following the same mocking and testing patterns established in existing test files (SettingsModal.test.tsx,PlaygroundSidebar.test.tsx).Changes
src/tests/components/ToggleDarkMode.test.tsxwith 10 unit teststoggleDarkModecall verification)data-themeDOM attribute updatesuseEffectre-render onbackgroundColorchangesize={60},className)../../store/storereact-dark-mode-toggle../../styles/components/ToggleDarkModeFlags
useAppStore()call patternsScreenshots or Video
Related Issues
Author Checklist
--signoffoption ofgit commitmainfromfork:branchname