Skip to content

Commit

Permalink
fix: Table does not instanceIdentifier for the reported task name in …
Browse files Browse the repository at this point in the history
…metrics
  • Loading branch information
connorlanigan committed Feb 21, 2025
1 parent 63e53ad commit 445ec39
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/table/__tests__/analytics-events.test.tsx
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 React from 'react';
import { render } from '@testing-library/react';

import Header from '../../../lib/components/header';
import { ComponentMetrics, setComponentMetrics } from '../../../lib/components/internal/analytics';
import Table from '../../../lib/components/table';

const componentMounted = jest.fn();
const componentUpdated = jest.fn();

setComponentMetrics({ componentMounted, componentUpdated });

describe('Task name', () => {
test('instanceIdentifier overrides the automatically determined task name', () => {
render(
<Table
analyticsMetadata={{ instanceIdentifier: 'My custom task name override' }}
items={[]}
columnDefinitions={[]}
header={<Header>This is the table header</Header>}
/>
);

expect(ComponentMetrics.componentMounted).toHaveBeenCalledTimes(1);
expect(ComponentMetrics.componentMounted).toHaveBeenCalledWith(
expect.objectContaining({
componentConfiguration: expect.objectContaining({ taskName: 'My custom task name override' }),
})
);
});
});
2 changes: 1 addition & 1 deletion src/table/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const InternalTable = React.forwardRef(
variant,
flowType: rest.analyticsMetadata?.flowType,
instanceIdentifier: analyticsMetadata?.instanceIdentifier,
taskName: getHeaderText(),
taskName: analyticsMetadata?.instanceIdentifier ?? getHeaderText(),
patternIdentifier: getPatternIdentifier(),
sortedBy: {
columnId: sortingColumn?.sortingField,
Expand Down

0 comments on commit 445ec39

Please sign in to comment.