|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +// Copyright (c) 2026, The OpenROAD Authors |
| 3 | + |
| 4 | +import './setup-dom.js'; |
| 5 | +import { describe, it } from 'node:test'; |
| 6 | +import assert from 'node:assert/strict'; |
| 7 | +import { TimingWidget } from '../../src/timing-widget.js'; |
| 8 | + |
| 9 | +// jsdom does not implement scrollIntoView; stub it so _selectPathRow runs. |
| 10 | +if (!window.HTMLElement.prototype.scrollIntoView) { |
| 11 | + window.HTMLElement.prototype.scrollIntoView = function () {}; |
| 12 | +} |
| 13 | + |
| 14 | +// Build an app stub that records every websocketManager.request call and |
| 15 | +// lets each test control the response per message type. |
| 16 | +function createMockApp(responses = {}) { |
| 17 | + const requests = []; |
| 18 | + return { |
| 19 | + requests, |
| 20 | + websocketManager: { |
| 21 | + request(msg) { |
| 22 | + requests.push(msg); |
| 23 | + const handler = responses[msg.type]; |
| 24 | + const value = handler ? handler(msg) : {}; |
| 25 | + return Promise.resolve(value); |
| 26 | + }, |
| 27 | + }, |
| 28 | + }; |
| 29 | +} |
| 30 | + |
| 31 | +function makePath(slack, endPin, extra = {}) { |
| 32 | + return { |
| 33 | + start_clk: 'clk', end_clk: 'clk', |
| 34 | + slack, arrival: 0, required: 0, skew: 0, |
| 35 | + path_delay: 0, logic_depth: 0, fanout: 1, |
| 36 | + start_pin: 'start', end_pin: endPin, |
| 37 | + data_nodes: [], capture_nodes: [], |
| 38 | + ...extra, |
| 39 | + }; |
| 40 | +} |
| 41 | + |
| 42 | +describe('TimingWidget._selectPathRow', () => { |
| 43 | + it('sends timing_highlight with the row index when paths are unfiltered', () => { |
| 44 | + const app = createMockApp(); |
| 45 | + const widget = new TimingWidget(app, () => {}); |
| 46 | + widget.showPaths('setup', [ |
| 47 | + makePath(-0.1, 'a'), |
| 48 | + makePath(0.0, 'b'), |
| 49 | + makePath(0.1, 'c'), |
| 50 | + ]); |
| 51 | + |
| 52 | + // Clear requests from showPaths' _clearTimingHighlight. |
| 53 | + app.requests.length = 0; |
| 54 | + |
| 55 | + widget._selectPathRow(1); |
| 56 | + |
| 57 | + const highlight = app.requests.find(r => r.type === 'timing_highlight'); |
| 58 | + assert.ok(highlight, 'timing_highlight was requested'); |
| 59 | + assert.equal(highlight.path_index, 1); |
| 60 | + assert.equal(highlight.is_setup, 1); |
| 61 | + }); |
| 62 | + |
| 63 | + it('sends timing_highlight with _originalIndex when paths were filtered', () => { |
| 64 | + const app = createMockApp(); |
| 65 | + const widget = new TimingWidget(app, () => {}); |
| 66 | + // Filtered result — table row 0 maps to original overlay index 2. |
| 67 | + widget.showPaths('setup', [ |
| 68 | + { ...makePath(0.0, 'b'), _originalIndex: 2 }, |
| 69 | + { ...makePath(0.05, 'c'), _originalIndex: 4 }, |
| 70 | + ]); |
| 71 | + |
| 72 | + app.requests.length = 0; |
| 73 | + |
| 74 | + widget._selectPathRow(0); |
| 75 | + let highlight = app.requests.find(r => r.type === 'timing_highlight'); |
| 76 | + assert.equal(highlight.path_index, 2); |
| 77 | + |
| 78 | + app.requests.length = 0; |
| 79 | + widget._selectPathRow(1); |
| 80 | + highlight = app.requests.find(r => r.type === 'timing_highlight'); |
| 81 | + assert.equal(highlight.path_index, 4); |
| 82 | + }); |
| 83 | + |
| 84 | + it('uses hold side flag when current tab is hold', () => { |
| 85 | + const app = createMockApp(); |
| 86 | + const widget = new TimingWidget(app, () => {}); |
| 87 | + widget.showPaths('hold', [ |
| 88 | + { ...makePath(0.1, 'h0'), _originalIndex: 3 }, |
| 89 | + ]); |
| 90 | + |
| 91 | + app.requests.length = 0; |
| 92 | + widget._selectPathRow(0); |
| 93 | + |
| 94 | + const highlight = app.requests.find(r => r.type === 'timing_highlight'); |
| 95 | + assert.equal(highlight.path_index, 3); |
| 96 | + assert.equal(highlight.is_setup, 0); |
| 97 | + }); |
| 98 | + |
| 99 | + it('ignores out-of-range indices without sending a request', () => { |
| 100 | + const app = createMockApp(); |
| 101 | + const widget = new TimingWidget(app, () => {}); |
| 102 | + widget.showPaths('setup', [makePath(0.0, 'a')]); |
| 103 | + |
| 104 | + app.requests.length = 0; |
| 105 | + widget._selectPathRow(-1); |
| 106 | + widget._selectPathRow(5); |
| 107 | + |
| 108 | + assert.equal( |
| 109 | + app.requests.filter(r => r.type === 'timing_highlight').length, 0); |
| 110 | + }); |
| 111 | +}); |
0 commit comments