|
1 | 1 | @isTest |
2 | 2 | public with sharing class AbstractRedirectToLwcTabPageCtrlrTest |
3 | 3 | { |
4 | | - @isTest |
5 | | - private static void hasRecords_whenRecordsAreSelected_returnsTrue() // NOPMD: Test method name format |
6 | | - { |
7 | | - List<Contact> context = new List<Contact>{ |
8 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
9 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
10 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
11 | | - }; |
12 | | - |
13 | | - ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
14 | | - standardSetController.setSelected( context ); |
15 | | - TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
16 | | - |
17 | | - Test.startTest(); |
18 | | - Boolean got = controller.hasRecords; |
19 | | - Test.stopTest(); |
20 | | - |
21 | | - System.assertEquals( true, got, 'hasRecords, when records are selected, will return true' ); |
22 | | - } |
23 | | - |
24 | | - @isTest |
25 | | - private static void hasRecords_whenNoRecordsAreSelected_returnsFalse() // NOPMD: Test method name format |
26 | | - { |
27 | | - List<Contact> context = new List<Contact>{ |
28 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
29 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
30 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
31 | | - }; |
32 | | - |
33 | | - ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
34 | | - standardSetController.setSelected( new List<Contact>() ); |
35 | | - TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
36 | | - |
37 | | - Test.startTest(); |
38 | | - Boolean got = controller.hasRecords; |
39 | | - Test.stopTest(); |
40 | | - |
41 | | - System.assertEquals( false, got, 'hasRecords, when no records are selected, will return false' ); |
42 | | - } |
43 | | - |
44 | | - @isTest |
45 | | - private static void redirectToTabPage_whenCalled_returnsAPageReferenceToTheTabPage() // NOPMD: Test method name format |
46 | | - { |
47 | | - List<Contact> context = new List<Contact>{ |
48 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
49 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
50 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
51 | | - }; |
52 | | - |
53 | | - String expectedRecordIds = JSON.serialize( new List<Id>{ context[0].Id, context[1].Id, context[2].Id } ); |
54 | | - |
55 | | - ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
56 | | - standardSetController.setSelected( context ); |
57 | | - TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
58 | | - |
59 | | - Test.startTest(); |
60 | | - PageReference got = controller.redirectToTabPage(); |
61 | | - Test.stopTest(); |
62 | | - |
63 | | - Amoss_Asserts.assertContains( 'tabpagename', got.getUrl(), 'redirectToTabPage, when called, will retrun a PageReference with the URL pointing to the defined tab page' ); |
64 | | - |
65 | | - Map<String,String> parameters = got.getParameters(); |
66 | | - System.assertEquals( 'testscenario', parameters.get( 'c__returnUrl' ), 'redirectToTabPage, when called, will return a PageReference with a return url parameter' ); |
67 | | - System.assertNotEquals( null, parameters.get( 'c__epoch' ), 'redirectToTabPage, when called, will return a PageReference with an epoch parameter' ); |
68 | | - 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' ); |
69 | | - } |
70 | | - |
71 | | - @isTest |
72 | | - private static void redirectToTabPage_whenNoRecords_returnsAPageReferenceToTheTabPage() // NOPMD: Test method name format |
73 | | - { |
74 | | - List<Contact> context = new List<Contact>{ |
75 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
76 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
77 | | - new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
78 | | - }; |
79 | | - |
80 | | - String expectedRecordIds = JSON.serialize( new List<Id>() ); |
81 | | - |
82 | | - ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
83 | | - standardSetController.setSelected( new List<Contact>() ); |
84 | | - TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
85 | | - |
86 | | - Test.startTest(); |
87 | | - PageReference got = controller.redirectToTabPage(); |
88 | | - Test.stopTest(); |
89 | | - |
90 | | - 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' ); |
91 | | - |
92 | | - Map<String,String> parameters = got.getParameters(); |
93 | | - System.assertEquals( 'testscenario', parameters.get( 'c__returnUrl' ), 'redirectToTabPage, when no records are selected, will return a PageReference with a return url parameter' ); |
94 | | - System.assertNotEquals( null, parameters.get( 'c__epoch' ), 'redirectToTabPage, when no records are selected, will return a PageReference with an epoch parameter' ); |
95 | | - 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' ); |
96 | | - } |
97 | | - |
98 | | - class TestableRedirectToLwcTabPageController extends AbstractRedirectToLwcTabPageController |
99 | | - { |
100 | | - public TestableRedirectToLwcTabPageController( ApexPages.StandardSetController controller ) |
101 | | - { |
102 | | - super( controller ); |
103 | | - this.tabPageName = 'tabpagename'; |
104 | | - } |
105 | | - } |
| 4 | + @isTest |
| 5 | + private static void hasRecords_whenRecordsAreSelected_returnsTrue() // NOPMD: Test method name format |
| 6 | + { |
| 7 | + List<Contact> context = new List<Contact>{ |
| 8 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 9 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 10 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
| 11 | + }; |
| 12 | + |
| 13 | + ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
| 14 | + standardSetController.setSelected( context ); |
| 15 | + TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
| 16 | + |
| 17 | + Test.startTest(); |
| 18 | + Boolean got = controller.hasRecords; |
| 19 | + Test.stopTest(); |
| 20 | + |
| 21 | + System.assertEquals( true, got, 'hasRecords, when records are selected, will return true' ); |
| 22 | + } |
| 23 | + |
| 24 | + @isTest |
| 25 | + private static void hasRecords_whenNoRecordsAreSelected_returnsFalse() // NOPMD: Test method name format |
| 26 | + { |
| 27 | + List<Contact> context = new List<Contact>{ |
| 28 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 29 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 30 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
| 31 | + }; |
| 32 | + |
| 33 | + ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
| 34 | + standardSetController.setSelected( new List<Contact>() ); |
| 35 | + TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
| 36 | + |
| 37 | + Test.startTest(); |
| 38 | + Boolean got = controller.hasRecords; |
| 39 | + Test.stopTest(); |
| 40 | + |
| 41 | + System.assertEquals( false, got, 'hasRecords, when no records are selected, will return false' ); |
| 42 | + } |
| 43 | + |
| 44 | + @isTest |
| 45 | + private static void redirectToTabPage_whenCalled_returnsAPageReferenceToTheTabPage() // NOPMD: Test method name format |
| 46 | + { |
| 47 | + List<Contact> context = new List<Contact>{ |
| 48 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 49 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 50 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
| 51 | + }; |
| 52 | + |
| 53 | + String expectedRecordIds = JSON.serialize( new List<Id>{ context[0].Id, context[1].Id, context[2].Id } ); |
| 54 | + |
| 55 | + ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
| 56 | + standardSetController.setSelected( context ); |
| 57 | + TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
| 58 | + |
| 59 | + Test.startTest(); |
| 60 | + PageReference got = controller.redirectToTabPage(); |
| 61 | + Test.stopTest(); |
| 62 | + |
| 63 | + Amoss_Asserts.assertContains( 'tabpagename', got.getUrl(), 'redirectToTabPage, when called, will retrun a PageReference with the URL pointing to the defined tab page' ); |
| 64 | + |
| 65 | + Map<String,String> parameters = got.getParameters(); |
| 66 | + System.assertEquals( 'testscenario', parameters.get( 'c__returnUrl' ), 'redirectToTabPage, when called, will return a PageReference with a return url parameter' ); |
| 67 | + System.assertNotEquals( null, parameters.get( 'c__epoch' ), 'redirectToTabPage, when called, will return a PageReference with an epoch parameter' ); |
| 68 | + 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' ); |
| 69 | + } |
| 70 | + |
| 71 | + @isTest |
| 72 | + private static void redirectToTabPage_whenNoRecords_returnsAPageReferenceToTheTabPage() // NOPMD: Test method name format |
| 73 | + { |
| 74 | + List<Contact> context = new List<Contact>{ |
| 75 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 76 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ), |
| 77 | + new Contact( Id = TestIdUtils.generateId( Contact.sobjectType ) ) |
| 78 | + }; |
| 79 | + |
| 80 | + String expectedRecordIds = JSON.serialize( new List<Id>() ); |
| 81 | + |
| 82 | + ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController( context ); |
| 83 | + standardSetController.setSelected( new List<Contact>() ); |
| 84 | + TestableRedirectToLwcTabPageController controller = new TestableRedirectToLwcTabPageController( standardSetController ); |
| 85 | + |
| 86 | + Test.startTest(); |
| 87 | + PageReference got = controller.redirectToTabPage(); |
| 88 | + Test.stopTest(); |
| 89 | + |
| 90 | + 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' ); |
| 91 | + |
| 92 | + Map<String,String> parameters = got.getParameters(); |
| 93 | + System.assertEquals( 'testscenario', parameters.get( 'c__returnUrl' ), 'redirectToTabPage, when no records are selected, will return a PageReference with a return url parameter' ); |
| 94 | + System.assertNotEquals( null, parameters.get( 'c__epoch' ), 'redirectToTabPage, when no records are selected, will return a PageReference with an epoch parameter' ); |
| 95 | + 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' ); |
| 96 | + } |
| 97 | + |
| 98 | + class TestableRedirectToLwcTabPageController extends AbstractRedirectToLwcTabPageController |
| 99 | + { |
| 100 | + public TestableRedirectToLwcTabPageController( ApexPages.StandardSetController controller ) |
| 101 | + { |
| 102 | + super( controller ); |
| 103 | + this.tabPageName = 'tabpagename'; |
| 104 | + } |
| 105 | + } |
106 | 106 | } |
0 commit comments