Skip to content

Commit 00625ff

Browse files
authored
test(RepositoryGraph-responsive-breakpoints): verify Responsive Multi-device Columns & Mobile Viewport Layouts (Variation 7) (JhaSourav07#3553)
## Description Fixes JhaSourav07#2609 Added responsive breakpoint test coverage for `RepositoryGraph`. ## Pillar - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (test-only change) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [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 starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. ## Changes Made * Created `components/dashboard/RepositoryGraph.responsive-breakpoints.test.tsx` * Added mobile viewport rendering validation * Added responsive filter control coverage * Added graph container rendering verification for smaller screens * Added resize event handling coverage * Added responsive sidebar content validation ## Result * Improves responsive layout coverage for RepositoryGraph * Verifies mobile-width rendering behavior * Helps prevent regressions across viewport sizes * Confirms resize handling remains stable * All newly added tests pass successfully
2 parents 3628a75 + 5b4290b commit 00625ff

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { describe, it, expect, vi, beforeEach } from 'vitest';
3+
import { render, screen, act } from '@testing-library/react';
4+
import React from 'react';
5+
import RepositoryGraph from './RepositoryGraph';
6+
import type { GraphNode, GraphLink } from '@/types';
7+
8+
vi.mock('next/dynamic', () => {
9+
const DynamicForceGraphMock = React.forwardRef((props: any, ref: any) => {
10+
React.useImperativeHandle(ref, () => ({
11+
centerAt: vi.fn(),
12+
zoom: vi.fn(),
13+
}));
14+
15+
return (
16+
<div data-testid="force-graph-2d">
17+
{props.graphData?.nodes?.map((node: any) => (
18+
<div key={node.id}>{node.name}</div>
19+
))}
20+
</div>
21+
);
22+
});
23+
24+
DynamicForceGraphMock.displayName = 'ForceGraph2D';
25+
26+
return {
27+
default: () => DynamicForceGraphMock,
28+
};
29+
});
30+
31+
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
32+
configurable: true,
33+
value: 375,
34+
});
35+
36+
const mockData = {
37+
nodes: [
38+
{ id: 'user1', name: 'User 1', type: 'User', val: 30, color: '#FFF' },
39+
{
40+
id: 'repo1',
41+
name: 'Repo 1',
42+
type: 'Repo',
43+
val: 15,
44+
color: '#FFF',
45+
stats: { stars: 10 },
46+
},
47+
{
48+
id: 'fork1',
49+
name: 'Fork 1',
50+
type: 'Fork',
51+
val: 10,
52+
color: '#FFF',
53+
},
54+
{
55+
id: 'contrib1',
56+
name: 'Contrib 1',
57+
type: 'Contribution',
58+
val: 20,
59+
color: '#FFF',
60+
},
61+
] as GraphNode[],
62+
links: [
63+
{ source: 'user1', target: 'repo1' },
64+
{ source: 'user1', target: 'fork1' },
65+
{ source: 'user1', target: 'contrib1' },
66+
] as GraphLink[],
67+
};
68+
69+
describe('RepositoryGraph Responsive Breakpoints', () => {
70+
beforeEach(() => {
71+
vi.clearAllMocks();
72+
});
73+
74+
it('renders graph successfully on mobile viewport width', () => {
75+
render(<RepositoryGraph data={mockData} />);
76+
77+
expect(screen.getByText('🌐 Repository Dependency Graph')).toBeInTheDocument();
78+
});
79+
80+
it('renders filter controls in wrapped mobile layout', () => {
81+
render(<RepositoryGraph data={mockData} />);
82+
83+
expect(screen.getByText('Personal')).toBeInTheDocument();
84+
expect(screen.getByText('Contributions')).toBeInTheDocument();
85+
expect(screen.getByText('Forks')).toBeInTheDocument();
86+
});
87+
88+
it('renders graph container at mobile width without crashing', () => {
89+
render(<RepositoryGraph data={mockData} />);
90+
91+
expect(screen.getByTestId('force-graph-2d')).toBeInTheDocument();
92+
});
93+
94+
it('handles resize events correctly on smaller viewports', () => {
95+
render(<RepositoryGraph data={mockData} />);
96+
97+
act(() => {
98+
window.dispatchEvent(new Event('resize'));
99+
});
100+
101+
expect(screen.getByText('🌐 Repository Dependency Graph')).toBeInTheDocument();
102+
});
103+
104+
it('keeps desktop insight content available in rendered output', () => {
105+
render(<RepositoryGraph data={mockData} />);
106+
107+
expect(screen.getByText('Graph Insights')).toBeInTheDocument();
108+
109+
expect(screen.getByText(/Repositories connected/i)).toBeInTheDocument();
110+
});
111+
});

0 commit comments

Comments
 (0)