@@ -46,49 +46,85 @@ import {
4646import { dashboardApi } from '../../api/dashboardApi' ;
4747import type { DashboardData , QualityReport , CoverageReport , DependencyReport } from '../../types' ;
4848
49+ // ============================================================================
50+ // Test Constants
51+ // ============================================================================
52+
53+ const TEST_OUTPUTS_PATH = '/path/to/outputs' ;
54+ const TEST_TIMESTAMP = '2024-01-01T00:00:00Z' ;
55+ const TEST_VERSION = '1.0' ;
56+
57+ // Quality metrics
58+ const QUALITY_TOTAL_ISSUES = 15 ;
59+ const QUALITY_CRITICAL_COUNT = 2 ;
60+ const QUALITY_HIGH_COUNT = 5 ;
61+ const QUALITY_MEDIUM_COUNT = 8 ;
62+ const QUALITY_LOW_COUNT = 0 ;
63+
64+ // Alternative quality metrics for variation tests
65+ const ALT_QUALITY_TOTAL_ISSUES = 25 ;
66+ const ALT_QUALITY_CRITICAL_COUNT = 3 ;
67+ const ALT_QUALITY_HIGH_COUNT = 8 ;
68+ const ALT_QUALITY_MEDIUM_COUNT = 14 ;
69+
70+ // Coverage metrics
71+ const COVERAGE_PERCENTAGE = 85.5 ;
72+ const COVERAGE_TESTED_FUNCTIONS = 156 ;
73+ const COVERAGE_UNTESTED_FUNCTIONS = 28 ;
74+ const ALT_COVERAGE_PERCENTAGE = 92.6789 ;
75+
76+ // Dependency metrics
77+ const DEPENDENCY_TOTAL_FILES = 42 ;
78+ const DEPENDENCY_CIRCULAR_COUNT = 3 ;
79+ const DEPENDENCY_COUNT = 128 ;
80+ const DEPENDENCY_EXTERNAL_COUNT = 25 ;
81+
82+ // Expected section count for nested suspense
83+ const EXPECTED_SECTION_COUNT = 3 ;
84+
4985// ============================================================================
5086// Test Data Fixtures
5187// ============================================================================
5288
5389const mockQualityData : QualityReport = {
5490 summary : {
55- total_issues : 15 ,
91+ total_issues : QUALITY_TOTAL_ISSUES ,
5692 by_severity : {
57- critical : 2 ,
58- high : 5 ,
59- medium : 8 ,
60- low : 0 ,
93+ critical : QUALITY_CRITICAL_COUNT ,
94+ high : QUALITY_HIGH_COUNT ,
95+ medium : QUALITY_MEDIUM_COUNT ,
96+ low : QUALITY_LOW_COUNT ,
6197 } ,
6298 by_category : { } ,
6399 } ,
64100 issues : [ ] ,
65- timestamp : '2024-01-01T00:00:00Z' ,
66- version : '1.0' ,
101+ timestamp : TEST_TIMESTAMP ,
102+ version : TEST_VERSION ,
67103} ;
68104
69105const mockCoverageData : CoverageReport = {
70106 summary : {
71- coverage_percentage : 85.5 ,
72- tested_functions : 156 ,
73- untested_functions : 28 ,
107+ coverage_percentage : COVERAGE_PERCENTAGE ,
108+ tested_functions : COVERAGE_TESTED_FUNCTIONS ,
109+ untested_functions : COVERAGE_UNTESTED_FUNCTIONS ,
74110 coverage_trend : [ ] ,
75111 } ,
76112 coverage_by_file : [ ] ,
77- timestamp : '2024-01-01T00:00:00Z' ,
78- version : '1.0' ,
113+ timestamp : TEST_TIMESTAMP ,
114+ version : TEST_VERSION ,
79115} ;
80116
81117const mockDependencyData : DependencyReport = {
82118 summary : {
83- total_files : 42 ,
84- circular_dependencies : 3 ,
85- dependency_count : 128 ,
86- external_deps : 25 ,
119+ total_files : DEPENDENCY_TOTAL_FILES ,
120+ circular_dependencies : DEPENDENCY_CIRCULAR_COUNT ,
121+ dependency_count : DEPENDENCY_COUNT ,
122+ external_deps : DEPENDENCY_EXTERNAL_COUNT ,
87123 } ,
88124 dependencies : [ ] ,
89125 circular_deps : [ ] ,
90- timestamp : '2024-01-01T00:00:00Z' ,
91- version : '1.0' ,
126+ timestamp : TEST_TIMESTAMP ,
127+ version : TEST_VERSION ,
92128} ;
93129
94130const mockDashboardData : DashboardData = {
@@ -162,7 +198,7 @@ function MetricsOverview({ data }: MetricsOverviewProps) {
162198}
163199
164200function DashboardContent ( ) {
165- const { data } = useDashboardData ( '/path/to/outputs' ) ;
201+ const { data } = useDashboardData ( TEST_OUTPUTS_PATH ) ;
166202
167203 return (
168204 < div >
@@ -185,7 +221,7 @@ function DashboardApp() {
185221}
186222
187223function QualityDashboard ( ) {
188- const { data : qualityData } = useQualityReport ( '/path/to/outputs' ) ;
224+ const { data : qualityData } = useQualityReport ( TEST_OUTPUTS_PATH ) ;
189225
190226 return (
191227 < div data-testid = "quality-dashboard" >
@@ -198,7 +234,7 @@ function QualityDashboard() {
198234}
199235
200236function CoverageDashboard ( ) {
201- const { data : coverageData } = useCoverageReport ( '/path/to/outputs' ) ;
237+ const { data : coverageData } = useCoverageReport ( TEST_OUTPUTS_PATH ) ;
202238
203239 return (
204240 < div data-testid = "coverage-dashboard" >
@@ -211,7 +247,7 @@ function CoverageDashboard() {
211247}
212248
213249function DependencyDashboard ( ) {
214- const { data : dependencyData } = useDependencyReport ( '/path/to/outputs' ) ;
250+ const { data : dependencyData } = useDependencyReport ( TEST_OUTPUTS_PATH ) ;
215251
216252 return (
217253 < div data-testid = "dependency-dashboard" >
@@ -238,12 +274,11 @@ function RefreshButton() {
238274
239275function DashboardWithPrefetch ( ) {
240276 const queryClient = useQueryClient ( ) ;
241- const outputsPath = '/path/to/outputs' ;
242277
243278 const handleMouseEnter = ( ) => {
244279 queryClient . prefetchQuery ( {
245- queryKey : [ 'quality-report' , outputsPath ] ,
246- queryFn : ( ) => dashboardApi . loadQualityReport ( outputsPath ) ,
280+ queryKey : [ 'quality-report' , TEST_OUTPUTS_PATH ] ,
281+ queryFn : ( ) => dashboardApi . loadQualityReport ( TEST_OUTPUTS_PATH ) ,
247282 } ) ;
248283 } ;
249284
@@ -282,17 +317,17 @@ function DashboardWithErrorRecovery() {
282317}
283318
284319function QualitySection ( ) {
285- const { data } = useQualityReport ( '/path/to/outputs' ) ;
320+ const { data } = useQualityReport ( TEST_OUTPUTS_PATH ) ;
286321 return < div data-testid = "quality-section" > { /* Render quality data */ } </ div > ;
287322}
288323
289324function CoverageSection ( ) {
290- const { data } = useCoverageReport ( '/path/to/outputs' ) ;
325+ const { data } = useCoverageReport ( TEST_OUTPUTS_PATH ) ;
291326 return < div data-testid = "coverage-section" > { /* Render coverage data */ } </ div > ;
292327}
293328
294329function DependencySection ( ) {
295- const { data } = useDependencyReport ( '/path/to/outputs' ) ;
330+ const { data } = useDependencyReport ( TEST_OUTPUTS_PATH ) ;
296331 return < div data-testid = "dependency-section" > { /* Render dependency data */ } </ div > ;
297332}
298333
@@ -407,9 +442,9 @@ describe('HooksUsage Examples', () => {
407442
408443 await waitFor ( ( ) => {
409444 expect ( screen . getByTestId ( 'metrics-overview' ) ) . toBeInTheDocument ( ) ;
410- expect ( screen . getByTestId ( 'quality-metric' ) ) . toHaveTextContent ( '15' ) ;
411- expect ( screen . getByTestId ( 'coverage-metric' ) ) . toHaveTextContent ( '85.5%' ) ;
412- expect ( screen . getByTestId ( 'dependency-metric' ) ) . toHaveTextContent ( '3' ) ;
445+ expect ( screen . getByTestId ( 'quality-metric' ) ) . toHaveTextContent ( String ( QUALITY_TOTAL_ISSUES ) ) ;
446+ expect ( screen . getByTestId ( 'coverage-metric' ) ) . toHaveTextContent ( ` ${ COVERAGE_PERCENTAGE } %` ) ;
447+ expect ( screen . getByTestId ( 'dependency-metric' ) ) . toHaveTextContent ( String ( DEPENDENCY_CIRCULAR_COUNT ) ) ;
413448 } ) ;
414449 } ) ;
415450 } ) ;
@@ -435,9 +470,9 @@ describe('HooksUsage Examples', () => {
435470
436471 await waitFor ( ( ) => {
437472 expect ( screen . getByTestId ( 'quality-dashboard' ) ) . toBeInTheDocument ( ) ;
438- expect ( screen . getByText ( ' Total Issues: 15' ) ) . toBeInTheDocument ( ) ;
439- expect ( screen . getByText ( ' Critical: 2' ) ) . toBeInTheDocument ( ) ;
440- expect ( screen . getByText ( ' High: 5' ) ) . toBeInTheDocument ( ) ;
473+ expect ( screen . getByText ( ` Total Issues: ${ QUALITY_TOTAL_ISSUES } ` ) ) . toBeInTheDocument ( ) ;
474+ expect ( screen . getByText ( ` Critical: ${ QUALITY_CRITICAL_COUNT } ` ) ) . toBeInTheDocument ( ) ;
475+ expect ( screen . getByText ( ` High: ${ QUALITY_HIGH_COUNT } ` ) ) . toBeInTheDocument ( ) ;
441476 } ) ;
442477 } ) ;
443478
@@ -447,12 +482,12 @@ describe('HooksUsage Examples', () => {
447482 ...mockQualityData ,
448483 summary : {
449484 ...mockQualityData . summary ,
450- total_issues : 25 ,
485+ total_issues : ALT_QUALITY_TOTAL_ISSUES ,
451486 by_severity : {
452- critical : 3 ,
453- high : 8 ,
454- medium : 14 ,
455- low : 0 ,
487+ critical : ALT_QUALITY_CRITICAL_COUNT ,
488+ high : ALT_QUALITY_HIGH_COUNT ,
489+ medium : ALT_QUALITY_MEDIUM_COUNT ,
490+ low : QUALITY_LOW_COUNT ,
456491 } ,
457492 } ,
458493 } ;
@@ -470,9 +505,9 @@ describe('HooksUsage Examples', () => {
470505 ) ;
471506
472507 await waitFor ( ( ) => {
473- expect ( screen . getByText ( ' Total Issues: 25' ) ) . toBeInTheDocument ( ) ;
474- expect ( screen . getByText ( ' Critical: 3' ) ) . toBeInTheDocument ( ) ;
475- expect ( screen . getByText ( ' High: 8' ) ) . toBeInTheDocument ( ) ;
508+ expect ( screen . getByText ( ` Total Issues: ${ ALT_QUALITY_TOTAL_ISSUES } ` ) ) . toBeInTheDocument ( ) ;
509+ expect ( screen . getByText ( ` Critical: ${ ALT_QUALITY_CRITICAL_COUNT } ` ) ) . toBeInTheDocument ( ) ;
510+ expect ( screen . getByText ( ` High: ${ ALT_QUALITY_HIGH_COUNT } ` ) ) . toBeInTheDocument ( ) ;
476511 } ) ;
477512 } ) ;
478513 } ) ;
@@ -493,9 +528,9 @@ describe('HooksUsage Examples', () => {
493528
494529 await waitFor ( ( ) => {
495530 expect ( screen . getByTestId ( 'coverage-dashboard' ) ) . toBeInTheDocument ( ) ;
496- expect ( screen . getByText ( ' Coverage: 85.5%' ) ) . toBeInTheDocument ( ) ;
497- expect ( screen . getByText ( ' Tested: 156' ) ) . toBeInTheDocument ( ) ;
498- expect ( screen . getByText ( ' Untested: 28' ) ) . toBeInTheDocument ( ) ;
531+ expect ( screen . getByText ( ` Coverage: ${ COVERAGE_PERCENTAGE } %` ) ) . toBeInTheDocument ( ) ;
532+ expect ( screen . getByText ( ` Tested: ${ COVERAGE_TESTED_FUNCTIONS } ` ) ) . toBeInTheDocument ( ) ;
533+ expect ( screen . getByText ( ` Untested: ${ COVERAGE_UNTESTED_FUNCTIONS } ` ) ) . toBeInTheDocument ( ) ;
499534 } ) ;
500535 } ) ;
501536
@@ -504,7 +539,7 @@ describe('HooksUsage Examples', () => {
504539 ...mockCoverageData ,
505540 summary : {
506541 ...mockCoverageData . summary ,
507- coverage_percentage : 92.6789 ,
542+ coverage_percentage : ALT_COVERAGE_PERCENTAGE ,
508543 } ,
509544 } ;
510545
@@ -520,6 +555,7 @@ describe('HooksUsage Examples', () => {
520555 </ Suspense >
521556 ) ;
522557
558+ // ALT_COVERAGE_PERCENTAGE (92.6789) formatted to 1 decimal = 92.7
523559 await waitFor ( ( ) => {
524560 expect ( screen . getByText ( 'Coverage: 92.7%' ) ) . toBeInTheDocument ( ) ;
525561 } ) ;
@@ -542,8 +578,8 @@ describe('HooksUsage Examples', () => {
542578
543579 await waitFor ( ( ) => {
544580 expect ( screen . getByTestId ( 'dependency-dashboard' ) ) . toBeInTheDocument ( ) ;
545- expect ( screen . getByText ( ' Total Files: 42' ) ) . toBeInTheDocument ( ) ;
546- expect ( screen . getByText ( ' Circular Dependencies: 3' ) ) . toBeInTheDocument ( ) ;
581+ expect ( screen . getByText ( ` Total Files: ${ DEPENDENCY_TOTAL_FILES } ` ) ) . toBeInTheDocument ( ) ;
582+ expect ( screen . getByText ( ` Circular Dependencies: ${ DEPENDENCY_CIRCULAR_COUNT } ` ) ) . toBeInTheDocument ( ) ;
547583 } ) ;
548584 } ) ;
549585 } ) ;
@@ -632,7 +668,7 @@ describe('HooksUsage Examples', () => {
632668
633669 await waitFor ( ( ) => {
634670 expect ( mockPrefetchQuery ) . toHaveBeenCalledWith ( {
635- queryKey : [ 'quality-report' , '/path/to/outputs' ] ,
671+ queryKey : [ 'quality-report' , TEST_OUTPUTS_PATH ] ,
636672 queryFn : expect . any ( Function ) ,
637673 } ) ;
638674 } ) ;
@@ -777,7 +813,7 @@ describe('HooksUsage Examples', () => {
777813
778814 expect ( screen . getByText ( 'Dashboard' ) ) . toBeInTheDocument ( ) ;
779815 const skeletons = screen . getAllByTestId ( 'section-skeleton' ) ;
780- expect ( skeletons ) . toHaveLength ( 3 ) ;
816+ expect ( skeletons ) . toHaveLength ( EXPECTED_SECTION_COUNT ) ;
781817 } ) ;
782818
783819 it ( 'should render all three sections when loaded' , async ( ) => {
@@ -881,15 +917,15 @@ describe('HooksUsage Examples', () => {
881917 render ( < MetricsOverview data = { mockDashboardData } /> ) ;
882918
883919 expect ( screen . getByText ( 'Code Quality' ) ) . toBeInTheDocument ( ) ;
884- expect ( screen . getByText ( '15' ) ) . toBeInTheDocument ( ) ;
920+ expect ( screen . getByText ( String ( QUALITY_TOTAL_ISSUES ) ) ) . toBeInTheDocument ( ) ;
885921 expect ( screen . getByText ( 'Total Issues' ) ) . toBeInTheDocument ( ) ;
886922 } ) ;
887923
888924 it ( 'should format coverage percentage with one decimal' , ( ) => {
889925 render ( < MetricsOverview data = { mockDashboardData } /> ) ;
890926
891927 expect ( screen . getByText ( 'Test Coverage' ) ) . toBeInTheDocument ( ) ;
892- expect ( screen . getByText ( '85.5%' ) ) . toBeInTheDocument ( ) ;
928+ expect ( screen . getByText ( ` ${ COVERAGE_PERCENTAGE } %` ) ) . toBeInTheDocument ( ) ;
893929 expect ( screen . getByText ( 'Coverage' ) ) . toBeInTheDocument ( ) ;
894930 } ) ;
895931
@@ -901,7 +937,7 @@ describe('HooksUsage Examples', () => {
901937
902938 // Find the div with dependency metric and check for the value
903939 const depMetric = screen . getByTestId ( 'dependency-metric' ) ;
904- expect ( depMetric ) . toHaveTextContent ( '3' ) ;
940+ expect ( depMetric ) . toHaveTextContent ( String ( DEPENDENCY_CIRCULAR_COUNT ) ) ;
905941 } ) ;
906942 } ) ;
907943
0 commit comments