Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(quantic): CRGA component not showing collapsed when answer appears without streaming #4840

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const genQaMarkdownTextPayload = {
payloadType: 'genqa.messageType',
payload: JSON.stringify({
textDelta:
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'THIS IS SOME LOREM IPSUM: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan felis vel nulla venenatis, vel volutpat mauris suscipit. Praesent aliquam, ex et dapibus fermentum, ligula metus condimentum nunc, non vehicula magna magna a nulla. Integer efficitur nunc eget semper facilisis. Quisque nec tortor at nunc blandit dictum sit amet vel mauris. Duis at tellus sit amet mi pharetra tincidunt. Nullam id risus eget risus accumsan molestie ac quis velit. Vivamus consectetur nisi vel enim finibus, nec laoreet risus facilisis. Integer a lacinia ligula. Etiam cursus urna nisi, ut tincidunt elit consectetur quis. Pellentesque nec sem vel neque malesuada euismod vitae nec augue. Suspendisse non ligula eu purus posuere dictum quis et magna. Curabitur dignissim, magna non feugiat consectetur, lorem orci fringilla sapien, sit amet vehicula eros nulla eget enim. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan felis vel nulla venenatis, vel volutpat mauris suscipit. Praesent aliquam, ex et dapibus fermentum, ligula metus condimentum nunc, non vehicula magna magna a nulla. Integer efficitur nunc eget semper facilisis. Quisque nec tortor at nunc blandit dictum sit amet vel mauris. Duis at tellus sit amet mi pharetra tincidunt. Nullam id risus eget risus accumsan molestie ac quis velit. Vivamus consectetur nisi vel enim finibus, nec laoreet risus facilisis. Integer a lacinia ligula. Etiam cursus urna nisi, ut tincidunt elit consectetur quis. Pellentesque nec sem vel neque malesuada euismod vitae nec augue. Suspendisse non ligula eu purus posuere dictum quis et magna. Curabitur dignissim, magna non feugiat consectetur, lorem orci fringilla sapien, sit amet vehicula eros nulla eget enim.',
}),
finishReason: 'COMPLETED',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export class GeneratedAnswerObject {
.locator('.citation__link');
}

get showMoreButton(): Locator {
return this.page.getByTestId('generated-answer__answer-toggle');
}

async hoverOverCitation(index: number): Promise<void> {
// waiting 500ms to allow the component to render completely, cause any re-rendering abort the hover action.
await this.page.waitForTimeout(500);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {testSearch, testInsight} from './fixture';
import {testSearch, testInsight, expect} from './fixture';
import {useCaseTestCases} from '../../../../../../playwright/utils/useCase';
import genQaData from './data';

Expand Down Expand Up @@ -174,5 +174,26 @@ useCaseTestCases.forEach((useCase) => {
});
});
});

test.describe('when the answer is generated in a single shot and the answer exceeds the maximum height', () => {
test.use({
options: {
collapsible: true,
},
});
test('should display the answer as collapsed', async ({
generatedAnswer,
}) => {
const expectedShowMoreLabel = 'Show more';
await generatedAnswer.waitForStreamEndUaAnalytics();

const showMoreButton = generatedAnswer.showMoreButton;
expect(showMoreButton).not.toBeNull();

const showMoreButtonLabel = await showMoreButton.textContent();
expect(showMoreButtonLabel).not.toBeNull();
expect(showMoreButtonLabel).toEqual(expectedShowMoreLabel);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,7 @@ export default class QuanticGeneratedAnswer extends LightningElement {
renderedCallback() {
initializeWithHeadless(this, this.engineId, this.initialize);
if (this.collapsible) {
// If we are still streaming add a little extra height to the answer element to account for the next answer chunk.
// This helps a lot with the jankyness of the answer fading out when the chunk is close but not yet over the max height.
const answerElementHeight = this.isStreaming
? this.generatedAnswerElementHeight + 50
: this.generatedAnswerElementHeight;
this._exceedsMaximumHeight =
answerElementHeight > this._maximumAnswerHeight;
this._exceedsMaximumHeight = this.isMaximumHeightExceeded();
}
}

Expand Down Expand Up @@ -224,6 +218,16 @@ export default class QuanticGeneratedAnswer extends LightningElement {
}
}

isMaximumHeightExceeded() {
// If we are still streaming add a little extra height to the answer element to account for the next answer chunk.
// This helps a lot with the jankyness of the answer fading out when the chunk is close but not yet over the max height.
const answerElementHeight = this.isStreaming
? this.generatedAnswerElementHeight + 50
: this.generatedAnswerElementHeight;

return answerElementHeight > this._maximumAnswerHeight;
}

getGeneratedAnswerStatus() {
if (!this.state.isVisible) {
return this.labels.generatedAnswerIsHidden;
Expand Down Expand Up @@ -348,6 +352,14 @@ export default class QuanticGeneratedAnswer extends LightningElement {
}
};

handleAnswerContentUpdated = (event) => {
event.stopPropagation();
if (this.collapsible) {
this._exceedsMaximumHeight = this.isMaximumHeightExceeded();
}
this.updateGeneratedAnswerCSSVariables();
};

handleToggleCollapseAnswer() {
this.state?.expanded
? this.generatedAnswer.collapse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
answer-content-format={answerContentFormat}
answer={answer}
is-streaming={isStreaming}
quantic__answercontentupdated={handleAnswerContentUpdated}
data-cy="generated-answer__content"
>
</c-quantic-generated-answer-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import generatedTextContentTemplate from './templates/generatedTextContent.html'
/**
* The `QuanticGeneratedAnswerContent` component displays the generated answer content.
* @category Internal
* @fires CustomEvent#quantic__answercontentupdated
* @example
* <c-quantic-generated-answer-content answer-content-format={answerContentFormat} answer={answer} is-streaming={isStreaming}></c-quantic-generated-answer-content>
*/
Expand Down Expand Up @@ -110,6 +111,7 @@ export default class QuanticGeneratedAnswerContent extends LightningElement {
else {
answerContainer.textContent = this.answer;
}
this.dispatchEvent(new CustomEvent('quantic__answercontentupdated'));
}

get generatedAnswerContentClass() {
Expand Down
Loading