Guest User

Untitled

a guest
Jan 16th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. @isTest
  2. public class bcfTest {
  3. public static testMethod void adBill(){
  4. Billing_Change_form__c testBill = new Billing_Change_Form__c();
  5. testBill.Name = 'Test name';
  6. insert testBill;
  7.  
  8. Billing_Change_form__c testBill2 = new Billing_Change_Form__c();
  9. testBill2.Name = 'Test name2';
  10. insert testBill2;
  11.  
  12. Contingency__c caseTest = new Contingency__c();
  13. caseTest.Name = 'test Case';
  14. caseTest.Contingency__c = 'IN BILLING';
  15. caseTest.VENDOR_INVOICE__r.Account_del__r.id='1234';
  16. insert caseTest;
  17.  
  18. Contingency__c caseTest2 = new Contingency__c();
  19. caseTest2.Name = 'test Case2';
  20. caseTest2.Contingency__c = 'IN BILLING';
  21. caseTest2.VENDOR_INVOICE__r.Account_del__r.id='5678';
  22. insert caseTest2;
  23.  
  24. Account accTest = new Account();
  25. accTest.Name = 'Test Account';
  26. insert accTest;
  27.  
  28. Test.startTest();
  29. PageReference pageRef = Page.bcTest; // Add your VF page Name here
  30. pageRef.getParameters().put('id', String.valueOf(testBill.Id));
  31. Test.setCurrentPage(pageRef);
  32.  
  33.  
  34. List<wrapperCase> wrapList = new List<wrapperCase>();
  35. List<Contingency__c> selCase = new List<Contingency__c>();
  36.  
  37. for(Contingency__c b : [Select id, name,
  38. contingency__c, VENDOR_INVOICE__r.Account_del__r.Id from Contingency__c
  39. where (VENDOR_INVOICE__r.Account_del__r.Id = :accTest.Id) ]){
  40. wrapList.add(New wrapperCase(b));
  41. }
  42.  
  43.  
  44. for(wrapperCase WATest: wrapList){
  45. WATest.check = true;
  46. }
  47.  
  48.  
  49. System.assertEquals(testBill.Id, caseTest.Bill_Form__c);
  50. System.assertEquals('Test name',testBill.Name);
  51. System.assertEquals('IN BILLING', caseTest.CONTINGENCY__c);
  52.  
  53. test.stopTest();
  54. }
  55. public class wrapperCase{
  56. public contingency__c con{get;set;}
  57. public boolean check{get;set;}
  58. public wrapperCase(contingency__c c){
  59. con = c;
  60. check = false;
  61. }
  62. }
  63.  
  64. public with sharing class test2 {
  65. //Declare varialbles
  66. public string lookup{get;set;}
  67. public list<conCase> caseList{get;set;}
  68. public boolean allbool{get;set;}
  69. public string inputValue{get;set;}
  70. public boolean bool{get;set;}
  71. public set<id> caseIds{get;set;}
  72. Billing_Change_form__c[] accID = [Select account__c from
  73. Billing_Change_Form__c where id =
  74. :System.currentPagereference().getParameters().get('id')];
  75.  
  76.  
  77. ApexPages.StandardController controller;
  78.  
  79. //Constructor
  80. public test2(ApexPages.StandardController con){
  81. controller = con;
  82. caseList = new list<conCase>();
  83. bool = false;
  84. caseIds = new Set<id>();
  85. }
  86.  
  87.  
  88. //Event on clicking the checkbox
  89. public void inIt(){
  90. List<Contingency__c> selectedCase = new list<Contingency__c>();
  91. lookUp = '';
  92. for(conCase conObj : caseList){
  93. if(conObj.check != False){
  94. system.debug('conObj.con'+ conObj.con);
  95. selectedCase.add(conObj.con);
  96. lookUp += conObj.con.name + ', ';
  97. system.debug('lookup:'+ lookup);
  98. caseIds.add(conObj.con.id);
  99. bool = true;
  100. }
  101. If(conObj.check != true){
  102. caseIds.remove(conObj.con.id); }
  103. }
  104. }
  105.  
  106. //Displaying the records
  107. public List<conCase> getShow(){
  108. caseList = new list <conCase> ();
  109.  
  110. for(Contingency__c coObj : [Select id, name,billing_type__c, report_description__c, discovery_amount__c,
  111. billing_begins_date__c, contingency__c, VENDOR_INVOICE__r.Account_del__r.Id from Contingency__c
  112. where (VENDOR_INVOICE__r.Account_del__r.Id = :accID[0].Account__c) AND (Bill_form__c = null)])
  113.  
  114. {
  115. caseList.add(new conCase(coObj, Bool));
  116. }
  117.  
  118. return caseList;
  119. }
  120.  
  121. //Event on saving the selected records
  122. public PageReference mySave(){
  123. list<Contingency__c> updateSelectedCase = new list<Contingency__c>();
  124. id billId = ApexPages.currentPage().getparameters().get('id');
  125. System.debug('Bill ID is' + billID);
  126. for(Contingency__c co:[select id, name, bill_form__c from Contingency__c where id = :caseIds ]){
  127. co.bill_form__c = billId;
  128. updateSelectedCase.add(co);
  129. }
  130. update updateSelectedCase;
  131. return null;
  132. }
  133.  
  134. //Event When the cancel button is hit
  135. public void closePopup(){
  136. bool = false;
  137. }
  138. public void add(){
  139. bool = true;
  140. }
  141.  
  142. //Wrapper class for the selected records
  143. public class conCase{
  144. public contingency__c con{get;set;}
  145. public boolean check{get;set;}
  146. public conCase(contingency__c c, boolean boo){
  147. con = c;
  148. check = boo;
  149. }
  150. }
  151.  
  152. }
  153.  
  154. <apex:page showHeader="False" standardController="Billing_Change_Form__c"
  155. extensions="test2">
  156. <script>
  157. function closeWindow(){
  158. window.opener.location.href="/{!$CurrentPage.parameters.id}";
  159. window.top.close();
  160. }
  161. </script>
  162.  
  163. <apex:form >
  164. <apex:PageBlock title="CaseFindings" id="counter">
  165.  
  166. <apex:pageBlockButtons >
  167. <apex:commandButton value="Save" action="{!mySave}" onComplete="closeWindow();"/>
  168. <apex:commandButton value="Cancel" onclick="window.top.close();" immediate="true" action="{!closePopup}"/>
  169. </apex:pageBlockButtons>
  170.  
  171. <apex:pageBlockTable value="{!show}" var="e" title="show">
  172.  
  173. <apex:column >
  174. <apex:inputCheckbox value="{!e.check}" />
  175. <apex:actionSupport event="onclick" action="{!inIt}" rerender="none"/>
  176. </apex:column>
  177.  
  178. <apex:column value="{!e.con.Name}"/>
  179. <apex:column value="{!e.con.DISCOVERY_AMOUNT__c}"/>
  180. <apex:column value="{!e.con.BILLING_BEGINS_DATE__c}"/>
  181. <apex:column value="{!e.con.REPORT_DESCRIPTION__c}"/>
  182. <apex:column value="{!e.con.CONTINGENCY__c}"/>
  183. </apex:pageBlockTable>
  184. </apex:PageBlock>
  185. </apex:form>
  186. </apex:page>
Add Comment
Please, Sign In to add comment