@@ -18,42 +18,50 @@ describe("Weather module: Weather Forecast", () => {
1818 const days = [ "Today" , "Tomorrow" , "Sun" , "Mon" , "Tue" ] ;
1919 for ( const [ index , day ] of days . entries ( ) ) {
2020 it ( `should render day ${ day } ` , async ( ) => {
21- const dayCell = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } ) td:nth-child(1) ` ) ;
21+ const dayCell = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } ) .day ` ) ;
2222 await expect ( dayCell ) . toHaveText ( day ) ;
2323 } ) ;
2424 }
2525
2626 const icons = [ "day-cloudy" , "rain" , "day-sunny" , "day-sunny" , "day-sunny" ] ;
2727 for ( const [ index , icon ] of icons . entries ( ) ) {
2828 it ( `should render icon ${ icon } ` , async ( ) => {
29- const iconElement = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } ) td:nth-child(2 ) span.wi-${ icon } ` ) ;
29+ const iconElement = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } ) span.wi-${ icon } ` ) ;
3030 await expect ( iconElement ) . toBeVisible ( ) ;
3131 } ) ;
3232 }
3333
3434 const maxTemps = [ "24.4°" , "21.0°" , "22.9°" , "23.4°" , "20.6°" ] ;
3535 for ( const [ index , temp ] of maxTemps . entries ( ) ) {
3636 it ( `should render max temperature ${ temp } ` , async ( ) => {
37- const maxTempCell = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } ) td .max-temp` ) ;
37+ const maxTempCell = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } ) .max-temp` ) ;
3838 await expect ( maxTempCell ) . toHaveText ( temp ) ;
3939 } ) ;
4040 }
4141
4242 const minTemps = [ "15.3°" , "13.6°" , "13.8°" , "13.9°" , "10.9°" ] ;
4343 for ( const [ index , temp ] of minTemps . entries ( ) ) {
4444 it ( `should render min temperature ${ temp } ` , async ( ) => {
45- const minTempCell = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } ) td .min-temp` ) ;
45+ const minTempCell = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } ) .min-temp` ) ;
4646 await expect ( minTempCell ) . toHaveText ( temp ) ;
4747 } ) ;
4848 }
4949
5050 const opacities = [ 1 , 1 , 0.8 , 0.5333333333333333 , 0.2666666666666667 ] ;
5151 for ( const [ index , opacity ] of opacities . entries ( ) ) {
5252 it ( `should render fading of rows with opacity=${ opacity } ` , async ( ) => {
53- const row = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } )` ) ;
53+ const row = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } )` ) ;
5454 await expect ( row ) . toHaveAttribute ( "style" , `opacity: ${ opacity } ;` ) ;
5555 } ) ;
5656 }
57+
58+ it ( "should align forecast columns across rows" , async ( ) => {
59+ for ( const column of [ ".day" , ".weather-icon" , ".min-temp" , ".max-temp" ] ) {
60+ const firstCell = await page . locator ( `.weather .weather-forecast-row:nth-child(1) ${ column } ` ) . boundingBox ( ) ;
61+ const secondCell = await page . locator ( `.weather .weather-forecast-row:nth-child(2) ${ column } ` ) . boundingBox ( ) ;
62+ expect ( firstCell . x ) . toBe ( secondCell . x ) ;
63+ }
64+ } ) ;
5765 } ) ;
5866
5967 describe ( "Absolute configuration" , ( ) => {
@@ -65,7 +73,7 @@ describe("Weather module: Weather Forecast", () => {
6573 const days = [ "Fri" , "Sat" , "Sun" , "Mon" , "Tue" ] ;
6674 for ( const [ index , day ] of days . entries ( ) ) {
6775 it ( `should render day ${ day } ` , async ( ) => {
68- const dayCell = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } ) td:nth-child(1) ` ) ;
76+ const dayCell = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } ) .day ` ) ;
6977 await expect ( dayCell ) . toHaveText ( day ) ;
7078 } ) ;
7179 }
@@ -78,27 +86,55 @@ describe("Weather module: Weather Forecast", () => {
7886 } ) ;
7987
8088 it ( "should render custom table class" , async ( ) => {
81- await expect ( page . locator ( ".weather table .myTableClass.weather-forecast" ) ) . toBeVisible ( ) ;
89+ await expect ( page . locator ( ".weather .myTableClass.weather-forecast" ) ) . toBeVisible ( ) ;
8290 } ) ;
8391
8492 it ( "should render colored rows" , async ( ) => {
85- const rows = page . locator ( ".weather table .myTableClass tr " ) ;
93+ const rows = page . locator ( ".weather .myTableClass.weather-forecast .weather-forecast-row " ) ;
8694 await expect ( rows ) . toHaveCount ( 5 ) ;
8795 } ) ;
8896
97+ it ( "should align optional columns across rows" , async ( ) => {
98+ for ( const column of [ ".precipitation-amount" ] ) {
99+ const firstCell = await page . locator ( `.weather .myTableClass.weather-forecast .weather-forecast-row:nth-child(1) ${ column } ` ) . boundingBox ( ) ;
100+ const secondCell = await page . locator ( `.weather .myTableClass.weather-forecast .weather-forecast-row:nth-child(2) ${ column } ` ) . boundingBox ( ) ;
101+ const firstRow = await page . locator ( ".weather .myTableClass.weather-forecast .weather-forecast-row:nth-child(1)" ) . boundingBox ( ) ;
102+ const secondRow = await page . locator ( ".weather .myTableClass.weather-forecast .weather-forecast-row:nth-child(2)" ) . boundingBox ( ) ;
103+ expect ( firstCell . x ) . toBe ( secondCell . x ) ;
104+ expect ( firstCell . y ) . toBe ( firstRow . y ) ;
105+ expect ( secondCell . y ) . toBe ( secondRow . y ) ;
106+ }
107+ } ) ;
108+
89109 it ( "should expose forecast column order through CSS" , async ( ) => {
90- const minTempCell = page . locator ( ".weather table .myTableClass tr :first-child td .min-temp" ) ;
91- const maxTempCell = page . locator ( ".weather table .myTableClass tr :first-child td .max-temp" ) ;
110+ const minTempCell = page . locator ( ".weather .myTableClass.weather-forecast .weather-forecast-row :first-child .min-temp" ) ;
111+ const maxTempCell = page . locator ( ".weather .myTableClass.weather-forecast .weather-forecast-row :first-child .max-temp" ) ;
92112
93113 await expect ( minTempCell ) . toHaveCSS ( "order" , "3" ) ;
94114 await expect ( maxTempCell ) . toHaveCSS ( "order" , "4" ) ;
115+
116+ await page . addStyleTag ( {
117+ content : `
118+ .weather .myTableClass.weather-forecast {
119+ --weather-forecast-min-temp-order: 4;
120+ --weather-forecast-max-temp-order: 3;
121+ }
122+ `
123+ } ) ;
124+
125+ await expect ( minTempCell ) . toHaveCSS ( "order" , "4" ) ;
126+ await expect ( maxTempCell ) . toHaveCSS ( "order" , "3" ) ;
127+
128+ const minTempBox = await minTempCell . boundingBox ( ) ;
129+ const maxTempBox = await maxTempCell . boundingBox ( ) ;
130+ expect ( minTempBox . x - ( maxTempBox . x + maxTempBox . width ) ) . toBe ( 25 ) ;
95131 } ) ;
96132
97133 const precipitations = [ undefined , "2.51 mm" ] ;
98134 for ( const [ index , precipitation ] of precipitations . entries ( ) ) {
99135 if ( precipitation ) {
100136 it ( `should render precipitation amount ${ precipitation } ` , async ( ) => {
101- const precipCell = page . locator ( `.weather table tr :nth-child(${ index + 1 } ) td .precipitation-amount` ) ;
137+ const precipCell = page . locator ( `.weather .myTableClass.weather-forecast .weather-forecast-row :nth-child(${ index + 1 } ) .precipitation-amount` ) ;
102138 await expect ( precipCell ) . toHaveText ( precipitation ) ;
103139 } ) ;
104140 }
@@ -115,7 +151,7 @@ describe("Weather module: Weather Forecast", () => {
115151 const temperatures = [ "75_9°" , "69_8°" , "73_2°" , "74_1°" , "69_1°" ] ;
116152 for ( const [ index , temp ] of temperatures . entries ( ) ) {
117153 it ( `should render custom decimalSymbol = '_' for temp ${ temp } ` , async ( ) => {
118- const tempCell = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } ) td .max-temp` ) ;
154+ const tempCell = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } ) .max-temp` ) ;
119155 await expect ( tempCell ) . toHaveText ( temp ) ;
120156 } ) ;
121157 }
@@ -126,7 +162,7 @@ describe("Weather module: Weather Forecast", () => {
126162 for ( const [ index , precipitation ] of precipitations . entries ( ) ) {
127163 if ( precipitation ) {
128164 it ( `should render precipitation amount ${ precipitation } ` , async ( ) => {
129- const precipCell = page . locator ( `.weather table.small tr :nth-child(${ index + 1 } ) td .precipitation-amount` ) ;
165+ const precipCell = page . locator ( `.weather .weather-forecast-row :nth-child(${ index + 1 } ) .precipitation-amount` ) ;
130166 await expect ( precipCell ) . toHaveText ( precipitation ) ;
131167 } ) ;
132168 }
0 commit comments