Skip to content

Commit c52bd42

Browse files
ui: Added test ids for more components (#5927)
* Added test ids for more components * Reverted back a id removal * [pre-commit.ci lite] apply automatic fixes * Linter fixes * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent c427f3d commit c52bd42

4 files changed

Lines changed: 59 additions & 6 deletions

File tree

ui/packages/shared/components/src/Select/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const Select = ({
5050
icon,
5151
id,
5252
hideCaretDropdown,
53+
flyoutTestId,
5354
...props
5455
}: {
5556
items: SelectItem[];
@@ -64,6 +65,7 @@ const Select = ({
6465
icon?: JSX.Element;
6566
id?: string;
6667
hideCaretDropdown?: boolean;
68+
flyoutTestId?: string;
6769
} & React.HTMLAttributes<HTMLButtonElement>): JSX.Element => {
6870
const selection = items.find(v => v.key === selectedKey) ?? {
6971
key: selectedKey,
@@ -120,6 +122,7 @@ const Select = ({
120122
className={cx(
121123
'absolute z-50 mt-1 pt-0 max-h-[50vh] w-max overflow-auto rounded-md bg-gray-50 py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:border-gray-600 dark:bg-gray-900 dark:ring-white dark:ring-opacity-20 sm:text-sm'
122124
)}
125+
data-testid={flyoutTestId}
123126
>
124127
{loading === true ? (
125128
<div className="w-[270px]">{loader}</div>

ui/packages/shared/profile/src/ProfileView/components/GroupByLabelsDropdown/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import Select from 'react-select';
1515

16+
import {testId} from '@parca/test-utils';
17+
1618
import {FIELD_LABELS} from '../../../ProfileFlameGraph/FlameGraphArrow';
1719

1820
interface LabelOption {
@@ -28,20 +30,30 @@ interface Props {
2830

2931
const GroupByLabelsDropdown = ({labels, groupBy, setGroupByLabels}: Props): JSX.Element => {
3032
return (
31-
<div className="flex flex-col">
33+
<div className="flex flex-col" {...testId('GROUP_BY_CONTAINER')}>
3234
<div className="flex items-center justify-between">
33-
<label className="text-sm">Group by</label>
35+
<label className="text-sm" {...testId('GROUP_BY_LABEL')}>
36+
Group by
37+
</label>
3438
</div>
3539

3640
<Select<LabelOption, true>
37-
id="h-group-by-labels-selector"
3841
isMulti
3942
defaultMenuIsOpen={false}
4043
defaultValue={undefined}
4144
name="labels"
4245
options={labels.map(label => ({label, value: `${FIELD_LABELS}.${label}`}))}
4346
className="parca-select-container text-sm rounded-md bg-white"
4447
classNamePrefix="parca-select"
48+
menuPortalTarget={document.body}
49+
components={{
50+
// eslint-disable-next-line react/prop-types
51+
MenuList: ({children, innerProps}) => (
52+
<div {...testId('GROUP_BY_SELECT_FLYOUT')} {...innerProps}>
53+
{children}
54+
</div>
55+
),
56+
}}
4557
value={groupBy
4658
.filter(l => l.startsWith(FIELD_LABELS))
4759
.map(l => ({value: l, label: l.slice(FIELD_LABELS.length + 1)}))}

ui/packages/shared/profile/src/ProfileView/components/ProfileFilters/index.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {Icon} from '@iconify/react';
1717
import cx from 'classnames';
1818

1919
import {Button, Input, Select, type SelectItem} from '@parca/components';
20+
import {testId} from '@parca/test-utils';
2021

2122
import {useProfileViewContext} from '../../context/ProfileViewContext';
2223
import {getPresetByKey, getPresetsForProfileType, isPresetKey} from './filterPresets';
@@ -204,7 +205,7 @@ const ProfileFilters = ({readOnly = false}: ProfileFiltersProps = {}): JSX.Eleme
204205
const filtersToRender = localFilters.length > 0 ? localFilters : appliedFilters ?? [];
205206

206207
return (
207-
<div className="flex gap-2 w-full items-start">
208+
<div className="flex gap-2 w-full items-start" {...testId('PROFILE_FILTERS_CONTAINER')}>
208209
<div className="flex-1 flex flex-wrap gap-2">
209210
{filtersToRender.map(filter => {
210211
const isNumberField = filter.field === 'address' || filter.field === 'line_number';
@@ -218,6 +219,8 @@ const ProfileFilters = ({readOnly = false}: ProfileFiltersProps = {}): JSX.Eleme
218219
selectedKey={filter.type}
219220
placeholder="Select Filter"
220221
disabled={readOnly}
222+
{...testId('FILTER_TYPE_SELECT')}
223+
flyoutTestId="filter-type-select-flyout"
221224
onSelection={key => {
222225
// Check if this is a preset selection
223226
if (isPresetKey(key)) {
@@ -266,6 +269,8 @@ const ProfileFilters = ({readOnly = false}: ProfileFiltersProps = {}): JSX.Eleme
266269
items={fieldItems}
267270
selectedKey={filter.field ?? ''}
268271
disabled={readOnly}
272+
{...testId('FILTER_FIELD_SELECT')}
273+
flyoutTestId="filter-field-select-flyout"
269274
onSelection={key => {
270275
const newField = key as ProfileFilter['field'];
271276
const isNewFieldNumber = newField === 'address' || newField === 'line_number';
@@ -292,6 +297,8 @@ const ProfileFilters = ({readOnly = false}: ProfileFiltersProps = {}): JSX.Eleme
292297
items={matchTypeItems}
293298
selectedKey={filter.matchType ?? ''}
294299
disabled={readOnly}
300+
{...testId('FILTER_MATCH_TYPE_SELECT')}
301+
flyoutTestId="filter-match-type-select-flyout"
295302
onSelection={key =>
296303
updateFilter(filter.id, {matchType: key as ProfileFilter['matchType']})
297304
}
@@ -309,13 +316,15 @@ const ProfileFilters = ({readOnly = false}: ProfileFiltersProps = {}): JSX.Eleme
309316
onChange={e => updateFilter(filter.id, {value: e.target.value})}
310317
onKeyDown={handleKeyDown}
311318
className="rounded-none w-36 text-sm focus:outline-1"
319+
{...testId('FILTER_VALUE_INPUT')}
312320
/>
313321
</>
314322
)}
315323

316324
{!readOnly && (
317325
<Button
318326
variant="neutral"
327+
{...testId('FILTER_REMOVE_BUTTON')}
319328
onClick={() => {
320329
// If we're displaying local filters and this is the last one, reset everything
321330
if (localFilters.length > 0 && localFilters.length === 1) {
@@ -345,13 +354,23 @@ const ProfileFilters = ({readOnly = false}: ProfileFiltersProps = {}): JSX.Eleme
345354
})}
346355

347356
{!readOnly && localFilters.length > 0 && (
348-
<Button variant="neutral" onClick={addFilter} className="p-3 h-[38px]">
357+
<Button
358+
variant="neutral"
359+
onClick={addFilter}
360+
className="p-3 h-[38px]"
361+
{...testId('ADD_FILTER_BUTTON')}
362+
>
349363
<Icon icon="mdi:filter-plus-outline" className="h-4 w-4" />
350364
</Button>
351365
)}
352366

353367
{!readOnly && localFilters.length === 0 && (appliedFilters?.length ?? 0) === 0 && (
354-
<Button variant="neutral" onClick={addFilter} className="flex items-center gap-2">
368+
<Button
369+
variant="neutral"
370+
onClick={addFilter}
371+
className="flex items-center gap-2"
372+
{...testId('ADD_FILTER_BUTTON')}
373+
>
355374
<Icon icon="mdi:filter-outline" className="h-4 w-4" />
356375
<span>Filter</span>
357376
</Button>
@@ -364,6 +383,7 @@ const ProfileFilters = ({readOnly = false}: ProfileFiltersProps = {}): JSX.Eleme
364383
onClick={onApplyFilters}
365384
disabled={!hasUnsavedChanges || !localFilters.some(isFilterComplete)}
366385
className={cx('flex items-center gap-2 sticky top-0')}
386+
{...testId('APPLY_FILTERS_BUTTON')}
367387
>
368388
<span>Apply</span>
369389
</Button>

ui/packages/shared/test-utils/src/test-ids.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ export const TEST_IDS = {
8787
FLAMEGRAPH_CONTAINER: 'flamegraph-container',
8888
FLAMEGRAPH_RESET_BUTTON: 'flamegraph-reset-button',
8989

90+
// Profile Filters
91+
PROFILE_FILTERS_CONTAINER: 'profile-filters-container',
92+
FILTER_TYPE_SELECT: 'filter-type-select',
93+
FILTER_TYPE_SELECT_FLYOUT: 'filter-type-select-flyout',
94+
FILTER_FIELD_SELECT: 'filter-field-select',
95+
FILTER_FIELD_SELECT_FLYOUT: 'filter-field-select-flyout',
96+
FILTER_MATCH_TYPE_SELECT: 'filter-match-type-select',
97+
FILTER_MATCH_TYPE_SELECT_FLYOUT: 'filter-match-type-select-flyout',
98+
FILTER_VALUE_INPUT: 'filter-value-input',
99+
FILTER_REMOVE_BUTTON: 'filter-remove-button',
100+
ADD_FILTER_BUTTON: 'add-filter-button',
101+
APPLY_FILTERS_BUTTON: 'apply-filters-button',
102+
103+
// Group By Controls
104+
GROUP_BY_CONTAINER: 'group-by-container',
105+
GROUP_BY_LABEL: 'group-by-label',
106+
GROUP_BY_SELECT_FLYOUT: 'group-by-select-flyout',
107+
90108
// Common Interactive Elements
91109
SELECT_DROPDOWN: 'select-dropdown',
92110
SELECT_OPTION: 'select-option',

0 commit comments

Comments
 (0)