forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for the redirect to tab page controller
- Loading branch information
1 parent
71e5297
commit b9bc589
Showing
3 changed files
with
114 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
106 changes: 106 additions & 0 deletions
106
...fault/ortoo-lwc-list-view-buttons/classes/tests/AbstractRedirectToLwcTabPageCtrlrTest.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,106 @@ | ||
@isTest | ||
public with sharing class AbstractRedirectToLwcTabPageCtrlrTest | ||
{ | ||
@isTest | ||
private static void hasRecords_whenRecordsAreSelected_returnsTrue() // NOPMD: Test method name format | ||
{ | ||
List<Contact> context = new List<Contact>{ | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) | ||
}; | ||
|
||
ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); | ||
standardSetController.setSelected( context ); | ||
TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); | ||
|
||
Test.startTest(); | ||
Boolean got = controller.hasRecords; | ||
Test.stopTest(); | ||
|
||
System.assertEquals( true, got, 'hasRecords, when records are selected, will return true' ); | ||
} | ||
|
||
@isTest | ||
private static void hasRecords_whenNoRecordsAreSelected_returnsFalse() // NOPMD: Test method name format | ||
{ | ||
List<Contact> context = new List<Contact>{ | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) | ||
}; | ||
|
||
ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); | ||
standardSetController.setSelected( new List<Contact>() ); | ||
TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); | ||
|
||
Test.startTest(); | ||
Boolean got = controller.hasRecords; | ||
Test.stopTest(); | ||
|
||
System.assertEquals( false, got, 'hasRecords, when no records are selected, will return false' ); | ||
} | ||
|
||
@isTest | ||
private static void redirectToTabPage_whenCalled_returnsAPageReferenceToTheTabPage() // NOPMD: Test method name format | ||
{ | ||
List<Contact> context = new List<Contact>{ | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) | ||
}; | ||
|
||
String expectedRecordIds = JSON.serialize( new List<Id>{ context[0].Id, context[1].Id, context[2].Id } ); | ||
|
||
ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); | ||
standardSetController.setSelected( context ); | ||
TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); | ||
|
||
Test.startTest(); | ||
PageReference got = controller.redirectToTabPage(); | ||
Test.stopTest(); | ||
|
||
Amoss_Asserts.assertContains( 'tabpagename', got.getUrl(), 'redirectToTabPage, when called, will retrun a PageReference with the URL pointing to the defined tab page' ); | ||
|
||
Map<String,String> parameters = got.getParameters(); | ||
System.assertEquals( 'testscenario', parameters.get( 'c__returnUrl' ), 'redirectToTabPage, when called, will return a PageReference with a return url parameter' ); | ||
System.assertNotEquals( null, parameters.get( 'c__epoch' ), 'redirectToTabPage, when called, will return a PageReference with an epoch parameter' ); | ||
System.assertEquals( expectedRecordIds, parameters.get( 'c__recordIds' ), 'redirectToTabPage, when called, will return a PageReference with a record ids parameter that contains a serialised list of the selected record ids' ); | ||
} | ||
|
||
@isTest | ||
private static void redirectToTabPage_whenNoRecords_returnsAPageReferenceToTheTabPage() // NOPMD: Test method name format | ||
{ | ||
List<Contact> context = new List<Contact>{ | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), | ||
new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) | ||
}; | ||
|
||
String expectedRecordIds = JSON.serialize( new List<Id>() ); | ||
|
||
ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); | ||
standardSetController.setSelected( new List<Contact>() ); | ||
TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); | ||
|
||
Test.startTest(); | ||
PageReference got = controller.redirectToTabPage(); | ||
Test.stopTest(); | ||
|
||
Amoss_Asserts.assertContains( 'tabpagename', got.getUrl(), 'redirectToTabPage, when no records are selected, will retrun a PageReference with the URL pointing to the defined tab page' ); | ||
|
||
Map<String,String> parameters = got.getParameters(); | ||
System.assertEquals( 'testscenario', parameters.get( 'c__returnUrl' ), 'redirectToTabPage, when no records are selected, will return a PageReference with a return url parameter' ); | ||
System.assertNotEquals( null, parameters.get( 'c__epoch' ), 'redirectToTabPage, when no records are selected, will return a PageReference with an epoch parameter' ); | ||
System.assertEquals( expectedRecordIds, parameters.get( 'c__recordIds' ), 'redirectToTabPage, when no records are selected, will return a PageReference with a record ids parameter that contains a serialised empty list' ); | ||
} | ||
|
||
class TestableRedirectToLwcTabPageController extends AbstractRedirectToLwcTabPageController | ||
{ | ||
public TestableRedirectToLwcTabPageController( ApexPages.StandardSetController controller ) | ||
{ | ||
super( controller ); | ||
this.tabPageName = 'tabpagename'; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...oo-lwc-list-view-buttons/classes/tests/AbstractRedirectToLwcTabPageCtrlrTest.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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |