Skip to content

Commit ed389f8

Browse files
authored
test(ShareButtons-theme-contrast): verify Dark and Light Prefers-Color-Scheme Visual Cohesion (JhaSourav07#3298)
## Description Fixes JhaSourav07#2765 This PR introduces integration tests for `components/ShareButtons.tsx` focusing on **Dark and Light Prefers-Color-Scheme Visual Cohesion**. Since this component inherits dynamic colors from its parents via SVG `currentColor`, these tests assert that the structural wrappers remain completely transparent (`bg-transparent`) without forcing localized colors that would disrupt the global dark/light modes. ## 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 - Integration Tests)* ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`vitest`). - [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): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started 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 raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions.
2 parents 1d97250 + c317a56 commit ed389f8

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, it, expect, beforeEach } from 'vitest';
2+
import { render, cleanup } from '@testing-library/react';
3+
import React from 'react';
4+
import ShareButtons from './ShareButtons';
5+
6+
describe('ShareButtons - Theme Contrast & Visual Cohesion (Issue #2765 Equivalent)', () => {
7+
beforeEach(() => {
8+
cleanup();
9+
});
10+
11+
it('Dual Theme Environment Mock (Dark/Light Presets Equivalent): inherently adapts to a light parent container', () => {
12+
// Render inside a explicitly light container
13+
const { container } = render(
14+
<div
15+
className="bg-white text-black dark:bg-black dark:text-white"
16+
style={{ color: 'rgb(0, 0, 0)' }}
17+
>
18+
<ShareButtons url="https://example.com" />
19+
</div>
20+
);
21+
22+
// SVGs should inherit the parent color via currentColor, not force their own
23+
const svgs = container.querySelectorAll('svg');
24+
expect(svgs.length).toBe(2);
25+
26+
// We verify the SVG elements don't contain hardcoded fill colors that override inheritance
27+
svgs.forEach((svg) => {
28+
expect(['currentColor', null]).toContain(svg.getAttribute('fill')); // React icons use currentColor or inherit
29+
});
30+
});
31+
32+
it('Color Styling Adaptation (Visual Elements Equivalent): explicitly avoids hardcoded text color utilities', () => {
33+
const { container } = render(<ShareButtons url="https://example.com" />);
34+
35+
const rootDiv = container.firstChild as HTMLElement;
36+
const classes = rootDiv.className;
37+
38+
// Component should NOT force a color
39+
expect(classes).not.toContain('text-white');
40+
expect(classes).not.toContain('text-black');
41+
expect(classes).not.toContain('text-'); // No text colors at all
42+
});
43+
44+
it('Contrast Ratio Standards (Textual Elements Equivalent): avoids inline styles that could break contrast inheritance', () => {
45+
const { container } = render(<ShareButtons url="https://example.com" />);
46+
47+
const anchors = container.querySelectorAll('a');
48+
49+
// Anchors must rely entirely on CSS cascades for contrast, no inline overrides
50+
anchors.forEach((a) => {
51+
expect(a.getAttribute('style')).toBeNull();
52+
});
53+
});
54+
55+
it('Custom Stylesheet Properties (Markup Classes Equivalent): relies solely on structural flex utilities for layout', () => {
56+
const { container } = render(<ShareButtons url="https://example.com" />);
57+
58+
const rootDiv = container.firstChild as HTMLElement;
59+
60+
// Should be a structural flex container
61+
expect(rootDiv.className).toContain('flex');
62+
expect(rootDiv.className).toContain('gap-3');
63+
64+
// Should NOT have any custom theme hacks
65+
expect(rootDiv.className).not.toContain('dark:');
66+
});
67+
68+
it('Background Overlay Clipping (Foreground Colors Equivalent): remains completely transparent to avoid overlay clipping', () => {
69+
const { container } = render(<ShareButtons url="https://example.com" />);
70+
71+
const rootDiv = container.firstChild as HTMLElement;
72+
73+
// Must not have any background colors that would clip against parent thematic overlays
74+
expect(rootDiv.className).not.toContain('bg-');
75+
76+
const anchors = container.querySelectorAll('a');
77+
anchors.forEach((a) => {
78+
expect(a.className).not.toContain('bg-');
79+
});
80+
});
81+
});

0 commit comments

Comments
 (0)