|
| 1 | +/** |
| 2 | + * Hover a chart point until its tooltip opens, then assert the tooltip text. |
| 3 | + * The D3 charts re-render after the container is measured, which can detach |
| 4 | + * the hovered point (so the first synthetic mouseenter is lost) and can hide |
| 5 | + * the tooltip again before a retrying `:visible` assertion samples it — so |
| 6 | + * re-trigger (bounded) and assert the content at the moment it is displayed. |
| 7 | + */ |
| 8 | +function hoverGpuSpecsPointAndAssertTooltip( |
| 9 | + pointSelector: string, |
| 10 | + tooltipSelector: string, |
| 11 | + expectedTexts: string[], |
| 12 | + attempts = 20, |
| 13 | +) { |
| 14 | + cy.get(pointSelector).first().trigger('mouseenter', { force: true }); |
| 15 | + cy.document().then((doc) => { |
| 16 | + const tip = doc.querySelector<HTMLElement>(tooltipSelector); |
| 17 | + if (tip && tip.style.display === 'block') { |
| 18 | + for (const text of expectedTexts) { |
| 19 | + expect(tip.textContent, `tooltip ${tooltipSelector}`).to.include(text); |
| 20 | + } |
| 21 | + } else if (attempts > 0) { |
| 22 | + cy.wait(200); |
| 23 | + hoverGpuSpecsPointAndAssertTooltip( |
| 24 | + pointSelector, |
| 25 | + tooltipSelector, |
| 26 | + expectedTexts, |
| 27 | + attempts - 1, |
| 28 | + ); |
| 29 | + } else { |
| 30 | + throw new Error(`tooltip ${tooltipSelector} never became visible`); |
| 31 | + } |
| 32 | + }); |
| 33 | +} |
| 34 | + |
1 | 35 | describe('GPU Specs Tab', () => { |
2 | 36 | before(() => { |
3 | 37 | cy.window().then((win) => { |
@@ -526,17 +560,19 @@ describe('GPU Specs Chinese route', () => { |
526 | 560 | .should('contain.text', '指标:') |
527 | 561 | .and('contain.text', '悬停柱形可查看详情'); |
528 | 562 | cy.get('[data-testid="gpu-specs-bar-d3-chart"] svg').should('contain.text', '显存容量 (GB)'); |
529 | | - cy.get('[data-testid="gpu-specs-bar-d3-chart"] svg .bar') |
530 | | - .first() |
531 | | - .trigger('mouseenter', { force: true }); |
532 | | - cy.get('[data-chart-tooltip]:visible').should('contain.text', '显存容量:'); |
| 563 | + hoverGpuSpecsPointAndAssertTooltip( |
| 564 | + '[data-testid="gpu-specs-bar-d3-chart"] svg .bar', |
| 565 | + '[data-chart-tooltip="gpu-specs-bar-chart"]', |
| 566 | + ['显存容量:'], |
| 567 | + ); |
533 | 568 | cy.get('[data-testid="gpu-specs-radar-view-btn"]').click({ force: true }); |
534 | 569 | cy.get('[data-testid="gpu-specs-radar-chart"] svg').should('contain.text', '显存容量'); |
535 | 570 | cy.get('[data-testid="gpu-specs-radar-chart"]').should('contain.text', '归一化'); |
536 | | - cy.get('[data-testid="gpu-specs-radar-chart"] svg .radar-dot') |
537 | | - .first() |
538 | | - .trigger('mouseenter', { force: true }); |
539 | | - cy.get('[data-chart-tooltip]:visible').should('contain.text', '显存容量:'); |
| 571 | + hoverGpuSpecsPointAndAssertTooltip( |
| 572 | + '[data-testid="gpu-specs-radar-chart"] svg .radar-dot', |
| 573 | + '[data-chart-tooltip="gpu-radar-chart"]', |
| 574 | + ['显存容量:'], |
| 575 | + ); |
540 | 576 | }); |
541 | 577 |
|
542 | 578 | it('supports table, topology, chart, and radar navigation at 1440px', () => { |
|
0 commit comments