Repository navigation
fix(dashrate): decode grouped-count rating keys for protocol v14 #122
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
Open
thephez
wants to merge
1
commit into
main
Choose a base branch
from
fix/dashrate-grouped-count-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { test, expect, type Page } from "./fixtures"; | ||
| import { test as liteTest } from "@playwright/test"; | ||
|
|
||
| // Live rating-consistency checks against testnet. Unlike the smoke specs, | ||
| // these DO read live rating data, but only assert an invariant that holds | ||
| // for any data: the per-star distribution (grouped `count` by rating) must | ||
| // sum to the total review count (ungrouped `count`). Both come from separate | ||
| // queries, so a change in how Platform keys grouped-count results (e.g. the | ||
| // PV14 index-key encoding change, dashpay/platform#5350) shows up here as a | ||
| // non-zero total with an all-zero distribution. | ||
| // | ||
| // The default contract's reviews can't be deleted (`canBeDeleted: false`), | ||
| // so at least one resource always has reviews to check. | ||
|
|
||
| const LOAD_TIMEOUT = 90_000; | ||
|
|
||
| function parseCount(text: string): number { | ||
| const match = /(\d+)\s+reviews?/.exec(text); | ||
| return match ? Number(match[1]) : 0; | ||
| } | ||
|
|
||
| async function sumCounts(page: Page, selector: string): Promise<number> { | ||
| const texts = await page.locator(selector).allTextContents(); | ||
| return texts.reduce((sum, text) => sum + (parseInt(text, 10) || 0), 0); | ||
| } | ||
|
|
||
| test.describe("rating consistency (app)", () => { | ||
| test("resources with reviews show a rating, and the distribution sums to the total", async ({ | ||
| page, | ||
| }) => { | ||
| const sidebar = page.locator('aside[aria-label="Tutorial resources"]'); | ||
| const rated = sidebar.locator("small.rating-present"); | ||
| await expect(rated.first()).toBeVisible({ timeout: LOAD_TIMEOUT }); | ||
|
|
||
| // A card counted as having reviews (total > 0) must not fall back to | ||
| // "No reviews yet", which it does when the distribution is all zero. | ||
| for (const card of await rated.all()) { | ||
| await expect(card).not.toContainText("No reviews yet"); | ||
| } | ||
|
|
||
| await sidebar | ||
| .locator("button.resource-card") | ||
| .filter({ has: page.locator("small.rating-present") }) | ||
| .first() | ||
| .click(); | ||
|
|
||
| const stats = page.locator('[aria-label="Aggregate rating stats"]'); | ||
| await expect(stats.locator(".detail-rating-score")).not.toHaveText("—", { | ||
| timeout: LOAD_TIMEOUT, | ||
| }); | ||
| const total = parseCount( | ||
| (await stats.locator(".detail-rating-count").textContent()) ?? "", | ||
| ); | ||
| expect(total).toBeGreaterThan(0); | ||
| await expect | ||
| .poll(() => sumCounts(page, ".rating-histogram .histogram-count"), { | ||
| timeout: LOAD_TIMEOUT, | ||
| }) | ||
| .toBe(total); | ||
| }); | ||
| }); | ||
|
|
||
| liteTest.describe("rating consistency (dashrate-lite)", () => { | ||
| liteTest( | ||
| "the distribution sums to the total for a resource with reviews", | ||
| async ({ page }) => { | ||
| liteTest.setTimeout(240_000); | ||
| await page.goto("/dashrate-lite.html"); | ||
| await expect(page.locator("#status")).toHaveText(/Connected to testnet/, { | ||
| timeout: LOAD_TIMEOUT, | ||
| }); | ||
|
|
||
| const grid = page.locator("#aggregate-result .summary-grid"); | ||
| const navButtons = page.locator( | ||
| 'nav[aria-label="Tutorial resources"] button', | ||
| ); | ||
| let checked = false; | ||
| for (const button of await navButtons.all()) { | ||
| await button.click(); | ||
| await expect(grid).toBeVisible({ timeout: LOAD_TIMEOUT }); | ||
| const total = parseCount( | ||
| (await grid.locator(".score .label").textContent()) ?? "", | ||
| ); | ||
| if (total === 0) continue; | ||
|
|
||
| await expect(grid.locator(".score .value")).not.toHaveText("-"); | ||
| expect( | ||
| await sumCounts(page, "#aggregate-result .dist-row .muted"), | ||
| ).toBe(total); | ||
| checked = true; | ||
| break; | ||
| } | ||
| expect(checked, "expected at least one resource with reviews").toBe(true); | ||
| }, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Increase the app test timeout.
If testnet ratings take more than 30 seconds to load, Playwright ends this test before the 90-second assertion timeout expires. Set a test timeout that covers the intended wait, as the lite test does. (raw.githubusercontent.com)