@@ -23,8 +23,8 @@ import {
2323 FeatureWPTMetricViewType ,
2424 WPTRunMetric ,
2525} from '../../api/client.js' ;
26- import { WebstatusLineChartPanel } from '../webstatus-line-chart-panel.js' ;
2726import '../webstatus-feature-wpt-progress-chart-panel.js' ;
27+ import { WebstatusLineChartTabbedPanel } from '../webstatus-line-chart-tabbed-panel.js' ;
2828
2929const startDate = new Date ( '2024-01-01' ) ;
3030const endDate = new Date ( '2024-01-31' ) ;
@@ -46,21 +46,21 @@ async function createFixtureElement(
4646describe ( 'WebstatusFeatureWPTProgressChartPanel' , ( ) => {
4747 let el : WebstatusFeatureWPTProgressChartPanel ;
4848 let apiClientStub : SinonStubbedInstance < APIClient > ;
49- let fetchAndAggregateDataStub : SinonStub ;
49+ let populateDataForChartByViewStub : SinonStub ;
5050
5151 beforeEach ( async ( ) => {
5252 apiClientStub = stub ( new APIClient ( '' ) ) ;
53- fetchAndAggregateDataStub = stub (
54- WebstatusLineChartPanel . prototype ,
55- '_fetchAndAggregateData ' ,
53+ populateDataForChartByViewStub = stub (
54+ WebstatusLineChartTabbedPanel . prototype ,
55+ '_populateDataForChartByView ' ,
5656 ) ;
5757 el = await createFixtureElement ( startDate , endDate , DEFAULT_TEST_VIEW ) ;
5858 el . apiClient = apiClientStub ;
5959 await el . updateComplete ;
6060 } ) ;
6161
6262 afterEach ( ( ) => {
63- fetchAndAggregateDataStub . restore ( ) ;
63+ populateDataForChartByViewStub . restore ( ) ;
6464 } ) ;
6565
6666 it ( 'renders the card' , async ( ) => {
@@ -82,12 +82,13 @@ describe('WebstatusFeatureWPTProgressChartPanel', () => {
8282 expect ( el . dataFetchEndDate ) . to . deep . equal ( new Date ( '2024-01-31' ) ) ;
8383 } ) ;
8484
85- it ( 'calls _fetchAndAggregateData with correct configurations' , async ( ) => {
86- expect ( fetchAndAggregateDataStub ) . to . have . been . calledOnce ;
87- const [ fetchFunctionConfigs , additionalSeriesConfigs ] =
88- fetchAndAggregateDataStub . getCall ( 0 ) . args ;
89-
85+ it ( 'calls _populateDataForChartByView with correct configurations' , async ( ) => {
86+ // Call method for both desktop and mobile views.
87+ expect ( populateDataForChartByViewStub ) . to . have . been . calledTwice ;
88+ let [ fetchFunctionConfigs , dataIndex , additionalSeriesConfigs ] =
89+ populateDataForChartByViewStub . getCall ( 0 ) . args ;
9090 expect ( fetchFunctionConfigs . length ) . to . equal ( 4 ) ; // 4 browsers
91+ expect ( dataIndex ) . to . equal ( 0 ) ; // First view index
9192
9293 // Test Chrome configuration
9394 const chromeConfig = fetchFunctionConfigs [ 0 ] ;
@@ -158,10 +159,64 @@ describe('WebstatusFeatureWPTProgressChartPanel', () => {
158159 new Date ( '2024-01-01T13:00:00.000Z' ) , // Expecting the rounded timestamp
159160 ) ;
160161 expect ( totalConfig . valueExtractor ( totalTestDataPoint ) ) . to . equal ( 15 ) ;
162+
163+ [ fetchFunctionConfigs , dataIndex , additionalSeriesConfigs ] =
164+ populateDataForChartByViewStub . getCall ( 1 ) . args ;
165+
166+ expect ( fetchFunctionConfigs . length ) . to . equal ( 3 ) ; // 3 browsers
167+ expect ( dataIndex ) . to . equal ( 1 ) ; // Second view index
168+
169+ // Test Chrome Android configuration
170+ const chromeAndroidConfig = fetchFunctionConfigs [ 0 ] ;
171+ expect ( chromeAndroidConfig . label ) . to . equal ( 'Chrome Android' ) ;
172+ expect ( chromeAndroidConfig . fetchFunction ) . to . be . a ( 'function' ) ;
173+ const chromeAndroidTestDataPoint : WPTRunMetric = {
174+ run_timestamp : '2024-01-01T12:34:56.789Z' ,
175+ total_tests_count : 10 ,
176+ test_pass_count : 5 ,
177+ } ;
178+ expect (
179+ chromeAndroidConfig . timestampExtractor ( chromeAndroidTestDataPoint ) ,
180+ ) . to . deep . equal (
181+ new Date ( '2024-01-01T13:00:00.000Z' ) , // Expecting the rounded timestamp
182+ ) ;
183+ expect (
184+ chromeAndroidConfig . valueExtractor ( chromeAndroidTestDataPoint ) ,
185+ ) . to . equal ( 5 ) ;
186+
187+ // Test Firefox Android configuration
188+ const firefoxAndroidConfig = fetchFunctionConfigs [ 1 ] ;
189+ expect ( firefoxAndroidConfig . label ) . to . equal ( 'Firefox Android' ) ;
190+ expect ( firefoxAndroidConfig . fetchFunction ) . to . be . a ( 'function' ) ;
191+ const firefoxAndroidTestDataPoint : WPTRunMetric = {
192+ run_timestamp : '2024-01-01' ,
193+ total_tests_count : 12 ,
194+ test_pass_count : 7 ,
195+ } ;
196+ expect (
197+ firefoxAndroidConfig . timestampExtractor ( firefoxAndroidTestDataPoint ) ,
198+ ) . to . deep . equal ( new Date ( '2024-01-01' ) ) ;
199+ expect (
200+ firefoxAndroidConfig . valueExtractor ( firefoxAndroidTestDataPoint ) ,
201+ ) . to . equal ( 7 ) ;
202+
203+ // Test Safari iOS configuration
204+ const safariIosConfig = fetchFunctionConfigs [ 2 ] ;
205+ expect ( safariIosConfig . label ) . to . equal ( 'Safari iOS' ) ;
206+ expect ( safariIosConfig . fetchFunction ) . to . be . a ( 'function' ) ;
207+ const safariIosTestDataPoint : WPTRunMetric = {
208+ run_timestamp : '2024-01-01' ,
209+ total_tests_count : 8 ,
210+ test_pass_count : 3 ,
211+ } ;
212+ expect (
213+ safariIosConfig . timestampExtractor ( safariIosTestDataPoint ) ,
214+ ) . to . deep . equal ( new Date ( '2024-01-01' ) ) ;
215+ expect ( safariIosConfig . valueExtractor ( safariIosTestDataPoint ) ) . to . equal ( 3 ) ;
161216 } ) ;
162217
163218 it ( 'generates chart options correctly' , ( ) => {
164- const options = el . generateDisplayDataChartOptions ( ) ;
219+ const options = el . generateDisplayDataChartOptionsByView ( 0 ) ;
165220 // Check colors based on browsers displayed.
166221 // 4 browsers and total.
167222 expect ( options . colors ) . eql ( [
@@ -180,30 +235,32 @@ describe('WebstatusFeatureWPTProgressChartPanel', () => {
180235
181236 describe ( 'metric view specific tests' , ( ) => {
182237 it ( 'generates metric view specific chart options correctly when view=test' , async ( ) => {
183- fetchAndAggregateDataStub . reset ( ) ;
238+ populateDataForChartByViewStub . reset ( ) ;
184239 el = await createFixtureElement ( startDate , endDate , 'test_counts' ) ;
185240 el . apiClient = apiClientStub ;
186241 await el . updateComplete ;
187- const options = el . generateDisplayDataChartOptions ( ) ;
242+ const options = el . generateDisplayDataChartOptionsByView ( 0 ) ;
188243 expect ( options . vAxis ?. title ) . to . equal ( 'Number of tests passed' ) ;
189- expect ( fetchAndAggregateDataStub ) . to . have . been . calledOnce ;
244+ // Call method for both desktop and mobile views.
245+ expect ( populateDataForChartByViewStub ) . to . have . been . calledTwice ;
190246 const additionalSeriesConfigs =
191- fetchAndAggregateDataStub . getCall ( 0 ) . args [ 1 ] ;
247+ populateDataForChartByViewStub . getCall ( 0 ) . args [ 2 ] ;
192248 // Check additional series configurations
193249 expect ( additionalSeriesConfigs ) . to . have . lengthOf ( 1 ) ;
194250 const totalConfig = additionalSeriesConfigs [ 0 ] ;
195251 expect ( totalConfig . label ) . to . equal ( 'Total number of tests' ) ;
196252 } ) ;
197253 it ( 'generates metric view specific chart options correctly when view=subtest' , async ( ) => {
198- fetchAndAggregateDataStub . reset ( ) ;
254+ populateDataForChartByViewStub . reset ( ) ;
199255 el = await createFixtureElement ( startDate , endDate , 'subtest_counts' ) ;
200256 el . apiClient = apiClientStub ;
201257 await el . updateComplete ;
202- const options = el . generateDisplayDataChartOptions ( ) ;
258+ const options = el . generateDisplayDataChartOptionsByView ( 0 ) ;
203259 expect ( options . vAxis ?. title ) . to . equal ( 'Number of subtests passed' ) ;
204- expect ( fetchAndAggregateDataStub ) . to . have . been . calledOnce ;
260+ // Call method for both desktop and mobile views.
261+ expect ( populateDataForChartByViewStub ) . to . have . been . calledTwice ;
205262 const additionalSeriesConfigs =
206- fetchAndAggregateDataStub . getCall ( 0 ) . args [ 1 ] ;
263+ populateDataForChartByViewStub . getCall ( 0 ) . args [ 2 ] ;
207264 // Check additional series configurations
208265 expect ( additionalSeriesConfigs ) . to . have . lengthOf ( 1 ) ;
209266 const totalConfig = additionalSeriesConfigs [ 0 ] ;
0 commit comments