mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
# Backport This will backport the following commits from `main` to `8.11`: - [[EBT] Click's target circuit-breakers (#170440)](https://github.com/elastic/kibana/pull/170440) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Alejandro Fernández Haro","email":"alejandro.haro@elastic.co"},"sourceCommit":{"committedDate":"2023-11-03T11:21:26Z","message":"[EBT] Click's target circuit-breakers (#170440)","sha":"52aec54df4bc75b5feb8485487aa8aae21236494","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","Feature:Telemetry","release_note:skip","telemetry","backport:prev-minor","v8.12.0"],"number":170440,"url":"https://github.com/elastic/kibana/pull/170440","mergeCommit":{"message":"[EBT] Click's target circuit-breakers (#170440)","sha":"52aec54df4bc75b5feb8485487aa8aae21236494"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/170440","number":170440,"mergeCommit":{"message":"[EBT] Click's target circuit-breakers (#170440)","sha":"52aec54df4bc75b5feb8485487aa8aae21236494"}}]}] BACKPORT--> Co-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>
This commit is contained in:
parent
80840ede73
commit
414848ca90
2 changed files with 34 additions and 1 deletions
|
@ -84,6 +84,38 @@ describe('trackClicks', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('trims values longer than 256 chars', async () => {
|
||||
// Gather an actual "click" event
|
||||
const event$ = new ReplaySubject<MouseEvent>(1);
|
||||
const parent = document.createElement('div');
|
||||
parent.setAttribute('data-test-subj', 'test-click-target-parent');
|
||||
const element = document.createElement('button');
|
||||
parent.appendChild(element);
|
||||
const reallyLongText = `test-click-target-${new Array(10000).fill('0').join('')}`;
|
||||
element.setAttribute('data-test-subj', reallyLongText);
|
||||
element.innerText = 'test'; // Only to validate that it is not included in the event.
|
||||
element.value = 'test'; // Only to validate that it is not included in the event.
|
||||
element.addEventListener('click', (e) => event$.next(e));
|
||||
element.click();
|
||||
// Using an observable because the event might not be immediately available
|
||||
const event = await firstValueFrom(event$.pipe(take(1)));
|
||||
event$.complete(); // No longer needed
|
||||
|
||||
trackClicks(analyticsClientMock, true);
|
||||
expect(addEventListenerSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
(addEventListenerSpy.mock.calls[0][1] as EventListener)(event);
|
||||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(1);
|
||||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledWith('click', {
|
||||
target: [
|
||||
'DIV',
|
||||
'data-test-subj=test-click-target-parent',
|
||||
'BUTTON',
|
||||
`data-test-subj=test-click-target-${new Array(256 - 33).fill('0').join('')}`,
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test('swallows any processing errors when not in dev mode', async () => {
|
||||
trackClicks(analyticsClientMock, false);
|
||||
expect(addEventListenerSpy).toHaveBeenCalledTimes(1);
|
||||
|
|
|
@ -19,6 +19,7 @@ const HTML_ATTRIBUTES_TO_REMOVE = [
|
|||
'data-rfd-draggable-id',
|
||||
'href',
|
||||
'value',
|
||||
'title',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -81,6 +82,6 @@ function getTargetDefinition(target: HTMLElement): string[] {
|
|||
target.tagName,
|
||||
...[...target.attributes]
|
||||
.filter((attr) => !HTML_ATTRIBUTES_TO_REMOVE.includes(attr.name))
|
||||
.map((attr) => `${attr.name}=${attr.value}`),
|
||||
.map((attr) => `${attr.name}=${attr.value}`.slice(0, 256)),
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue