-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a1e103
commit 8683fe4
Showing
4 changed files
with
107 additions
and
76 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
83 changes: 50 additions & 33 deletions
83
src-lookup-sample/main/default/classes/ContactLookupTest.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 |
---|---|---|
@@ -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
68
src-lookup/main/default/classes/LookupControllerHandlerTest.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 |
---|---|---|
@@ -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() }; | ||
} | ||
} | ||
} | ||
} |
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