Skip to content

Commit baef481

Browse files
author
Francesco Longo
committed
chore: Address PR feedback
1 parent 00b3751 commit baef481

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/internal/analytics-metadata/__tests__/dom-utils.test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import React from 'react';
55
import { render } from '@testing-library/react';
66
import { activateAnalyticsMetadata, getAnalyticsMetadataAttribute, METADATA_ATTRIBUTE } from '../attributes';
7-
import { findLogicalParent, isNodeComponent, findComponentUp, findSelectorUp } from '../dom-utils';
7+
import { findLogicalParent, isNodeComponent, findComponentUpUntil, findSelectorUp } from '../dom-utils';
88

99
beforeAll(() => {
1010
activateAnalyticsMetadata(true);
@@ -78,17 +78,17 @@ describe('isNodeComponent', () => {
7878
});
7979
});
8080

81-
describe('findComponentUp', () => {
81+
describe('findComponentUpUntil', () => {
8282
test('returns null when input is null', () => {
83-
expect(findComponentUp(null)).toBeNull();
83+
expect(findComponentUpUntil(null)).toBeNull();
8484
});
8585
test('returns parent component element', () => {
8686
const { container } = render(
8787
<div id="component-element" {...getAnalyticsMetadataAttribute({ component: { name: 'ComponentName' } })}>
8888
<div id="target-element"></div>
8989
</div>
9090
);
91-
expect(findComponentUp(container.querySelector('#target-element'))!.id).toBe('component-element');
91+
expect(findComponentUpUntil(container.querySelector('#target-element'))!.id).toBe('component-element');
9292
});
9393
test('returns parent component element with portals', () => {
9494
const { container } = render(
@@ -101,15 +101,15 @@ describe('findComponentUp', () => {
101101
</div>
102102
</div>
103103
);
104-
expect(findComponentUp(container.querySelector('#target-element'))!.id).toBe('component-element');
104+
expect(findComponentUpUntil(container.querySelector('#target-element'))!.id).toBe('component-element');
105105
});
106106
test('returns null when element has no parent component', () => {
107107
const { container } = render(
108108
<div>
109109
<div id="target-element"></div>
110110
</div>
111111
);
112-
expect(findComponentUp(container.querySelector('#target-element'))).toBeNull();
112+
expect(findComponentUpUntil(container.querySelector('#target-element'))).toBeNull();
113113
});
114114
test('with `until` argument', () => {
115115
const { container } = render(
@@ -128,31 +128,31 @@ describe('findComponentUp', () => {
128128
</>
129129
);
130130
expect(
131-
findComponentUp(
131+
findComponentUpUntil(
132132
container.querySelector('#target-element'),
133133
container.querySelector('#outer-element') as HTMLElement
134134
)!.id
135135
).toBe('component-element');
136136
expect(
137-
findComponentUp(
137+
findComponentUpUntil(
138138
container.querySelector('#target-element'),
139139
container.querySelector('#target-element') as HTMLElement
140140
)
141141
).toBeNull();
142142
expect(
143-
findComponentUp(
143+
findComponentUpUntil(
144144
container.querySelector('#target-element'),
145145
container.querySelector('#component-element') as HTMLElement
146146
)!.id
147147
).toBe('component-element');
148148
expect(
149-
findComponentUp(
149+
findComponentUpUntil(
150150
container.querySelector('#another-target-element'),
151151
container.querySelector('#outer-element') as HTMLElement
152152
)!.id
153153
).toBe('component-element');
154154
expect(
155-
findComponentUp(
155+
findComponentUpUntil(
156156
container.querySelector('#another-target-element'),
157157
container.querySelector('#another-until') as HTMLElement
158158
)

src/internal/analytics-metadata/dom-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const findLogicalParent = (node: HTMLElement): HTMLElement | null => {
1515
}
1616
};
1717

18-
export function findComponentUp(node: HTMLElement | null, until: HTMLElement = document.body): HTMLElement | null {
18+
export function findComponentUpUntil(node: HTMLElement | null, until: HTMLElement = document.body): HTMLElement | null {
1919
let firstComponentElement = node;
2020
while (firstComponentElement && firstComponentElement !== until && !isNodeComponent(firstComponentElement)) {
2121
firstComponentElement = findLogicalParent(firstComponentElement);

src/internal/analytics-metadata/labels-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { LABEL_DATA_ATTRIBUTE } from './attributes';
5-
import { findSelectorUp, findComponentUp } from './dom-utils';
5+
import { findSelectorUp, findComponentUpUntil } from './dom-utils';
66
import { LabelIdentifier } from './interfaces';
77

88
export const processLabel = (node: HTMLElement | null, labelIdentifier: string | LabelIdentifier | null): string => {
@@ -52,7 +52,7 @@ const processSingleLabel = (
5252
return processSingleLabel(findSelectorUp(node, rootSelector), labelSelector);
5353
}
5454
if (root === 'component') {
55-
return processSingleLabel(findComponentUp(node), labelSelector);
55+
return processSingleLabel(findComponentUpUntil(node), labelSelector);
5656
}
5757
if (root === 'body') {
5858
return processSingleLabel(document.body, labelSelector);

0 commit comments

Comments
 (0)