Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new usage chart to the feature detail page #944

Merged
merged 11 commits into from
Dec 10, 2024
20 changes: 20 additions & 0 deletions e2e/tests/feature-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ test('matches the screenshot', async ({page}) => {
await expect(pageContainer).toHaveScreenshot();
});

// TODO: Remove this test once the usage chart is enabled by default.
test('matches the screenshot with usage chart', async ({page}) => {
await page.goto('http://localhost:5555/features/odit64?showUsageChart');
DanielRyanSmith marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use hyphens to separate the words: show-usage-chart [1]

[1] https://developers.google.com/search/docs/crawling-indexing/url-structure


// Wait for the chart container to exist
await page.waitForSelector('#feature-support-chart-container');

// Wait for the usage chart container to exist
await page.waitForSelector('#feature-usage-chart-container');

// Wait specifically for the "Baseline since" text
await page.waitForSelector('sl-card.wptScore .avail >> text=Baseline since');

// Wait for the loading overlay to disappear
await page.waitForSelector('.spinner-container', {state: 'detached'});

const pageContainer = page.locator('.page-container');
await expect(pageContainer).toHaveScreenshot();
});

test('chart width resizes with window', async ({page}) => {
await page.goto('http://localhost:5555/features/odit64');
await page.waitForSelector('#feature-support-chart-container');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions frontend/src/static/js/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ const DEFAULT_TEST_VIEW: components['schemas']['WPTMetricView'] =

export type WPTRunMetric = components['schemas']['WPTRunMetric'];
export type WPTRunMetricsPage = components['schemas']['WPTRunMetricsPage'];
export type ChromiumUsageStat = components['schemas']['ChromiumUsageStat'];
export type ChromiumDailyUsageStatsPage =
components['schemas']['ChromiumDailyStatsPage'];
export type BrowserReleaseFeatureMetric =
components['schemas']['BrowserReleaseFeatureMetric'];
export type BrowserReleaseFeatureMetricsPage =
Expand Down Expand Up @@ -359,6 +362,38 @@ export class APIClient {
} while (nextPageToken !== undefined);
}

public async *getChromiumDailyUsageStats(
featureId: string,
startAtDate: Date,
endAtDate: Date,
): AsyncIterable<ChromiumUsageStat[]> {
const startAt: string = startAtDate.toISOString().substring(0, 10);
const endAt: string = endAtDate.toISOString().substring(0, 10);
let nextPageToken;
do {
const response = await this.client.GET(
'/v1/features/{feature_id}/stats/usage/chromium/daily_stats',
{
...temporaryFetchOptions,
params: {
query: {startAt, endAt, page_token: nextPageToken},
path: {
feature_id: featureId,
},
},
},
);
const error = response.error;
if (error !== undefined) {
throw createAPIError(error);
}
const page: ChromiumDailyUsageStatsPage =
response.data as ChromiumDailyUsageStatsPage;
nextPageToken = page?.metadata?.next_page_token;
yield page.data;
} while (nextPageToken !== undefined);
}

// Fetches feature counts for a browser in a date range
// via "/v1/stats/features/browsers/{browser}/feature_counts"
public async *getFeatureCountsForBrowser(
Expand Down
Loading
Loading