Skip to content

Commit

Permalink
added working test classes for print
Browse files Browse the repository at this point in the history
  • Loading branch information
airwin606 committed Jul 1, 2020
1 parent 3be84da commit f4b1e3b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 7 deletions.
5 changes: 1 addition & 4 deletions force-app/main/default/classes/ServicePrint.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ public class ServicePrint {


@AuraEnabled
public String serviceId {get;set;}
public Service__c service {get;set;}
public List<Open_Hours__c> hrs {get;set;}
public List<Open_Hours__c> allHours {get;set;}
public String Sunday {
get {
if(Sunday == null){
Expand Down Expand Up @@ -84,7 +81,7 @@ public class ServicePrint {
}

public Service__c getServices(string serviceId) {
Service__c newserv = [SELECT Id, Name, Account__r.Name, Type__c,Description__c, Website__c, Account__r.ShippingStreet, Account__r.ShippingCity, Account__r.ShippingState, Account__r.ShippingPostalCode, Account__r.Phone FROM Service__c WHERE Id = :serviceId];
Service__c newserv = [SELECT Id, Name, Account__r.Name, Type__c,Description__c, Website__c, Street__c, City__c, Zip_Code__c, Phone__c FROM Service__c WHERE Id = :serviceId];
system.debug('serv' + newserv);
return newserv;
}
Expand Down
80 changes: 80 additions & 0 deletions force-app/main/default/classes/Test_ServicePrint.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,73 @@
private with sharing class Test_ServicePrint {
@testSetup
static void makeData() {
Time start = Time.newInstance(9,0,0,0);
Time stop = Time.newInstance(17,0,0,0);
contact c = new Contact();
c.LastName = 'TestContact';
insert c;

Service__c s = new Service__c();
s.Name = 'Test Service for Printing';
insert s;

Open_Hours__c ohSun = new Open_Hours__c();
ohSun.Service__c = s.Id;
ohSun.End_Time__c = stop;
ohSun.Start_Time__c = start;
ohSun.Day__c = 'Sunday';
insert ohSun;

Open_Hours__c ohM = new Open_Hours__c();
ohM.Service__c = s.Id;
ohM.End_Time__c = stop;
ohM.Start_Time__c = start;
ohM.Day__c = 'Monday';
insert ohM;

Open_Hours__c ohTu = new Open_Hours__c();
ohTu.Service__c = s.Id;
ohTu.End_Time__c = stop;
ohTu.Start_Time__c = start;
ohTu.Day__c = 'Tuesday';
insert ohTu;

Open_Hours__c ohW = new Open_Hours__c();
ohW.Service__c = s.Id;
ohW.End_Time__c = stop;
ohW.Start_Time__c = start;
ohW.Day__c = 'Wednesday';
insert ohW;

Open_Hours__c ohT = new Open_Hours__c();
ohT.Service__c = s.Id;
ohT.End_Time__c = stop;
ohT.Start_Time__c = start;
ohT.Day__c = 'Thursday';
insert ohT;

Open_Hours__c ohF = new Open_Hours__c();
ohF.Service__c = s.Id;
ohF.End_Time__c = stop;
ohF.Start_Time__c = start;
ohF.Day__c = 'Friday';
insert ohF;

Open_Hours__c ohSat = new Open_Hours__c();
ohSat.Service__c = s.Id;
ohSat.End_Time__c = stop;
ohSat.Start_Time__c = start;
ohSat.Day__c = 'Saturday';
insert ohSat;

}

static testMethod void printReferral() {
id contactId = getTestContactId();
id serviceId = getTestServiceId();

Test.StartTest();

ServicePrint.PrintPage(serviceId);
Test.StopTest();

Expand All @@ -24,6 +77,31 @@ private with sharing class Test_ServicePrint {
System.assertEquals(attachs[0].ParentId, serviceId);
}

static testMethod void openHours() {
system.debug('running open hours');
id serviceId = getTestServiceId();

ApexPages.CurrentPage().getParameters().put('servId',serviceId);
System.debug(serviceId);
Test.StartTest();
ServicePrint servP = new ServicePrint();
servP.Saturday = null;
servP.Sunday = null;
servP.Wednesday = null;
servP.Friday = null;
Test.StopTest();

List<Open_Hours__c> openHrs = [SELECT Id,Day__c, End_Time__c, Start_Time__c, Service__c FROM Open_Hours__c WHERE Service__c = :serviceId];

system.assertEquals(openHrs.Size(), 7);
system.assertEquals(servP.Saturday, 'S: Closed');
system.assertEquals(servP.Sunday, 'S: Closed');
system.assertEquals(servP.Wednesday, 'W: Closed');
system.assertEquals(servP.Friday, 'F: Closed');


}


private static Id getTestContactId() {
return [SELECT id FROM Contact WHERE LastName = 'TestContact'].Id;
Expand All @@ -32,5 +110,7 @@ private with sharing class Test_ServicePrint {
private static Id getTestServiceId() {
return [SELECT id FROM Service__c WHERE Name = 'Test Service for Printing'].Id;
}



}
6 changes: 3 additions & 3 deletions force-app/main/default/pages/ServicePrintPage.page
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<div>
<h3>Contact Information</h3>

<p>{!service.Account__r.ShippingStreet}</p>
<p>{!service.Account__r.ShippingCity}, {!service.Account__r.ShippingState} {!service.Account__r.ShippingPostalCode}</p>
<p>{!service.Account__r.Phone}</p>
<p>{!service.Street__c}</p>
<p>{!service.City__c}, {!service.Zip_Code__c}</p>
<p>{!service.Phone__c}</p>
<a href='{!service.Website__c}'>{!service.Website__c}</a>
</div>

Expand Down

0 comments on commit f4b1e3b

Please sign in to comment.