@parca/profile 0.19.139 → 0.19.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/GraphTooltipArrow/Content.js +224 -30
  3. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.js +192 -33
  4. package/dist/GraphTooltipArrow/ExpandOnHoverValue.js +53 -3
  5. package/dist/GraphTooltipArrow/index.d.ts.map +1 -1
  6. package/dist/GraphTooltipArrow/index.js +86 -56
  7. package/dist/GraphTooltipArrow/useGraphTooltip/index.js +37 -37
  8. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +103 -73
  9. package/dist/MatchersInput/SuggestionItem.js +91 -12
  10. package/dist/MatchersInput/SuggestionsList.d.ts +2 -1
  11. package/dist/MatchersInput/SuggestionsList.d.ts.map +1 -1
  12. package/dist/MatchersInput/SuggestionsList.js +371 -157
  13. package/dist/MatchersInput/SuggestionsList.test.d.ts +2 -0
  14. package/dist/MatchersInput/SuggestionsList.test.d.ts.map +1 -0
  15. package/dist/MatchersInput/index.js +308 -115
  16. package/dist/MetricsCircle/index.js +39 -3
  17. package/dist/MetricsGraph/MetricsContextMenu/index.js +119 -19
  18. package/dist/MetricsGraph/MetricsInfoPanel/index.js +81 -20
  19. package/dist/MetricsGraph/MetricsTooltip/index.d.ts.map +1 -1
  20. package/dist/MetricsGraph/MetricsTooltip/index.js +107 -74
  21. package/dist/MetricsGraph/index.js +552 -203
  22. package/dist/MetricsGraph/useMetricsGraphDimensions.js +46 -25
  23. package/dist/MetricsGraph/utils/colorMapping.js +24 -17
  24. package/dist/MetricsSeries/index.js +70 -7
  25. package/dist/PreSelectedMatchers/index.d.ts.map +1 -1
  26. package/dist/PreSelectedMatchers/index.js +249 -102
  27. package/dist/ProfileExplorer/ProfileExplorerCompare.js +240 -49
  28. package/dist/ProfileExplorer/ProfileExplorerSingle.js +98 -11
  29. package/dist/ProfileExplorer/index.js +183 -32
  30. package/dist/ProfileFlameChart/SamplesStrips/SamplesGraph/index.js +333 -148
  31. package/dist/ProfileFlameChart/SamplesStrips/SamplesStrips.stories.js +69 -35
  32. package/dist/ProfileFlameChart/SamplesStrips/index.js +645 -134
  33. package/dist/ProfileFlameChart/SamplesStrips/labelSetUtils.js +114 -55
  34. package/dist/ProfileFlameChart/index.js +266 -134
  35. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +287 -88
  36. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenuWrapper.js +56 -20
  37. package/dist/ProfileFlameGraph/FlameGraphArrow/FlameGraphNodes.js +211 -140
  38. package/dist/ProfileFlameGraph/FlameGraphArrow/MemoizedTooltip.js +133 -38
  39. package/dist/ProfileFlameGraph/FlameGraphArrow/MiniMap.js +261 -216
  40. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  41. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +71 -45
  42. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.d.ts.map +1 -1
  43. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.js +58 -28
  44. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.d.ts.map +1 -1
  45. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.js +59 -8
  46. package/dist/ProfileFlameGraph/FlameGraphArrow/index.js +396 -179
  47. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.d.ts.map +1 -1
  48. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.js +68 -50
  49. package/dist/ProfileFlameGraph/FlameGraphArrow/useMappingList.js +62 -38
  50. package/dist/ProfileFlameGraph/FlameGraphArrow/useNodeColor.js +14 -6
  51. package/dist/ProfileFlameGraph/FlameGraphArrow/useScrollViewport.js +124 -82
  52. package/dist/ProfileFlameGraph/FlameGraphArrow/useVisibleNodes.js +160 -98
  53. package/dist/ProfileFlameGraph/FlameGraphArrow/useZoom.js +232 -112
  54. package/dist/ProfileFlameGraph/FlameGraphArrow/utils.js +137 -114
  55. package/dist/ProfileFlameGraph/benchmarks/benchdata/populateData.js +85 -0
  56. package/dist/ProfileFlameGraph/index.js +324 -148
  57. package/dist/ProfileMetricsGraph/hooks/useQueryRange.js +140 -32
  58. package/dist/ProfileMetricsGraph/index.js +518 -259
  59. package/dist/ProfileSelector/CompareButton.js +132 -12
  60. package/dist/ProfileSelector/MetricsGraphSection.js +234 -67
  61. package/dist/ProfileSelector/index.d.ts.map +1 -1
  62. package/dist/ProfileSelector/index.js +730 -142
  63. package/dist/ProfileSelector/useAutoQuerySelector.js +249 -130
  64. package/dist/ProfileSource.js +230 -163
  65. package/dist/ProfileTypeSelector/index.js +214 -125
  66. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.js +50 -4
  67. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +139 -33
  68. package/dist/ProfileView/components/ColorStackLegend.js +184 -55
  69. package/dist/ProfileView/components/DashboardItems/index.js +87 -28
  70. package/dist/ProfileView/components/DashboardLayout/index.js +108 -16
  71. package/dist/ProfileView/components/DiffLegend.js +172 -29
  72. package/dist/ProfileView/components/GroupByLabelsDropdown/index.js +199 -55
  73. package/dist/ProfileView/components/InvertCallStack/index.js +99 -10
  74. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +260 -315
  75. package/dist/ProfileView/components/ProfileFilters/index.js +518 -215
  76. package/dist/ProfileView/components/ProfileFilters/useProfileFilters.js +370 -306
  77. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +188 -120
  78. package/dist/ProfileView/components/ProfileHeader/index.js +105 -11
  79. package/dist/ProfileView/components/ShareButton/ResultBox.js +119 -16
  80. package/dist/ProfileView/components/ShareButton/index.js +352 -62
  81. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  82. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +675 -195
  83. package/dist/ProfileView/components/Toolbars/SwitchMenuItem.js +94 -7
  84. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +198 -157
  85. package/dist/ProfileView/components/Toolbars/index.js +441 -21
  86. package/dist/ProfileView/components/ViewSelector/Dropdown.js +233 -22
  87. package/dist/ProfileView/components/ViewSelector/index.js +211 -91
  88. package/dist/ProfileView/components/VisualizationContainer/index.d.ts.map +1 -1
  89. package/dist/ProfileView/components/VisualizationContainer/index.js +52 -7
  90. package/dist/ProfileView/components/VisualizationPanel.js +185 -8
  91. package/dist/ProfileView/context/DashboardContext.js +84 -28
  92. package/dist/ProfileView/context/ProfileViewContext.js +56 -15
  93. package/dist/ProfileView/hooks/useAutoSelectDimension.js +71 -41
  94. package/dist/ProfileView/hooks/useProfileMetadata.js +50 -18
  95. package/dist/ProfileView/hooks/useResetFlameGraphState.js +31 -10
  96. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +72 -29
  97. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +39 -13
  98. package/dist/ProfileView/hooks/useVisualizationState.js +262 -87
  99. package/dist/ProfileView/index.js +383 -45
  100. package/dist/ProfileView/types/visualization.js +1 -13
  101. package/dist/ProfileView/utils/colorUtils.js +8 -7
  102. package/dist/ProfileViewWithData.js +332 -237
  103. package/dist/QueryControls/index.js +418 -47
  104. package/dist/Sandwich/components/CalleesSection.js +54 -4
  105. package/dist/Sandwich/components/CallersSection.js +97 -27
  106. package/dist/Sandwich/components/TableSection.js +77 -4
  107. package/dist/Sandwich/index.js +125 -12
  108. package/dist/Sandwich/utils/processRowData.js +48 -39
  109. package/dist/SelectWithRefresh/index.js +102 -28
  110. package/dist/SimpleMatchers/Select.js +520 -187
  111. package/dist/SimpleMatchers/index.js +590 -288
  112. package/dist/SourceView/Highlighter.js +230 -70
  113. package/dist/SourceView/LineNo.js +72 -17
  114. package/dist/SourceView/index.js +177 -101
  115. package/dist/SourceView/lang-detector/ext-to-lang.json +798 -798
  116. package/dist/SourceView/lang-detector/index.js +28 -14
  117. package/dist/SourceView/useSelectedLineRange.js +97 -16
  118. package/dist/Table/ColorCell.js +42 -1
  119. package/dist/Table/ColumnsVisibility.js +114 -6
  120. package/dist/Table/MoreDropdown.js +121 -27
  121. package/dist/Table/TableContextMenu.js +150 -139
  122. package/dist/Table/TableContextMenuWrapper.js +59 -14
  123. package/dist/Table/hooks/useColorManagement.js +58 -16
  124. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  125. package/dist/Table/hooks/useTableConfiguration.js +331 -168
  126. package/dist/Table/index.js +222 -126
  127. package/dist/Table/utils/functions.js +169 -144
  128. package/dist/Table/utils/topAndBottomExpandedRowModel.js +69 -52
  129. package/dist/TimelineGuide/index.js +209 -16
  130. package/dist/TopTable/benchmarks/benchdata/populateData.js +91 -0
  131. package/dist/TopTable/index.js +340 -122
  132. package/dist/contexts/LabelsQueryProvider.js +94 -32
  133. package/dist/contexts/UnifiedLabelsContext.js +114 -49
  134. package/dist/contexts/utils.js +37 -15
  135. package/dist/hooks/useCompareModeMeta.js +157 -94
  136. package/dist/hooks/useLabels.js +295 -52
  137. package/dist/hooks/useQueryState.js +371 -330
  138. package/dist/index.js +21 -16
  139. package/dist/testdata/fg-diff.json +3750 -0
  140. package/dist/testdata/fg-simple.json +1879 -0
  141. package/dist/testdata/link_data.json +56 -0
  142. package/dist/testdata/tabular.json +30 -0
  143. package/dist/testdata/test_flamegraph.json +26846 -0
  144. package/dist/testdata/test_graph.json +53 -0
  145. package/dist/useDelayedLoader.js +32 -18
  146. package/dist/useGrpcQuery/index.js +71 -11
  147. package/dist/useHasProfileData.js +90 -12
  148. package/dist/useQuery.js +205 -64
  149. package/dist/useSumBy.d.ts.map +1 -1
  150. package/dist/useSumBy.js +294 -138
  151. package/dist/utils.js +62 -30
  152. package/package.json +9 -9
  153. package/src/GraphTooltipArrow/index.tsx +3 -0
  154. package/src/MatchersInput/SuggestionsList.test.tsx +70 -0
  155. package/src/MatchersInput/SuggestionsList.tsx +11 -10
  156. package/src/MatchersInput/index.tsx +1 -1
  157. package/src/MetricsGraph/MetricsTooltip/index.tsx +22 -34
  158. package/src/PreSelectedMatchers/index.tsx +3 -0
  159. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +3 -0
  160. package/src/ProfileFlameGraph/FlameGraphArrow/TooltipContext.tsx +3 -0
  161. package/src/ProfileFlameGraph/FlameGraphArrow/ZoomControls.tsx +3 -0
  162. package/src/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.ts +3 -0
  163. package/src/ProfileSelector/index.tsx +30 -7
  164. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +3 -0
  165. package/src/ProfileView/components/VisualizationContainer/index.tsx +3 -0
  166. package/src/Table/hooks/useTableConfiguration.tsx +7 -13
  167. package/src/useDelayedLoader.ts +10 -10
  168. package/src/useSumBy.ts +12 -18
  169. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +0 -541
  170. package/dist/hooks/useQueryState.test.js +0 -984
