Skip to content

Commit b80df38

Browse files
fix(classification): use AsyncLoad for AppliedByAiClassificationReason (#4274)
* fix(classification): use AsyncLoad for AppliedByAiClassificationReason * fix(classification): test nits --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 6e1bd80 commit b80df38

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎src/features/classification/Classification.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as React from 'react';
33
import { FormattedDate, FormattedMessage } from 'react-intl';
44

5-
import AppliedByAiClassificationReason from './applied-by-ai-classification-reason/AppliedByAiClassificationReason';
5+
import AsyncLoad from '../../elements/common/async-load';
66
import ClassifiedBadge from './ClassifiedBadge';
77
import Label from '../../components/label/Label';
88
import LoadingIndicator from '../../components/loading-indicator/LoadingIndicator';
@@ -17,6 +17,14 @@ import type { AiClassificationReason, Controls, ControlsFormat } from './flowTyp
1717

1818
const STYLE_INLINE: 'inline' = 'inline';
1919
const STYLE_TOOLTIP: 'tooltip' = 'tooltip';
20+
21+
const LoadableAppliedByAiClassificationReason = AsyncLoad({
22+
loader: () =>
23+
import(
24+
/* webpackMode: "lazy", webpackChunkName: "applied-by-ai-classification-reason" */ './applied-by-ai-classification-reason/AppliedByAiClassificationReason'
25+
),
26+
});
27+
2028
type Props = {
2129
aiClassificationReason?: AiClassificationReason,
2230
className?: string,
@@ -101,7 +109,7 @@ const Classification = ({
101109

102110
if (aiClassificationReason) {
103111
return (
104-
<AppliedByAiClassificationReason
112+
<LoadableAppliedByAiClassificationReason
105113
answer={aiClassificationReason.answer}
106114
citations={aiClassificationReason.citations}
107115
className="bdl-Classification-appliedByAiDetails"

‎src/features/classification/__tests__/Classification.test.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('features/classification/Classification', () => {
137137
});
138138

139139
const modifiedByClassificationLabel = screen.getByText(messages.modifiedByLabel.defaultMessage);
140-
const modifiedByDetailsSection = screen.getByTestId('classification-modifiedby');
140+
const modifiedByDetailsSection = screen.queryByTestId('classification-modifiedby');
141141
const messageText = screen.getByText(expectedMessageText);
142142
const appliedByTitle = screen.queryByText(messages.appliedByTitle.defaultMessage);
143143

@@ -235,7 +235,7 @@ describe('features/classification/Classification', () => {
235235

236236
test.each([true, false, undefined])(
237237
'should render AI reasoning with expected label when provided aiClassificationReason prop regardless of shouldUseAppliedByLabels value: %s',
238-
shouldUseAppliedByLabels => {
238+
async shouldUseAppliedByLabels => {
239239
const expectedCitationsCount = 5;
240240
const expectedCitations = Array.from({ length: expectedCitationsCount }, () => ({
241241
content: 'file content for citation',
@@ -257,7 +257,8 @@ describe('features/classification/Classification', () => {
257257
shouldUseAppliedByLabels,
258258
});
259259

260-
const boxAiIcon = screen.getByTestId('box-ai-icon');
260+
// Wait for the async component to load
261+
const boxAiIcon = await screen.findByTestId('box-ai-icon');
261262
const appliedByTitle = screen.getByText(messages.appliedByTitle.defaultMessage);
262263
const appliedByDetails = screen.getByText('Box AI on January 15, 2024'); // expected text based on provided mocks
263264
const reasonText = screen.getByText(aiClassificationReason.answer);
@@ -284,7 +285,7 @@ describe('features/classification/Classification', () => {
284285
modifiedBy,
285286
});
286287

287-
const modifiedByDetailsSection = screen.getByTestId('classification-modifiedby');
288+
const modifiedByDetailsSection = screen.queryByTestId('classification-modifiedby');
288289
const appliedByTitle = screen.getByText(messages.appliedByTitle.defaultMessage);
289290
const appliedByDetails = screen.getByText('TestUser on January 15, 2024');
290291
const modifiedByClassificationLabel = screen.queryByText(messages.modifiedByLabel.defaultMessage);
@@ -307,7 +308,7 @@ describe('features/classification/Classification', () => {
307308
modifiedBy,
308309
});
309310

310-
const modifiedByDetailsSection = screen.getByTestId('classification-modifiedby');
311+
const modifiedByDetailsSection = screen.queryByTestId('classification-modifiedby');
311312
const appliedByTitle = screen.getByText(messages.appliedByTitle.defaultMessage);
312313
const appliedByDetails = screen.getByText('TestUser on January 15, 2024');
313314
const modifiedByClassificationLabel = screen.queryByText(messages.modifiedByLabel.defaultMessage);

0 commit comments

Comments
 (0)