Skip to content

Commit

Permalink
Formatting tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Feb 7, 2022
1 parent 658ce8c commit c746627
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Includes a timestamp (Epoch time in seconds) for the generation of the URL
* Includes a return URL
*/
public virtual with sharing class AbstractRedirectToLwcTabPageController {

public virtual with sharing class AbstractRedirectToLwcTabPageController
{
protected String tabPageName;

/**
Expand Down Expand Up @@ -96,11 +96,11 @@ public virtual with sharing class AbstractRedirectToLwcTabPageController {
* Includes parameters for defining the return Url, the Epoch time (for checking the timely usage of the link)
* and the record Ids that are to be processed.
*/
public PageReference redirectToTabPage() {

public PageReference redirectToTabPage()
{
Contract.requires( this.tabPageName != null, 'redirectToTabPage called with a null this.tabPageName. Ensure that the controller extension ('+ObjectUtils.getClassName( this )+') sets "this.tabPageName" in the constructor' );

PageReference appPage = new PageReference( '/lightning/n/' + this.tabPageName ); // TODO: may not need the 'lightning' bit...
PageReference appPage = new PageReference( '/lightning/n/' + this.tabPageName );
appPage.getParameters().put( 'c__returnUrl', returnUrl );
appPage.getParameters().put( 'c__epoch', epochTime );
appPage.getParameters().put( 'c__recordIds', serializedRecordIds );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* A Lightning Controlller that provides access to the Epoch Time as defined by the
* Salesforce instance's clock
*/
public with sharing class TimeController {

public with sharing class TimeController
{
/**
* Returns the current Epoch time, in seconds
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,106 +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';
}
}
@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';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import getEpochTime from '@salesforce/apex/TimeController.getEpochTime';

const LOAD_LEEWAY = 60; // number of seconds leeway between the redirection to the page and the load of it.

// TODO: can we have a generic 'no records selected' error?
// TODO: clarify the error message when using an old link
// TODO: standards to always say how many records will be updated on the included LWC
export default class LwcListViewWrapper extends NavigationMixin( LightningElement ) {
Expand Down

0 comments on commit c746627

Please sign in to comment.