-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 0432b3a into feature/248__hh_manageHH
- Loading branch information
Showing
12 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
public with sharing class PotentialDuplicates { | ||
|
||
private static final String SET_OF_MATCHES_KEY = 'setOfMatches'; | ||
|
||
@AuraEnabled | ||
public static Map<String, Object> getDuplicates(Id recordId) { | ||
Map<String, Object> returnParams = new Map<String, Object>{ SET_OF_MATCHES_KEY => null }; | ||
|
||
try { | ||
returnParams.put(SET_OF_MATCHES_KEY, getDuplicateList(recordId)); | ||
} | ||
catch (Exception e) { | ||
} | ||
|
||
return returnParams; | ||
} | ||
|
||
private static String getDuplicateList(Id recordId) { | ||
String strSetOfMatches = ''; | ||
|
||
Set<String> setOfMatchIds = new Set<String>(); | ||
List<Datacloud.FindDuplicatesResult> results = | ||
Datacloud.FindDuplicatesByIds.findDuplicatesByIds(new List<Id>{recordId}); | ||
for (Datacloud.FindDuplicatesResult findDupeResult : results) { | ||
for (Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) { | ||
for (Datacloud.MatchResult matchResult : dupeResult.getMatchResults()) { | ||
for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) { | ||
setOfMatchIds.add(matchRecord.getRecord().Id); | ||
} | ||
} | ||
} | ||
} | ||
for (String matchId : setOfMatchIds) { | ||
strSetOfMatches += (strSetOfMatches == '' ? '' : ',') + matchId; | ||
} | ||
|
||
return strSetOfMatches; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/PotentialDuplicates.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
28 changes: 28 additions & 0 deletions
28
force-app/main/default/classes/PotentialDuplicates_TEST.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@IsTest(IsParallel=false) | ||
private with sharing class PotentialDuplicates_TEST { | ||
|
||
@IsTest | ||
private static void shouldReturnNullWhenNoDuplicatesAreFound() { | ||
Id recordId = UTIL_UnitTestData_TEST.mockId(Contact.getSObjectType()); | ||
Map<String, Object> data = PotentialDuplicates.getDuplicates(recordId); | ||
System.assertEquals('', data.get('setOfMatches'), | ||
'There should be no duplicates'); | ||
} | ||
|
||
@IsTest | ||
private static void shouldReturnIdsWhenDuplicatesAreFound() { | ||
List<Contact> contactList = UTIL_UnitTestData_TEST.getContacts(3); | ||
for(Contact c : contactList) { | ||
c.FirstName = 'Test'; | ||
c.LastName = 'LastName'; | ||
c.Email = '[email protected]'; | ||
} | ||
insert contactList; | ||
|
||
Map<String, Object> data = PotentialDuplicates.getDuplicates(contactList[0].Id); | ||
String setOfMatches = (String)data.get('setOfMatches'); | ||
System.assertNotEquals('', setOfMatches, 'Duplicate Ids should be returned'); | ||
Integer numberOfMatches = setOfMatches.split(',').size(); | ||
System.assertEquals(2, numberOfMatches, 'There should be 2 duplicates returned'); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/PotentialDuplicates_TEST.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
force-app/main/default/lwc/potentialDuplicates/__tests__/potentialDuplicates.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { createElement } from 'lwc'; | ||
import PotentialDuplicates from 'c/potentialDuplicates'; | ||
import getDuplicates from '@salesforce/apex/PotentialDuplicates.getDuplicates'; | ||
import lblPotentialDuplicatesFoundNone from '@salesforce/label/c.potentialDuplicatesFoundNone'; | ||
import lblPotentialDuplicatesFoundOne from '@salesforce/label/c.potentialDuplicatesFoundOne'; | ||
import lblPotentialDuplicatesFoundMultiple from '@salesforce/label/c.potentialDuplicatesFoundMultiple'; | ||
import lblViewDuplicates from '@salesforce/label/c.viewDuplicates'; | ||
|
||
jest.mock('@salesforce/apex/PotentialDuplicates.getDuplicates', | ||
() => ({ default : jest.fn() }), | ||
{ virtual: true } | ||
); | ||
|
||
const createComponentForTest = () => { | ||
const el = createElement('c-potential-duplicates', { | ||
is: PotentialDuplicates | ||
}); | ||
Object.assign(el); | ||
el.recordId = 'fakeId'; | ||
el.displayCard = true; | ||
document.body.appendChild(el); | ||
return el; | ||
}; | ||
|
||
describe('Potential Duplicates Component', () => { | ||
|
||
afterEach(() => { | ||
clearDOM(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders the component with no link', async () => { | ||
getDuplicates.mockResolvedValue({}); | ||
const el = createComponentForTest(); | ||
await flushPromises(); | ||
|
||
const heading = el.shadowRoot.querySelector('h1'); | ||
expect(heading.textContent).toBe(lblPotentialDuplicatesFoundNone); | ||
const duplicateLink = el.shadowRoot.querySelector('[data-qa-locator="viewDuplicatesURL"]'); | ||
expect(duplicateLink).toBeFalsy(); | ||
}); | ||
|
||
it('renders the component with a duplicate link', async () => { | ||
getDuplicates.mockResolvedValue({"setOfMatches" : "anotherId"}); | ||
const el = createComponentForTest(); | ||
await flushPromises(); | ||
|
||
expect(getDuplicates).toHaveBeenCalled(); | ||
const heading = el.shadowRoot.querySelector('h1'); | ||
expect(heading.textContent).toBe(lblPotentialDuplicatesFoundOne); | ||
const duplicateLink = el.shadowRoot.querySelector('[data-qa-locator="viewDuplicatesURL"] a'); | ||
expect(duplicateLink).not.toBeNull(); | ||
expect(duplicateLink.textContent).toBe(lblViewDuplicates); | ||
}); | ||
|
||
it('text changes for multiple duplicates', async () => { | ||
getDuplicates.mockResolvedValue({"setOfMatches" : "anotherId,moreIds,lastId"}); | ||
const el = createComponentForTest(); | ||
await flushPromises(); | ||
|
||
expect(getDuplicates).toHaveBeenCalled(); | ||
const heading = el.shadowRoot.querySelector('h1'); | ||
expect(heading.textContent).toBe(lblPotentialDuplicatesFoundMultiple); | ||
const duplicateLink = el.shadowRoot.querySelector('[data-qa-locator="viewDuplicatesURL"] a'); | ||
expect(duplicateLink).not.toBeNull(); | ||
expect(duplicateLink.textContent).toBe(lblViewDuplicates); | ||
}); | ||
|
||
it('renders an error when callout fails', async () => { | ||
getDuplicates.mockRejectedValue({"status" : "fail", "body" : {"message" : "test"}}); | ||
const el = createComponentForTest(); | ||
await flushPromises(); | ||
|
||
const heading = el.shadowRoot.querySelector('h1'); | ||
expect(heading.textContent).toBe(lblPotentialDuplicatesFoundNone); | ||
const error = el.shadowRoot.querySelector('[data-qa-locator="error"]'); | ||
expect(error).not.toBeNull(); | ||
}); | ||
}) |
3 changes: 3 additions & 0 deletions
3
force-app/main/default/lwc/potentialDuplicates/potentialDuplicates.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.wrapped-content{ | ||
text-wrap: wrap; | ||
} |
13 changes: 13 additions & 0 deletions
13
force-app/main/default/lwc/potentialDuplicates/potentialDuplicates.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<template> | ||
<template lwc:if={displayCard}> | ||
<lightning-card variant="narrow" icon-name="standard:merge"> | ||
<h1 slot="title" class="wrapped-content">{lblTitle}</h1> | ||
<p class="slds-var-m-left_xx-large" lwc:if={viewDuplicatesURL} data-qa-locator="viewDuplicatesURL"> | ||
<a class="slds-var-m-left_xx-small" onclick={navigateToContactMerge}>{lblViewDuplicatesLink}</a> | ||
</p> | ||
<p class="slds-var-m-left_xx-large" lwc:if={error} data-qa-locator="error"> | ||
<span class="slds-text-color_error">{error}</span> | ||
</p> | ||
</lightning-card> | ||
</template> | ||
</template> |
103 changes: 103 additions & 0 deletions
103
force-app/main/default/lwc/potentialDuplicates/potentialDuplicates.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { LightningElement, api, track } from 'lwc'; | ||
import { NavigationMixin } from 'lightning/navigation'; | ||
import { getCurrentNamespace, showToast } from 'c/utilCommon'; | ||
|
||
import lblPotentialDuplicatesFoundNone from '@salesforce/label/c.potentialDuplicatesFoundNone'; | ||
import lblPotentialDuplicatesFoundOne from '@salesforce/label/c.potentialDuplicatesFoundOne'; | ||
import lblPotentialDuplicatesFoundMultiple from '@salesforce/label/c.potentialDuplicatesFoundMultiple'; | ||
import lblViewDuplicates from '@salesforce/label/c.viewDuplicates'; | ||
|
||
import getDuplicates from '@salesforce/apex/PotentialDuplicates.getDuplicates'; | ||
|
||
export default class PotentialDuplicates extends NavigationMixin(LightningElement) { | ||
|
||
@api recordId; | ||
@api displayCard; | ||
@api displayToast; | ||
|
||
@track isEnabled = true; | ||
@track duplicateCount; | ||
@track error; | ||
lblTitle = lblPotentialDuplicatesFoundNone; | ||
lblViewDuplicatesLink = lblViewDuplicates; | ||
viewDuplicatesURL; | ||
|
||
connectedCallback() { | ||
if (this.recordId) { | ||
getDuplicates({ recordId: this.recordId }) | ||
.then(response => { | ||
this.handleDuplicates(response); | ||
this.error = null; | ||
}) | ||
.catch(error => { | ||
this.error = this.handleError(error); | ||
}); | ||
} | ||
} | ||
|
||
handleDuplicates(response) { | ||
this.duplicateCount = 0; | ||
if (response && response.setOfMatches) { | ||
this.duplicateIdsParam = this.recordId + ',' + response.setOfMatches; | ||
this.duplicateCount = response.setOfMatches.split(',').length; | ||
} | ||
this.generateDuplicatesURL(); | ||
this.updateTitle(); | ||
this.handleToast(); | ||
} | ||
|
||
handleError(error) { | ||
if (error && error.status && error.body) { | ||
return error.body.message; | ||
} else if (error && error.name && error.message) { | ||
return error.message; | ||
} | ||
return ""; | ||
} | ||
|
||
handleToast() { | ||
if (this.displayToast && this.duplicateCount > 0) { | ||
let messageData = [{ | ||
"url": this.viewDuplicatesURL, | ||
"label": this.lblViewDuplicatesLink, | ||
}]; | ||
showToast("", this.lblTitle + " {0}", "info", "sticky", messageData); | ||
} | ||
} | ||
|
||
updateTitle() { | ||
switch (this.duplicateCount) { | ||
case 0: | ||
this.lblTitle = lblPotentialDuplicatesFoundNone; | ||
break; | ||
case 1: | ||
this.lblTitle = lblPotentialDuplicatesFoundOne; | ||
break; | ||
default: | ||
this.lblTitle = lblPotentialDuplicatesFoundMultiple.replace("{0}", this.duplicateCount.toString()); | ||
} | ||
} | ||
|
||
generateDuplicatesURL() { | ||
if (this.duplicateCount > 0) { | ||
const contactMerge = 'CON_ContactMerge'; | ||
const namespace = getCurrentNamespace(); | ||
const contactMergePage = namespace ? `${namespace}__${contactMerge}` : contactMerge; | ||
this.viewDuplicatesURL = "/apex/" + contactMergePage + "?searchIds=" + this.duplicateIdsParam; | ||
} | ||
else { | ||
this.viewDuplicatesURL = ""; | ||
} | ||
} | ||
|
||
navigateToContactMerge() { | ||
this[NavigationMixin.GenerateUrl]({ | ||
type: "standard__webPage", | ||
attributes: { | ||
url: this.viewDuplicatesURL | ||
} | ||
}).then(generatedUrl => { | ||
window.location.assign(generatedUrl); | ||
}); | ||
} | ||
} |
Oops, something went wrong.