-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add text content, clean up innerText and textContent, make Button Cli…
…cks more reliable (#1151)
- Loading branch information
Showing
9 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@segment/analytics-signals': patch | ||
--- | ||
|
||
- Clean up up innerText AND textContent artifacts to make easier to parse. | ||
- Add textContent field | ||
- Make button Clicks more reliable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../signals/signals-integration-tests/src/tests/signals-vanilla/button-click-complex.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { test, expect } from '@playwright/test' | ||
import type { SegmentEvent } from '@segment/analytics-next' | ||
import { IndexPage } from './index-page' | ||
|
||
const indexPage = new IndexPage() | ||
|
||
const basicEdgeFn = ` | ||
// this is a process signal function | ||
const processSignal = (signal) => {}` | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await indexPage.loadAndWait(page, basicEdgeFn) | ||
}) | ||
|
||
test('button click (complex, with nested items)', async () => { | ||
/** | ||
* Click a button with nested text, ensure that that correct text shows up | ||
*/ | ||
await Promise.all([ | ||
indexPage.clickComplexButton(), | ||
indexPage.waitForSignalsApiFlush(), | ||
]) | ||
|
||
const signalsReqJSON = indexPage.lastSignalsApiReq.postDataJSON() | ||
const interactionSignals = signalsReqJSON.batch.filter( | ||
(el: SegmentEvent) => el.properties!.type === 'interaction' | ||
) | ||
expect(interactionSignals).toHaveLength(1) | ||
const data = { | ||
eventType: 'click', | ||
target: { | ||
attributes: { | ||
id: 'complex-button', | ||
}, | ||
classList: [], | ||
id: 'complex-button', | ||
labels: [], | ||
name: '', | ||
nodeName: 'BUTTON', | ||
tagName: 'BUTTON', | ||
title: '', | ||
type: 'submit', | ||
innerText: expect.any(String), | ||
textContent: expect.stringContaining( | ||
'Other Example Button with Nested Text' | ||
), | ||
value: '', | ||
}, | ||
} | ||
|
||
expect(interactionSignals[0]).toMatchObject({ | ||
event: 'Segment Signal Generated', | ||
type: 'track', | ||
properties: { | ||
type: 'interaction', | ||
data, | ||
}, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/signals/signals/src/core/signal-generators/__tests__/dom-gen-helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { cleanText } from '../dom-gen' | ||
|
||
describe(cleanText, () => { | ||
test('should remove newline characters', () => { | ||
const input = 'Hello\nWorld\n' | ||
const expected = 'Hello World' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
|
||
test('should remove tab characters', () => { | ||
const input = 'Hello\tWorld\t' | ||
const expected = 'Hello World' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
|
||
test('should replace multiple spaces with a single space', () => { | ||
const input = 'Hello World' | ||
const expected = 'Hello World' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
|
||
test('should replace non-breaking spaces with regular spaces', () => { | ||
const input = 'Hello\u00A0World' | ||
const expected = 'Hello World' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
|
||
test('should trim leading and trailing spaces', () => { | ||
const input = ' Hello World ' | ||
const expected = 'Hello World' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
|
||
test('should handle a combination of special characters', () => { | ||
const input = ' \n\tHello\u00A0 World\n\t ' | ||
const expected = 'Hello World' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
|
||
test('should return an empty string if input is empty', () => { | ||
const input = '' | ||
const expected = '' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
|
||
test('should return the same string if there are no special characters', () => { | ||
const input = 'Hello World' | ||
const expected = 'Hello World' | ||
expect(cleanText(input)).toBe(expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters