Skip to content

Commit

Permalink
fix(quantic): adding support to opening case comments in Salesforce s…
Browse files Browse the repository at this point in the history
…ub tabs (#3626)

* adding support to oppening case comments in Salesforce sub tabs

* comment added
  • Loading branch information
mmitiche authored Feb 20, 2024
1 parent 25002cd commit ec0c2dc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export default class QuanticFoldedResultList extends LightningElement {
* A list of fields to include in the query results, separated by commas.
* @api
* @type {string}
* @defaultValue `'date,author,source,language,filetype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid'`
* @defaultValue `'date,author,source,language,filetype,documenttype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid,sfparentid'`
*/
@api fieldsToInclude =
'date,author,source,language,filetype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid';
'date,author,source,language,filetype,documenttype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid,sfparentid';
/**
* The name of the field on which to do the folding.
* @api
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
// @ts-ignore
import {
getNavigateCalledWith,
// @ts-ignore
getNavigateCalledWith, // @ts-ignore
getGenerateUrlCalledWith,
} from 'lightning/navigation';
// @ts-ignore
import {createElement} from 'lwc';
import QuanticResultLink from '../quanticResultLink';
// @ts-ignore
import mockDefaultResult from './data/defaultResult.json';
// @ts-ignore
import mockKnowledgeArticleResult from './data/knowledgeArticleResult.json';
// @ts-ignore
import mockSalesforceResult from './data/salesforceResult.json';

const exampleResult = {
clickUri: 'https://coveo.com/',
};

jest.mock('c/quanticHeadlessLoader');

Expand Down Expand Up @@ -83,19 +81,25 @@ describe('c-quantic-result-link', () => {
});

describe('when the result is of type Salesforce', () => {
const exampleSalesforceResult = {
...exampleResult,
raw: {
sfid: '123',
},
};
it('should call the navigation mixin to get the Salesforce record URL', async () => {
createTestComponent({...mockSalesforceResult});
createTestComponent({result: exampleSalesforceResult});
await flushPromises();

const {pageReference} = getGenerateUrlCalledWith();

expect(pageReference.attributes.recordId).toBe(
mockSalesforceResult.result.raw.sfid
exampleSalesforceResult.raw.sfid
);
});

it('should open the result link in a Salesforce console subtab', async () => {
const element = createTestComponent({...mockSalesforceResult});
const element = createTestComponent({result: exampleSalesforceResult});
await flushPromises();

const linkSalesforce = element.shadowRoot.querySelector('a');
Expand All @@ -104,13 +108,22 @@ describe('c-quantic-result-link', () => {
const {pageReference} = getNavigateCalledWith();

expect(pageReference.attributes.recordId).toBe(
mockSalesforceResult.result.raw.sfid
exampleSalesforceResult.raw.sfid
);
});

describe('when the result is a knowledge article', () => {
const exampleKnowledgeArticleResult = {
...exampleResult,
raw: {
sfid: '1234',
sfkavid: '1234',
},
};
it('should open the result link in a Salesforce console subtab', async () => {
const element = createTestComponent({...mockKnowledgeArticleResult});
const element = createTestComponent({
result: exampleKnowledgeArticleResult,
});
await flushPromises();

const LinkKnowledgeArticle = element.shadowRoot.querySelector('a');
Expand All @@ -119,39 +132,59 @@ describe('c-quantic-result-link', () => {
const {pageReference} = getNavigateCalledWith();

expect(pageReference.attributes.recordId).toBe(
mockKnowledgeArticleResult.result.raw.sfkavid
exampleKnowledgeArticleResult.raw.sfkavid
);
});
});

describe('when the result is a case comment', () => {
const exampleCaseCommentResult = {
...exampleResult,
raw: {
sfid: '1234',
sfparentid: '5678',
documenttype: 'CaseComment',
},
};
it('should open the parent of the result in a Salesforce console subtab', async () => {
const element = createTestComponent({result: exampleCaseCommentResult});
await flushPromises();

const link = element.shadowRoot.querySelector('a');
link.click();

const {pageReference} = getNavigateCalledWith();

expect(pageReference.attributes.recordId).toBe(
exampleCaseCommentResult.raw.sfparentid
);
});
});
});

describe('when the result is NOT of type salesforce', () => {
it('should open the result link in the current browser tab', async () => {
const element = createTestComponent({...mockDefaultResult});
const element = createTestComponent({result: exampleResult});
await flushPromises();

const link = element.shadowRoot.querySelector('a');

expect(link.getAttribute('href')).toEqual(
mockDefaultResult.result.clickUri
);
expect(link.getAttribute('href')).toEqual(exampleResult.clickUri);
expect(link.getAttribute('target')).toEqual('_self');
});

describe('with a custom value for the target property', () => {
it('should open the result link based on the value of the target property', async () => {
const customTarget = '_blank';
const element = createTestComponent({
...mockDefaultResult,
result: exampleResult,
target: customTarget,
});
await flushPromises();

const link = element.shadowRoot.querySelector('a');

expect(link.getAttribute('href')).toEqual(
mockDefaultResult.result.clickUri
);
expect(link.getAttribute('href')).toEqual(exampleResult.clickUri);
expect(link.getAttribute('target')).toEqual(customTarget);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {ResultUtils} from 'c/quanticUtils';
import {NavigationMixin} from 'lightning/navigation';
import {LightningElement, api} from 'lwc';

/**
* Some document types cannot be opened directly in Salesforce, but we need to open their parent record, as is the case for the Case Comment document type.
*/
const documentTypesRequiringParentRecord = ['CaseComment'];

/** @typedef {import("coveo").Result} Result */
/** @typedef {import("coveo").SearchEngine} SearchEngine */

Expand Down Expand Up @@ -139,9 +144,20 @@ export default class QuanticResultLink extends NavigationMixin(
if (this.result?.raw?.sfkbid && this.result?.raw?.sfkavid) {
return this.result.raw.sfkavid;
}
if (this.shouldOpenParentRecord) {
return this.result?.raw?.sfparentid;
}
return this.result.raw.sfid;
}

get shouldOpenParentRecord() {
return (
documentTypesRequiringParentRecord.includes(
this.result?.raw?.documenttype
) && this.result?.raw?.sfparentid
);
}

/**
* Checks if the Result type is Salesforce.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export default class QuanticResultList extends LightningElement {
* A list of fields to include in the query results, separated by commas.
* @api
* @type {string}
* @defaultValue `'date,author,source,language,filetype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid'`
* @defaultValue `'date,author,source,language,filetype,documenttype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid,sfparentid'`
*/
@api fieldsToInclude =
'date,author,source,language,filetype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid';
'date,author,source,language,filetype,documenttype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid,sfparentid';

/** @type {ResultListState}*/
@track state;
Expand Down

0 comments on commit ec0c2dc

Please sign in to comment.