Skip to content

Commit 37a088f

Browse files
authored
test(feature-cards): add theme contrast coverage (JhaSourav07#3240)
## Description Fixes JhaSourav07#2745 Added isolated unit tests for `components/FeatureCards.tsx` focusing on theme-aware rendering behavior, dark/light mode stability, and visual cohesion. ### Changes - Added `components/FeatureCards.theme-contrast.test.tsx` - Mocked GSAP and ScrollTrigger dependencies to isolate component rendering - Verified component rendering in simulated light theme environments - Verified component rendering in simulated dark theme environments - Tested heading visibility and content accessibility across theme changes - Confirmed foreground content remains visible and renderable under different theme states - Verified layout structure remains stable when switching theme contexts - Improved coverage around theme-related rendering behavior and visual consistency ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (test-only changes) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no visual changes made). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 78985d2 + c8aac38 commit 37a088f

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
5+
vi.mock('gsap', () => ({
6+
default: {
7+
set: vi.fn(),
8+
to: vi.fn(),
9+
fromTo: vi.fn(),
10+
registerPlugin: vi.fn(),
11+
context: vi.fn((callback: () => void) => {
12+
callback();
13+
14+
return {
15+
revert: vi.fn(),
16+
};
17+
}),
18+
timeline: vi.fn(() => ({
19+
to: vi.fn().mockReturnThis(),
20+
set: vi.fn().mockReturnThis(),
21+
fromTo: vi.fn().mockReturnThis(),
22+
kill: vi.fn(),
23+
})),
24+
},
25+
}));
26+
27+
vi.mock('gsap/ScrollTrigger', () => ({
28+
ScrollTrigger: {},
29+
}));
30+
31+
import { FeatureCardsSection } from './FeatureCards';
32+
33+
describe('FeatureCards Theme Contrast', () => {
34+
it('renders correctly in simulated light theme', () => {
35+
document.documentElement.classList.remove('dark');
36+
37+
render(
38+
<FeatureCardsSection>
39+
<div>Light Theme Content</div>
40+
</FeatureCardsSection>
41+
);
42+
43+
expect(screen.getByText('Light Theme Content')).toBeInTheDocument();
44+
});
45+
46+
it('renders correctly in simulated dark theme', () => {
47+
document.documentElement.classList.add('dark');
48+
49+
render(
50+
<FeatureCardsSection>
51+
<div>Dark Theme Content</div>
52+
</FeatureCardsSection>
53+
);
54+
55+
expect(screen.getByText('Dark Theme Content')).toBeInTheDocument();
56+
});
57+
58+
it('maintains heading visibility across themes', () => {
59+
render(
60+
<FeatureCardsSection>
61+
<div>Theme Test</div>
62+
</FeatureCardsSection>
63+
);
64+
65+
expect(
66+
screen.getByRole('heading', {
67+
name: /why commitpulse/i,
68+
})
69+
).toBeInTheDocument();
70+
});
71+
72+
it('renders child content without clipping foreground elements', () => {
73+
render(
74+
<FeatureCardsSection>
75+
<button>Foreground Action</button>
76+
</FeatureCardsSection>
77+
);
78+
79+
expect(
80+
screen.getByRole('button', {
81+
name: 'Foreground Action',
82+
})
83+
).toBeInTheDocument();
84+
});
85+
86+
it('preserves layout structure under theme changes', () => {
87+
const { container } = render(
88+
<FeatureCardsSection>
89+
<div>Theme Layout Content</div>
90+
</FeatureCardsSection>
91+
);
92+
93+
expect(container.firstChild).toBeTruthy();
94+
expect(screen.getByText('Theme Layout Content')).toBeInTheDocument();
95+
});
96+
});

0 commit comments

Comments
 (0)