Skip to content

Commit

Permalink
chore: Move table task interaction id to root of component (#2953)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldowseza authored Oct 30, 2024
1 parent 1a8e5d9 commit 4749c9a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
36 changes: 36 additions & 0 deletions pages/funnel-analytics/table.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';

import { Header, Link, Table } from '~components';
import { setComponentMetrics } from '~components/internal/analytics';

const componentMetricsLog: any[] = [];
(window as any).__awsuiComponentlMetrics__ = componentMetricsLog;

setComponentMetrics({
componentMounted: props => {
componentMetricsLog.push(props);
return props.taskInteractionId || 'mocked-task-interaction-id';
},
componentUpdated: props => {
componentMetricsLog.push(props);
},
});

export default function () {
return (
<>
<h1>Table analytics</h1>
<Table
items={[]}
columnDefinitions={[]}
header={
<Header info={<Link variant="info">Info</Link>} counter="(10)">
Table title
</Header>
}
/>
</>
);
}
33 changes: 33 additions & 0 deletions src/table/__integ__/component-metrics.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { BasePageObject } from '@cloudscape-design/browser-test-tools/page-objects';
import useBrowser from '@cloudscape-design/browser-test-tools/use-browser';

interface ExtendedWindow extends Window {
__awsuiComponentlMetrics__: Array<any>;
}
declare const window: ExtendedWindow;

class TableWithAnalyticsPageObject extends BasePageObject {
async getComponentMetricsLog() {
const componentsLog = await this.browser.execute(() => window.__awsuiComponentlMetrics__);
return componentsLog;
}
}

test(
'component mount event includes table title without additional header slot information',
useBrowser(async browser => {
await browser.url('#/light/funnel-analytics/table');
const page = new TableWithAnalyticsPageObject(browser);
const componentsLog = await page.getComponentMetricsLog();
expect(componentsLog.length).toBe(1);
expect(componentsLog[0]).toMatchObject({
componentConfiguration: {
taskName: 'Table title',
},
componentName: 'table',
taskInteractionId: expect.any(String),
});
})
);
19 changes: 19 additions & 0 deletions src/table/__tests__/component-metrics.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import * as React from 'react';
import { render } from '@testing-library/react';

import Table from '../../../lib/components/table';
import createWrapper from '../../../lib/components/test-utils/dom';
import { mockComponentMetrics } from '../../internal/analytics/__tests__/mocks';

beforeEach(() => {
jest.resetAllMocks();
mockComponentMetrics();
});

test('should add data-analytics-task-interaction-id to root of Table component', () => {
const { container } = render(<Table items={[]} columnDefinitions={[]} />);
const tableElement = createWrapper(container).findTable()!.getElement();
expect(tableElement).toHaveAttribute('data-analytics-task-interaction-id');
});
2 changes: 1 addition & 1 deletion src/table/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ const InternalTable = React.forwardRef(
>
<InternalContainer
{...baseProps}
{...tableInteractionAttributes}
__internalRootRef={__internalRootRef}
className={clsx(baseProps.className, styles.root)}
__funnelSubStepProps={__funnelSubStepProps}
Expand Down Expand Up @@ -502,7 +503,6 @@ const InternalTable = React.forwardRef(
>
<table
{...performanceMarkAttributes}
{...tableInteractionAttributes}
ref={tableRef}
className={clsx(
styles.table,
Expand Down

0 comments on commit 4749c9a

Please sign in to comment.