Skip to content

Commit

Permalink
formatting some files
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagoparradev committed Jun 1, 2024
1 parent 6a1e103 commit 8683fe4
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 76 deletions.
27 changes: 14 additions & 13 deletions src-lookup-sample/main/default/classes/ContactLookup.cls
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
public class ContactLookup implements LookupResult.ILookupResult {

public final static Map<String, Object> ACCOUNT_ICON = new Map<String, Object>{
'iconName' => 'standard:contact'
};
Expand All @@ -8,7 +7,6 @@ public class ContactLookup implements LookupResult.ILookupResult {
List<String> values,
Map<String, Object> payload
) {

List<LookupResult> result = new List<LookupResult>();
String parentAccountName = (String) payload.get('accountName');

Expand Down Expand Up @@ -44,7 +42,7 @@ public class ContactLookup implements LookupResult.ILookupResult {
WHERE LastViewedDate != NULL AND Type = 'Contact'
ORDER BY LastViewedDate DESC
]) {
recentlyViewedRecords.add(record.Id);
recentlyViewedRecords.add(record.Id);
}

if (recentlyViewedRecords.isEmpty()) {
Expand All @@ -70,7 +68,6 @@ public class ContactLookup implements LookupResult.ILookupResult {
List<String> selectedIds,
Map<String, Object> payload
) {

String parentAccountName = (String) payload.get('accountName');
List<LookupResult> result = new List<LookupResult>();

Expand All @@ -80,8 +77,10 @@ public class ContactLookup implements LookupResult.ILookupResult {
SELECT Name, Email, HasOptedOutOfEmail
FROM Contact
WHERE
Id NOT IN : selectedIds
AND (Name LIKE :searchTerm OR Phone LIKE :searchTerm OR Email LIKE :searchTerm)
Id NOT IN :selectedIds
AND (Name LIKE :searchTerm
OR Phone LIKE :searchTerm
OR Email LIKE :searchTerm)
AND Account.Name = :parentAccountName
];

Expand All @@ -101,19 +100,21 @@ public class ContactLookup implements LookupResult.ILookupResult {
List<LookupResult.Subtitle> subtitles = new List<LookupResult.Subtitle>();

if (String.isNotBlank(contact.Email)) {
LookupResult.Subtitle email = new LookupResult.Subtitle();
email.type = 'lightning-formatted-email';
email.label = 'Email';
email.value = contact.Email;
email.props = new Map<String, Object>{ 'hideIcon' => true };
subtitles.add(email);
LookupResult.Subtitle email = new LookupResult.Subtitle();
email.type = 'lightning-formatted-email';
email.label = 'Email';
email.value = contact.Email;
email.props = new Map<String, Object>{ 'hideIcon' => true };
subtitles.add(email);
}

LookupResult.Subtitle optedOut = new LookupResult.Subtitle();
optedOut.type = 'lightning-icon';
optedOut.label = 'Opted out of email';
optedOut.props = new Map<String, Object>{
'iconName' => contact.HasOptedOutOfEmail ? 'utility:email' : 'utility:end_chat'
'iconName' => contact.HasOptedOutOfEmail
? 'utility:email'
: 'utility:end_chat'
};
subtitles.add(optedOut);

Expand Down
83 changes: 50 additions & 33 deletions src-lookup-sample/main/default/classes/ContactLookupTest.cls
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
@IsTest
private class ContactLookupTest {
@IsTest
static void shouldCreateLookupResults() {
// DATA
Account account = new Account(Name = 'account name test');
insert account;

@IsTest
static void contactLookupTest() {
Contact contact = new Contact(
FirstName = 'FirstName',
LastName = 'LastName',
Phone = '123456789',
Email = '[email protected]',
HasOptedOutOfEmail = false,
AccountId = account.Id
);
insert contact;

// DATA
Account account = new Account(
Name = 'account name test'
);
insert account;
Map<String, Object> payload = new Map<String, Object>();
payload.put('accountName', account.Name);

Contact contact = new Contact(
FirstName = 'FirstName',
LastName = 'LastName',
Phone = '123456789',
Email = '[email protected]',
HasOptedOutOfEmail = false,
AccountId = account.Id
);
insert contact;
// TEST
Test.startTest();
ContactLookup contactLookup = new ContactLookup();
List<LookupResult> selectionResult = ContactLookup.getSelection(
new List<String>{ contact.id },
payload
);
List<LookupResult> defaultSearchResultsResult = ContactLookup.getDefaultSearchResults(
payload
);
List<LookupResult> searchResultsResult = ContactLookup.getSearchResults(
'123',
new List<String>(),
payload
);
Test.stopTest();

Map<String, Object> payload = new Map<String, Object>();
payload.put('accountName', account.Name);

// TEST
Test.startTest();
ContactLookup contactLookup = new ContactLookup();
List<LookupResult> selectionResult = ContactLookup.getSelection(new List<String>{contact.id}, payload);
List<LookupResult> defaultSearchResultsResult = ContactLookup.getDefaultSearchResults(payload);
List<LookupResult> searchResultsResult = ContactLookup.getSearchResults('123', new List<String>(), payload);
Test.stopTest();

// ASSERT
Assert.areEqual(selectionResult[0].id, contact.id);
Assert.areEqual(defaultSearchResultsResult[0].id, contact.id);
Assert.areEqual(searchResultsResult[0].id, contact.id);
}
}
// ASSERT
Assert.areEqual(
selectionResult[0].id,
contact.id,
'should get the selection'
);
Assert.areEqual(
defaultSearchResultsResult[0].id,
contact.id,
'should set getDefaultResults from recentlyViewed'
);
Assert.areEqual(
searchResultsResult[0].id,
contact.id,
'filters contacts using searchKey'
);
}
}
68 changes: 39 additions & 29 deletions src-lookup/main/default/classes/LookupControllerHandlerTest.cls
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
@IsTest
private class LookupControllerHandlerTest {
@IsTest
static void lookupControllerTest() {
// DATA
LookupControllerHandler.apexClass = 'LookupControllerHandlerTest.MockLookupController';

// TEST
Test.startTest();
List<LookupResult> LookupResult = LookupControllerHandler.getSelection(
'',
new List<String>{ '' },
new Map<String, Object>()
);
Test.stopTest();

// ASSERT
Assert.areEqual(LookupResult.size(), 1);
}

@TestVisible
public class MockLookupController implements LookupResult.ILookupResult {
public List<LookupResult> getSelection(
List<String> values,
Map<String, Object> payload
) {
return new List<LookupResult>{ new LookupResult() };
}

@IsTest
static void lookupControllerTest() {

// DATA
LookupControllerHandler.apexClass = 'LookupControllerHandlerTest.MockLookupController';

// TEST
Test.startTest();
List<LookupResult> LookupResult = LookupControllerHandler.getSelection('', new List<String>{''}, new Map<String, Object>());
Test.stopTest();

// ASSERT
Assert.areEqual(LookupResult.size(), 1);
}

@TestVisible
public class MockLookupController implements LookupResult.ILookupResult {

public List<LookupResult> getSelection(List<String> values, Map<String, Object> payload) {
return new List<LookupResult>{new LookupResult()};
}

public List<LookupResult> getDefaultSearchResults(Map<String, Object> payload) {
return new List<LookupResult>{new LookupResult()};
}
public List<LookupResult> getDefaultSearchResults(
Map<String, Object> payload
) {
return new List<LookupResult>{ new LookupResult() };
}

public List<LookupResult> getSearchResults(String searchTerm, List<String> selectedIds, Map<String, Object> payload) {
return new List<LookupResult>{new LookupResult()};
}
public List<LookupResult> getSearchResults(
String searchTerm,
List<String> selectedIds,
Map<String, Object> payload
) {
return new List<LookupResult>{ new LookupResult() };
}
}
}
}
5 changes: 4 additions & 1 deletion src-lookup/main/default/classes/LookupResult.cls
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public class LookupResult {
}

public interface ILookupResult {
List<LookupResult> getSelection(List<String> values, Map<String, Object> payload);
List<LookupResult> getSelection(
List<String> values,
Map<String, Object> payload
);
List<LookupResult> getDefaultSearchResults(Map<String, Object> payload);
List<LookupResult> getSearchResults(
String searchTerm,
Expand Down

0 comments on commit 8683fe4

Please sign in to comment.