diff --git a/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts b/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts index 3f82512608f..d76cacd88b3 100644 --- a/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts +++ b/packages/headless/src/features/generated-answer/generated-answer-slice.test.ts @@ -80,6 +80,7 @@ describe('generated answer slice', () => { const newCitations = [ buildMockCitation({ id: 'some-other-id', + uri: 'my-uri', }), ]; const finalState = generatedAnswerReducer( @@ -95,6 +96,30 @@ describe('generated answer slice', () => { ...newCitations, ]); }); + + it('Shows only citations that have different Uris', () => { + const existingCitations = [ + buildMockCitation({ + id: 'current-id', + uri: 'my-uri', + }), + ]; + const newCitations = [ + buildMockCitation({ + id: 'some-other-id', + uri: 'my-uri', + }), + ]; + const finalState = generatedAnswerReducer( + { + ...getGeneratedAnswerInitialState(), + citations: existingCitations, + }, + updateCitations({citations: newCitations}) + ); + + expect(finalState.citations).toEqual([...newCitations]); + }); }); describe('#updateError', () => { diff --git a/packages/headless/src/features/generated-answer/generated-answer-slice.ts b/packages/headless/src/features/generated-answer/generated-answer-slice.ts index f1935d3b59a..3da7d303558 100644 --- a/packages/headless/src/features/generated-answer/generated-answer-slice.ts +++ b/packages/headless/src/features/generated-answer/generated-answer-slice.ts @@ -1,5 +1,6 @@ import {createReducer} from '@reduxjs/toolkit'; import {RETRYABLE_STREAM_ERROR_CODE} from '../../api/generated-answer/generated-answer-client'; +import {GeneratedAnswerCitation} from '../../api/generated-answer/generated-answer-event-payload'; import { closeGeneratedAnswerFeedbackModal, dislikeGeneratedAnswer, @@ -47,7 +48,13 @@ export const generatedAnswerReducer = createReducer( .addCase(updateCitations, (state, {payload}) => { state.isLoading = false; state.isStreaming = true; - state.citations = state.citations.concat(payload.citations); + const citationMap = new Map(); + for (const citationCollection of [state.citations, payload.citations]) { + for (const citation of citationCollection) { + citationMap.set(citation.uri, citation); + } + } + state.citations = Array.from(citationMap.values()); delete state.error; }) .addCase(updateError, (state, {payload}) => { diff --git a/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts b/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts index 3f37d68135b..4d61a6cf336 100644 --- a/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts +++ b/packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts @@ -1124,7 +1124,7 @@ describe('quantic-generated-answer', () => { const firstTestCitation = { id: 'some-id-1', title: 'Some Title 1', - uri: 'https://www.coveo.com', + uri: 'https://www.coveo1.com', permanentid: 'some-permanent-id-1', clickUri: exampleLinkUrl, text: 'example text 1', @@ -1132,7 +1132,7 @@ describe('quantic-generated-answer', () => { const secondTestCitation = { id: 'some-id-2', title: 'Some Title 2', - uri: 'https://www.coveo.com', + uri: 'https://www.coveo2.com', permanentid: 'some-permanent-id-2', clickUri: exampleLinkUrl, text: 'example text 2',