Skip to content

Commit 566e364

Browse files
authored
Merge pull request #760 from sipcapture/copilot/fix-ui-bug-src-dst-ports-reversed
Fix transaction call-flow port labels for right-to-left SIP responses
2 parents 101fa9b + c9f51c8 commit 566e364

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { render } from '@testing-library/react'
3+
import { FlowItem } from './FlowItem'
4+
import type { FlowItemData } from './flow-data'
5+
6+
function makeItem(direction: boolean): FlowItemData {
7+
return {
8+
id: '1',
9+
idx: 1,
10+
method: 'INVITE',
11+
description: 'desc',
12+
srcIp: '10.0.0.1',
13+
dstIp: '10.0.0.2',
14+
srcPort: 5060,
15+
dstPort: 5070,
16+
callid: 'c1',
17+
callidColors: {
18+
color: '#000000',
19+
tabColor: '#000000',
20+
arrowColor: '#00ff00',
21+
},
22+
methodColor: '#00ff00',
23+
timeStr: '',
24+
fullDateStr: '',
25+
diffStr: '+0.0ms',
26+
protoLabel: 'UDP',
27+
payloadType: 'SIP',
28+
start: 0,
29+
middle: 1,
30+
rightEnd: 0,
31+
direction,
32+
isRadial: false,
33+
isLastHost: false,
34+
arrowStyleSolid: true,
35+
raw: {},
36+
}
37+
}
38+
39+
describe('FlowItem port labels', () => {
40+
it('shows src on left and dst on right for left-to-right packets', () => {
41+
const { container } = render(
42+
<FlowItem item={makeItem(false)} isSimplify={false} isAbsoluteTime={false} />,
43+
)
44+
45+
expect(container.querySelector('.port-label-left')?.textContent).toBe('5060')
46+
expect(container.querySelector('.port-label-right')?.textContent).toBe('5070')
47+
})
48+
49+
it('shows dst on left and src on right for right-to-left packets', () => {
50+
const { container } = render(
51+
<FlowItem item={makeItem(true)} isSimplify={false} isAbsoluteTime={false} />,
52+
)
53+
54+
expect(container.querySelector('.port-label-left')?.textContent).toBe('5070')
55+
expect(container.querySelector('.port-label-right')?.textContent).toBe('5060')
56+
})
57+
})

src/ui/src/dashboard/flow/FlowItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export function FlowItem({
7474
) : (
7575
<>
7676
<div className={item.direction ? 'port-label-right' : 'port-label-left'}>
77-
{item.direction ? item.dstPort || '' : item.srcPort || ''}
77+
{item.srcPort || ''}
7878
</div>
7979
<div className={item.direction ? 'port-label-left' : 'port-label-right'}>
80-
{item.direction ? item.srcPort || '' : item.dstPort || ''}
80+
{item.dstPort || ''}
8181
</div>
8282
</>
8383
)}

0 commit comments

Comments
 (0)