1+ describe ( "Documentation Page Images" , ( ) => {
2+ const pages = [
3+ { url : "/docs" , name : "Install and Quick start" } ,
4+ { url : "/docs/doc-table-instance-creation" , name : "Create Table Instance" } ,
5+ { url : "/docs/doc-adding-rows" , name : "Adding Rows" } ,
6+ { url : "/docs/doc-row-divider" , name : "Row Dividers" } ,
7+ { url : "/docs/doc-add-columns" , name : "Adding Columns" } ,
8+ { url : "/docs/doc-color" , name : "Coloring" } ,
9+ { url : "/docs/doc-sort-filter" , name : "Sort and Filter" } ,
10+ { url : "/docs/doc-alignment" , name : "Alignment" } ,
11+ { url : "/docs/doc-enable-disable-col" , name : "Enable and Disable Columns" } ,
12+ { url : "/docs/doc-computed-function" , name : "Calculated Columns" } ,
13+ { url : "/docs/doc-title" , name : "Table Title" } ,
14+ { url : "/docs/doc-column-title" , name : "Column Title" } ,
15+ { url : "/docs/doc-limit-line-width" , name : "Limit Column Width" } ,
16+ { url : "/docs/doc-border-design" , name : "Border Design" } ,
17+ { url : "/docs/doc-emojis-special-chars" , name : "Special Chars and emojis" } ,
18+ { url : "/docs/doc-render-console" , name : "Render Console Output" } ,
19+ { url : "/docs/doc-typescript" , name : "Typescript" } ,
20+ { url : "/docs/doc-cli-install-quick-start" , name : "CLI Quick Start" }
21+ ] ;
22+
23+ beforeEach ( ( ) => {
24+ // Increase the default timeout since we're dealing with image loading
25+ Cypress . config ( 'defaultCommandTimeout' , 10000 ) ;
26+
27+ // Intercept image requests to verify they succeed
28+ cy . intercept ( 'GET' , '/img/**/*' ) . as ( 'imageRequest' ) ;
29+ } ) ;
30+
31+ pages . forEach ( page => {
32+ it ( `should load all images properly on ${ page . name } page` , ( ) => {
33+ let imageRequestCount = 0 ;
34+
35+ // Count image requests
36+ cy . intercept ( 'GET' , '/img/**/*' , ( req ) => {
37+ imageRequestCount ++ ;
38+ req . continue ( ) ;
39+ } ) . as ( 'imageRequestCounter' ) ;
40+
41+ // Visit the page and wait for it to load
42+ cy . visit ( `http://localhost:3000${ page . url } ` , {
43+ timeout : 10000 ,
44+ retryOnStatusCodeFailure : true
45+ } ) ;
46+
47+ // Wait for main content to be visible
48+ cy . get ( 'main' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
49+
50+ // First wait for all images to be present in the DOM
51+ cy . get ( 'img' , { timeout : 10000 } ) . should ( 'exist' ) ;
52+
53+ // Get all images and verify their loading
54+ cy . get ( 'img' ) . then ( $images => {
55+ // Verify each image
56+ cy . wrap ( $images ) . each ( ( $img , index ) => {
57+ // Create a unique alias for this image
58+ const imgId = `img-${ index } ` ;
59+ cy . wrap ( $img ) . as ( imgId ) ;
60+
61+ // Wait for the image to be loaded
62+ cy . get ( `@${ imgId } ` ) . should ( ( $img ) => {
63+ expect ( $img [ 0 ] . complete ) . to . be . true ;
64+ expect ( $img [ 0 ] . naturalWidth ) . to . be . greaterThan ( 0 ) ;
65+ expect ( $img [ 0 ] . naturalHeight ) . to . be . greaterThan ( 0 ) ;
66+ } ) ;
67+
68+ // Verify src attribute
69+ cy . get ( `@${ imgId } ` )
70+ . should ( 'have.attr' , 'src' )
71+ . and ( 'not.be.empty' ) ;
72+ } ) ;
73+ } ) ;
74+
75+ // Verify all image requests were successful
76+ cy . get ( '@imageRequestCounter.all' ) . then ( ( interceptions ) => {
77+ if ( interceptions . length > 0 ) {
78+ interceptions . forEach ( ( interception ) => {
79+ if ( interception . response ) {
80+ expect ( [ 200 , 304 ] ) . to . include ( interception . response . statusCode ) ;
81+ } else {
82+ // If there's no response, the image might be cached or loaded from a different source
83+ // We've already verified the image is loaded properly above
84+ cy . log ( `No response for image request: ${ interception . request . url } ` ) ;
85+ }
86+ } ) ;
87+ }
88+ } ) ;
89+ } ) ;
90+ } ) ;
91+
92+ it ( 'should have proper alt text for all images' , ( ) => {
93+ cy . visit ( `http://localhost:3000/docs` , {
94+ timeout : 10000 ,
95+ retryOnStatusCodeFailure : true
96+ } ) ;
97+
98+ cy . get ( 'main' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
99+
100+ cy . get ( 'img' ) . each ( ( $img , index ) => {
101+ const imgId = `img-alt-${ index } ` ;
102+ cy . wrap ( $img ) . as ( imgId ) ;
103+
104+ cy . get ( `@${ imgId } ` )
105+ . should ( 'have.attr' , 'alt' )
106+ . and ( 'not.be.empty' ) ;
107+ } ) ;
108+ } ) ;
109+
110+ it ( 'should load images with correct dimensions' , ( ) => {
111+ cy . visit ( `http://localhost:3000/docs` , {
112+ timeout : 10000 ,
113+ retryOnStatusCodeFailure : true
114+ } ) ;
115+
116+ cy . get ( 'main' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
117+
118+ cy . get ( 'img' ) . each ( ( $img , index ) => {
119+ const imgId = `img-dim-${ index } ` ;
120+ cy . wrap ( $img ) . as ( imgId ) ;
121+
122+ cy . get ( `@${ imgId } ` ) . then ( ( $img ) => {
123+ const naturalWidth = $img [ 0 ] . naturalWidth ;
124+ const naturalHeight = $img [ 0 ] . naturalHeight ;
125+
126+ // Images should have reasonable dimensions
127+ expect ( naturalWidth ) . to . be . within ( 50 , 2000 ) ;
128+ expect ( naturalHeight ) . to . be . within ( 50 , 2000 ) ;
129+
130+ // Aspect ratio should be reasonable
131+ const aspectRatio = naturalWidth / naturalHeight ;
132+ expect ( aspectRatio ) . to . be . within ( 0.1 , 10 ) ;
133+ } ) ;
134+ } ) ;
135+ } ) ;
136+ } ) ;
0 commit comments