-
Notifications
You must be signed in to change notification settings - Fork 131
[web-console] Sort metrics lexicographically inside each block #6474
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
Karakatiza666
wants to merge
1
commit into
main
Choose a base branch
from
issue6406
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
47 changes: 47 additions & 0 deletions
47
js-packages/profiler-layout/src/lib/components/metrics/dispatch.test.ts
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,47 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import type { NodeAttributes, TooltipRow } from 'profiler-lib' | ||
| import { buildBlocks } from './dispatch.js' | ||
|
|
||
| function row(metric: string): TooltipRow { | ||
| return { metric, isCurrentMetric: false, cells: [] } | ||
| } | ||
|
|
||
| function makeAttrs(metrics: string[]): NodeAttributes { | ||
| return { | ||
| title: 'n op', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot guess what this is |
||
| columns: [], | ||
| rows: metrics.map(row), | ||
| attributes: new Map() | ||
| } | ||
| } | ||
|
|
||
| describe('buildBlocks', () => { | ||
| it('orders metrics lexicographically inside each block (case-insensitive)', () => { | ||
| // Metric IDs span categories; the order is intentionally scrambled to confirm the sort. | ||
| const attrs = makeAttrs([ | ||
| 'zeta_seconds', | ||
| 'Alpha_count', | ||
| 'gamma_size', | ||
| 'alpha_total' | ||
| ]) | ||
| const blocks = buildBlocks(attrs, /* showAdvanced */ true) | ||
| // All metrics fall into the same "Other" bucket (no descriptions registered), | ||
| // so we expect a single block whose entries are alphabetised by label. | ||
| const all = blocks.flatMap((b) => b.entries.map((e) => e.label)) | ||
| const sorted = [...all].sort((a, b) => | ||
| new Intl.Collator(undefined, { sensitivity: 'base', numeric: true }).compare(a, b) | ||
| ) | ||
| expect(all).toEqual(sorted) | ||
| // Sanity: the original input was not already sorted. | ||
| expect(attrs.rows.map((r) => r.metric)).not.toEqual(sorted) | ||
| }) | ||
|
|
||
| it('uses natural-number ordering, not raw codepoint order', () => { | ||
| // Labels like "slot 2" / "slot 10" share a numeric suffix; a plain ASCII sort would put | ||
| // "slot 10" before "slot 2". | ||
| const attrs = makeAttrs(['slot_10_loose', 'slot_2_loose', 'slot_1_loose']) | ||
| const blocks = buildBlocks(attrs, true) | ||
| const labels = blocks.flatMap((b) => b.entries.map((e) => e.label)) | ||
| expect(labels).toEqual(['Slot 1 loose', 'Slot 2 loose', 'Slot 10 loose']) | ||
| }) | ||
| }) | ||
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.
Nit:
jsdomis added to devDependencies, butvitest.config.tsalready runs in real Chromium via@vitest/browser-playwrightand this test only exercises pure logic. Isjsdomactually required by something, or can this dep be dropped?