@@ -1,541 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- // eslint-disable-next-line import/named
3
- import { act, renderHook, waitFor } from '@testing-library/react';
4
- import { beforeEach, describe, expect, it, vi } from 'vitest';
5
- import { URLStateProvider } from '@parca/components';
6
- import { decodeProfileFilters, useProfileFiltersUrlState } from './useProfileFiltersUrlState';
7
- // Mock window.location
8
- const mockLocation = {
9
- pathname: '/test',
10
- search: '',
11
- };
12
- // Mock the navigate function
13
- const mockNavigateTo = vi.fn((path, params) => {
14
- const searchParams = new URLSearchParams();
15
- Object.entries(params).forEach(([key, value]) => {
16
- if (value !== undefined && value !== null) {
17
- if (Array.isArray(value)) {
18
- searchParams.set(key, value.join(','));
19
- }
20
- else {
21
- searchParams.set(key, String(value));
22
- }
23
- }
24
- });
25
- mockLocation.search = `?${searchParams.toString()}`;
26
- });
27
- // Mock getQueryParamsFromURL
28
- vi.mock('@parca/components/src/hooks/URLState/utils', async () => {
29
- const actual = await vi.importActual('@parca/components/src/hooks/URLState/utils');
30
- return {
31
- ...actual,
32
- getQueryParamsFromURL: () => {
33
- if (mockLocation.search === '')
34
- return {};
35
- const params = new URLSearchParams(mockLocation.search);
36
- const result = {};
37
- for (const [key, value] of params.entries()) {
38
- const decodedValue = decodeURIComponent(value);
39
- const existing = result[key];
40
- if (existing !== undefined) {
41
- result[key] = Array.isArray(existing)
42
- ? [...existing, decodedValue]
43
- : [existing, decodedValue];
44
- }
45
- else {
46
- result[key] = decodedValue;
47
- }
48
- }
49
- return result;
50
- },
51
- };
52
- });
53
- // Helper to create wrapper with URLStateProvider
54
- const createWrapper = () => {
55
- const Wrapper = ({ children }) => (_jsx(URLStateProvider, { navigateTo: mockNavigateTo, children: children }));
56
- Wrapper.displayName = 'URLStateProviderWrapper';
57
- return Wrapper;
58
- };
59
- describe('useProfileFiltersUrlState', () => {
60
- beforeEach(() => {
61
- mockNavigateTo.mockClear();
62
- Object.defineProperty(window, 'location', {
63
- value: mockLocation,
64
- writable: true,
65
- });
66
- mockLocation.search = '';
67
- });
68
- describe('decodeProfileFilters', () => {
69
- it('should return empty array for empty string', () => {
70
- expect(decodeProfileFilters('')).toEqual([]);
71
- });
72
- it('should return empty array for undefined', () => {
73
- expect(decodeProfileFilters(undefined)).toEqual([]);
74
- });
75
- it('should decode stack filter with function_name', () => {
76
- // Format: type:field:match:value -> s:fn:=:testFunc
77
- const encoded = 's:fn:=:testFunc';
78
- const result = decodeProfileFilters(encoded);
79
- expect(result).toHaveLength(1);
80
- expect(result[0]).toMatchObject({
81
- type: 'stack',
82
- field: 'function_name',
83
- matchType: 'equal',
84
- value: 'testFunc',
85
- });
86
- });
87
- it('should decode frame filter with binary', () => {
88
- const encoded = 'f:b:!=:libc.so';
89
- const result = decodeProfileFilters(encoded);
90
- expect(result).toHaveLength(1);
91
- expect(result[0]).toMatchObject({
92
- type: 'frame',
93
- field: 'binary',
94
- matchType: 'not_equal',
95
- value: 'libc.so',
96
- });
97
- });
98
- it('should decode filter with contains match', () => {
99
- const encoded = 's:fn:~:runtime';
100
- const result = decodeProfileFilters(encoded);
101
- expect(result).toHaveLength(1);
102
- expect(result[0]).toMatchObject({
103
- type: 'stack',
104
- field: 'function_name',
105
- matchType: 'contains',
106
- value: 'runtime',
107
- });
108
- });
109
- it('should decode filter with not_contains match', () => {
110
- const encoded = 'f:b:!~:node';
111
- const result = decodeProfileFilters(encoded);
112
- expect(result).toHaveLength(1);
113
- expect(result[0]).toMatchObject({
114
- type: 'frame',
115
- field: 'binary',
116
- matchType: 'not_contains',
117
- value: 'node',
118
- });
119
- });
120
- it('should decode filter with starts_with match', () => {
121
- const encoded = 's:fn:^:std::';
122
- const result = decodeProfileFilters(encoded);
123
- expect(result).toHaveLength(1);
124
- expect(result[0]).toMatchObject({
125
- type: 'stack',
126
- field: 'function_name',
127
- matchType: 'starts_with',
128
- value: 'std::',
129
- });
130
- });
131
- it('should decode filter with not_starts_with match', () => {
132
- const encoded = 'f:fn:!^:tokio::';
133
- const result = decodeProfileFilters(encoded);
134
- expect(result).toHaveLength(1);
135
- expect(result[0]).toMatchObject({
136
- type: 'frame',
137
- field: 'function_name',
138
- matchType: 'not_starts_with',
139
- value: 'tokio::',
140
- });
141
- });
142
- it('should decode multiple filters', () => {
143
- const encoded = 's:fn:=:testFunc,f:b:!=:libc.so';
144
- const result = decodeProfileFilters(encoded);
145
- expect(result).toHaveLength(2);
146
- expect(result[0]).toMatchObject({
147
- type: 'stack',
148
- field: 'function_name',
149
- matchType: 'equal',
150
- value: 'testFunc',
151
- });
152
- expect(result[1]).toMatchObject({
153
- type: 'frame',
154
- field: 'binary',
155
- matchType: 'not_equal',
156
- value: 'libc.so',
157
- });
158
- });
159
- it('should decode preset filter', () => {
160
- const encoded = 'p:hide_libc:enabled';
161
- const result = decodeProfileFilters(encoded);
162
- expect(result).toHaveLength(1);
163
- expect(result[0]).toMatchObject({
164
- type: 'hide_libc',
165
- value: 'enabled',
166
- });
167
- });
168
- it('should handle values with colons', () => {
169
- const encoded = 'p:some_preset:value:with:colons';
170
- const result = decodeProfileFilters(encoded);
171
- expect(result).toHaveLength(1);
172
- expect(result[0]).toMatchObject({
173
- type: 'some_preset',
174
- value: 'value:with:colons',
175
- });
176
- });
177
- it('should decode all field types', () => {
178
- const testCases = [
179
- { encoded: 's:fn:=:test', expectedField: 'function_name' },
180
- { encoded: 's:b:=:test', expectedField: 'binary' },
181
- { encoded: 's:sn:=:test', expectedField: 'system_name' },
182
- { encoded: 's:f:=:test', expectedField: 'filename' },
183
- { encoded: 's:a:=:test', expectedField: 'address' },
184
- { encoded: 's:ln:=:test', expectedField: 'line_number' },
185
- ];
186
- for (const { encoded, expectedField } of testCases) {
187
- const result = decodeProfileFilters(encoded);
188
- expect(result[0].field).toBe(expectedField);
189
- }
190
- });
191
- it('should return empty array for malformed input', () => {
192
- // This should not throw - it returns empty array on error
193
- expect(() => decodeProfileFilters('malformed')).not.toThrow();
194
- });
195
- it('should generate unique IDs for each filter', () => {
196
- const encoded = 's:fn:=:func1,s:fn:=:func2,s:fn:=:func3';
197
- const result = decodeProfileFilters(encoded);
198
- const ids = result.map(f => f.id);
199
- const uniqueIds = new Set(ids);
200
- expect(uniqueIds.size).toBe(ids.length);
201
- });
202
- });
203
- describe('Basic functionality', () => {
204
- it('should initialize with empty filters when no URL params', () => {
205
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
206
- expect(result.current.appliedFilters).toEqual([]);
207
- });
208
- it('should read filters from URL', async () => {
209
- mockLocation.search = '?profile_filters=s:fn:=:testFunc';
210
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
211
- await waitFor(() => {
212
- expect(result.current.appliedFilters).toHaveLength(1);
213
- expect(result.current.appliedFilters[0]).toMatchObject({
214
- type: 'stack',
215
- field: 'function_name',
216
- matchType: 'equal',
217
- value: 'testFunc',
218
- });
219
- });
220
- });
221
- it('should update URL when setting filters', async () => {
222
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
223
- const newFilters = [
224
- {
225
- id: 'test-1',
226
- type: 'frame',
227
- field: 'binary',
228
- matchType: 'not_contains',
229
- value: 'libc.so',
230
- },
231
- ];
232
- act(() => {
233
- result.current.setAppliedFilters(newFilters);
234
- });
235
- await waitFor(() => {
236
- expect(mockNavigateTo).toHaveBeenCalled();
237
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
238
- expect(params.profile_filters).toBe('f:b:!~:libc.so');
239
- });
240
- });
241
- it('should clear URL param when setting empty filters', async () => {
242
- mockLocation.search = '?profile_filters=s:fn:=:testFunc';
243
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
244
- act(() => {
245
- result.current.setAppliedFilters([]);
246
- });
247
- await waitFor(() => {
248
- expect(mockNavigateTo).toHaveBeenCalled();
249
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
250
- // When filters are empty, the param is either empty string or undefined (removed)
251
- expect(params.profile_filters === '' || params.profile_filters === undefined).toBe(true);
252
- });
253
- });
254
- });
255
- describe('forceApplyFilters', () => {
256
- it('should provide forceApplyFilters method', () => {
257
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
258
- expect(typeof result.current.forceApplyFilters).toBe('function');
259
- });
260
- it('should force apply filters overwriting existing', async () => {
261
- mockLocation.search = '?profile_filters=s:fn:=:existingFunc';
262
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
263
- // Verify existing filter is loaded
264
- await waitFor(() => {
265
- expect(result.current.appliedFilters).toHaveLength(1);
266
- });
267
- const newFilters = [
268
- {
269
- id: 'forced-1',
270
- type: 'frame',
271
- field: 'binary',
272
- matchType: 'not_contains',
273
- value: 'forcedValue',
274
- },
275
- ];
276
- act(() => {
277
- result.current.forceApplyFilters(newFilters);
278
- });
279
- await waitFor(() => {
280
- expect(mockNavigateTo).toHaveBeenCalled();
281
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
282
- expect(params.profile_filters).toBe('f:b:!~:forcedValue');
283
- });
284
- });
285
- it('should clear filters when force applying empty array', async () => {
286
- mockLocation.search = '?profile_filters=s:fn:=:existingFunc';
287
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
288
- act(() => {
289
- result.current.forceApplyFilters([]);
290
- });
291
- await waitFor(() => {
292
- expect(mockNavigateTo).toHaveBeenCalled();
293
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
294
- // When filters are empty, the param is either empty string or undefined (removed)
295
- expect(params.profile_filters === '' || params.profile_filters === undefined).toBe(true);
296
- });
297
- });
298
- });
299
- describe('Preset filter encoding', () => {
300
- it('should encode preset filters correctly', async () => {
301
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
302
- const presetFilters = [
303
- {
304
- id: 'preset-1',
305
- type: 'hide_libc',
306
- value: 'enabled',
307
- },
308
- ];
309
- act(() => {
310
- result.current.setAppliedFilters(presetFilters);
311
- });
312
- await waitFor(() => {
313
- expect(mockNavigateTo).toHaveBeenCalled();
314
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
315
- expect(params.profile_filters).toBe('p:hide_libc:enabled');
316
- });
317
- });
318
- it('should handle mixed preset and regular filters', async () => {
319
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
320
- const mixedFilters = [
321
- {
322
- id: 'preset-1',
323
- type: 'hide_libc',
324
- value: 'enabled',
325
- },
326
- {
327
- id: 'regular-1',
328
- type: 'frame',
329
- field: 'binary',
330
- matchType: 'not_contains',
331
- value: 'node',
332
- },
333
- ];
334
- act(() => {
335
- result.current.setAppliedFilters(mixedFilters);
336
- });
337
- await waitFor(() => {
338
- expect(mockNavigateTo).toHaveBeenCalled();
339
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
340
- expect(params.profile_filters).toBe('p:hide_libc:enabled,f:b:!~:node');
341
- });
342
- });
343
- });
344
- describe('URL encoding edge cases', () => {
345
- it('should handle special characters in filter values', async () => {
346
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
347
- const filtersWithSpecialChars = [
348
- {
349
- id: 'special-1',
350
- type: 'stack',
351
- field: 'function_name',
352
- matchType: 'contains',
353
- value: 'std::vector<int>',
354
- },
355
- ];
356
- act(() => {
357
- result.current.setAppliedFilters(filtersWithSpecialChars);
358
- });
359
- await waitFor(() => {
360
- expect(mockNavigateTo).toHaveBeenCalled();
361
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
362
- // Value should be URL encoded
363
- expect(params.profile_filters).toContain('std%3A%3Avector%3Cint%3E');
364
- });
365
- });
366
- it('should filter out incomplete filters when encoding', async () => {
367
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
368
- const incompleteFilters = [
369
- {
370
- id: 'complete-1',
371
- type: 'frame',
372
- field: 'binary',
373
- matchType: 'not_contains',
374
- value: 'valid',
375
- },
376
- {
377
- id: 'incomplete-1',
378
- type: 'frame',
379
- // Missing field, matchType
380
- value: '',
381
- },
382
- {
383
- id: 'incomplete-2',
384
- type: undefined,
385
- value: 'value',
386
- },
387
- ];
388
- act(() => {
389
- result.current.setAppliedFilters(incompleteFilters);
390
- });
391
- await waitFor(() => {
392
- expect(mockNavigateTo).toHaveBeenCalled();
393
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
394
- // Only the complete filter should be encoded
395
- expect(params.profile_filters).toBe('f:b:!~:valid');
396
- });
397
- });
398
- });
399
- describe('Memoization', () => {
400
- it('should return empty array with consistent structure when no filters', () => {
401
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
402
- // Empty filters should be an empty array (not undefined or null)
403
- expect(Array.isArray(result.current.appliedFilters)).toBe(true);
404
- expect(result.current.appliedFilters).toHaveLength(0);
405
- });
406
- it('should always return array (never undefined)', () => {
407
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
408
- expect(Array.isArray(result.current.appliedFilters)).toBe(true);
409
- expect(result.current.appliedFilters).toEqual([]);
410
- });
411
- it('should return correctly structured filters from URL', async () => {
412
- mockLocation.search = '?profile_filters=s:fn:=:testFunc';
413
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
414
- await waitFor(() => {
415
- expect(result.current.appliedFilters).toHaveLength(1);
416
- });
417
- // Verify the filter structure is correct
418
- const filter = result.current.appliedFilters[0];
419
- expect(filter).toHaveProperty('id');
420
- expect(filter).toHaveProperty('type', 'stack');
421
- expect(filter).toHaveProperty('field', 'function_name');
422
- expect(filter).toHaveProperty('matchType', 'equal');
423
- // eslint-disable-next-line jest-dom/prefer-to-have-value
424
- expect(filter).toHaveProperty('value', 'testFunc');
425
- });
426
- });
427
- describe('View switching scenarios', () => {
428
- it('should completely replace filters when switching views using forceApplyFilters', async () => {
429
- // Start with View A's filters (2 filters)
430
- mockLocation.search = '?profile_filters=s:fn:=:viewAFunc,f:b:!=:viewABinary';
431
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
432
- await waitFor(() => {
433
- expect(result.current.appliedFilters).toHaveLength(2);
434
- expect(result.current.appliedFilters[0].value).toBe('viewAFunc');
435
- expect(result.current.appliedFilters[1].value).toBe('viewABinary');
436
- });
437
- // Switch to View B (completely different filter)
438
- const viewBFilters = [
439
- {
440
- id: 'viewB-1',
441
- type: 'frame',
442
- field: 'function_name',
443
- matchType: 'contains',
444
- value: 'viewBOnly',
445
- },
446
- ];
447
- act(() => {
448
- result.current.forceApplyFilters(viewBFilters);
449
- });
450
- await waitFor(() => {
451
- expect(mockNavigateTo).toHaveBeenCalled();
452
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
453
- // View A's filters should be completely gone
454
- expect(params.profile_filters).not.toContain('viewAFunc');
455
- expect(params.profile_filters).not.toContain('viewABinary');
456
- // Only View B's filter should be present
457
- expect(params.profile_filters).toBe('f:fn:~:viewBOnly');
458
- });
459
- });
460
- it('should handle sequential view switches correctly', async () => {
461
- // Simulate: [default] -> [storage] -> [testing-view]
462
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
463
- // View 1: default view (1 filter)
464
- const defaultFilters = [{ id: 'd-1', type: 'hide_libc', value: 'enabled' }];
465
- act(() => {
466
- result.current.forceApplyFilters(defaultFilters);
467
- });
468
- await waitFor(() => {
469
- expect(mockNavigateTo).toHaveBeenCalled();
470
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
471
- expect(params.profile_filters).toBe('p:hide_libc:enabled');
472
- });
473
- mockNavigateTo.mockClear();
474
- // View 2: storage view (3 filters)
475
- const storageFilters = [
476
- { id: 's-1', type: 'stack', field: 'function_name', matchType: 'not_contains', value: 'io' },
477
- { id: 's-2', type: 'frame', field: 'binary', matchType: 'not_contains', value: 'disk' },
478
- { id: 's-3', type: 'frame', field: 'function_name', matchType: 'contains', value: 'storage' },
479
- ];
480
- act(() => {
481
- result.current.forceApplyFilters(storageFilters);
482
- });
483
- await waitFor(() => {
484
- expect(mockNavigateTo).toHaveBeenCalled();
485
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
486
- // Default view's filter should be gone
487
- expect(params.profile_filters).not.toContain('hide_libc');
488
- // Storage view should have 3 filters
489
- expect(params.profile_filters).toContain('io');
490
- expect(params.profile_filters).toContain('disk');
491
- expect(params.profile_filters).toContain('storage');
492
- });
493
- mockNavigateTo.mockClear();
494
- // View 3: testing-view (2 filters)
495
- const testingFilters = [
496
- { id: 't-1', type: 'stack', field: 'function_name', matchType: 'equal', value: 'test_main' },
497
- { id: 't-2', type: 'frame', field: 'binary', matchType: 'contains', value: 'test' },
498
- ];
499
- act(() => {
500
- result.current.forceApplyFilters(testingFilters);
501
- });
502
- await waitFor(() => {
503
- expect(mockNavigateTo).toHaveBeenCalled();
504
- const [, params] = mockNavigateTo.mock.calls[mockNavigateTo.mock.calls.length - 1];
505
- // Storage view's filters should be gone
506
- expect(params.profile_filters).not.toContain('io');
507
- expect(params.profile_filters).not.toContain('disk');
508
- expect(params.profile_filters).not.toContain('storage');
509
- // Testing view should have its 2 filters
510
- expect(params.profile_filters).toContain('test_main');
511
- expect(params.profile_filters).toContain('test');
512
- });
513
- });
514
- it('should not change filters when clicking the same view tab', async () => {
515
- // Start with existing filters
516
- mockLocation.search = '?profile_filters=s:fn:=:existingFilter';
517
- const { result } = renderHook(() => useProfileFiltersUrlState(), { wrapper: createWrapper() });
518
- await waitFor(() => {
519
- expect(result.current.appliedFilters).toHaveLength(1);
520
- });
521
- mockNavigateTo.mockClear();
522
- // Apply the same filters (simulating clicking the same view tab)
523
- const sameFilters = [
524
- {
525
- id: 'same-1',
526
- type: 'stack',
527
- field: 'function_name',
528
- matchType: 'equal',
529
- value: 'existingFilter',
530
- },
531
- ];
532
- act(() => {
533
- result.current.forceApplyFilters(sameFilters);
534
- });
535
- await waitFor(() => {
536
- expect(result.current.appliedFilters).toHaveLength(1);
537
- expect(result.current.appliedFilters[0].value).toBe('existingFilter');
538
- });
539
- });
540
- });
541
- });