+ Start a Discussion
Deepu161Deepu161 

where am lagging to get 100% code coverage, i have 89% now


======================test class======================
@isTest
public class showallTimeCatdsCtrl2_Test{
public static testMethod void showtimcardMethod(){
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        User u = new User(  Alias = 'standt', Email='standarduser@testorg.com', EmailEncodingKey='UTF-8',
                            LastName='Testing123', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id,
                            TimeZoneSidKey='America/Los_Angeles', UserName='standarduser123@testorg.com');

        Account acc = new Account();
        acc.Name = 'test';
        insert acc;
        System.assertEquals('test',acc.Name);

        Contact cont = new Contact();
        cont.FirstName='Test';
        cont.LastName='Test';
        cont.Accountid= acc.id;
        insert cont;

        Employee__c emp=new Employee__c();
        emp.Name='pradeep';
        emp.Active__c=true;
        emp.Subcontractor_Account__c=acc.id;
        emp.Reports_to__c=u.id;
        emp.Portal_Contact__c=cont.id;
        emp.Phone__c='984466';
        insert emp;
        System.assertEquals('pradeep',emp.Name);

        Project__c prj=new Project__c();
        prj.Name='salesforceproject';
        prj.Account__c=acc.id;
        prj.Account_Manager__c=emp.id;
        prj.Client__c=cont.id;
        prj.Account_Manager__c=emp.id;
        insert prj;
        System.assertEquals('salesforceproject',prj.Name);

        Employee__c emp2=new Employee__c();
        emp2.Name='ramesh';
        emp2.Active__c=true;
        emp2.Subcontractor_Account__c=acc.id;
        emp2.Reports_to__c=u.id;
        emp2.Portal_Contact__c=cont.id;
        emp2.Phone__c='9846';
        insert emp2;
        System.assertEquals('ramesh',emp2.Name);

        prj.Resource1__c = emp2.Id;
        prj.Pay1__c = 100;
        update prj;

        Employee_Rate_Card__c empRateCard = new Employee_Rate_Card__c();
        empRateCard.Resource__c = emp2.Id;
        empRateCard.Project__c = prj.Id;
        empRateCard.From__c = Date.today().addDays(-7);
        empRateCard.To__c = Date.today().addDays(7);
        empRateCard.Rate__c = 50;
        insert empRateCard;

        Invoice__c inv=new Invoice__c();
        inv.Account__c=acc.id;
        inv.CurrencyIsoCode='USD';
        inv.Project__c=prj.id;
        inv.Sub_Contractor_Employee__c=emp.id;
        inv.Service_Term_From__c=Date.Today().addDays(-7);
        inv.Service_Term_To__c=Date.Today().addDays(7);
        inv.Amount__c=10000;
        insert inv;


        Timecard__c tc= new Timecard__c();
        tc.Employee__c = emp2.id;
        tc.Project__c = prj.id;
        tc.Total__c = 1000;
        tc.Status__c = 'Approved';
        tc.Hours__c = 10;
        tc.Client_Pay__c=100;
        tc.Invoice__c = inv.Id;
        tc.Date_Of_Service__c = Date.today();
        system.debug('==================='+ tc.Date_Of_Service__c);
        System.debug('Time card = ' + tc);
        insert tc;

        Timecard__c tc1 = new Timecard__c();
        tc1.Employee__c=emp2.id;
        tc1.Project__c=prj.id;
        tc1.Total__c=1000;
        tc1.Status__c='Approved';
        tc1.Hours__c=10;
        tc1.Client_Pay__c=100;
        tc1.Date_Of_Service__c = Date.today();
        system.debug('==================='+ tc1.Date_Of_Service__c);
        System.debug('Time card = ' + tc1);
        insert tc1;

        System.debug('lstTimeCard = ' + [SELECT Id, Client_Pay__c, Client_Pay_Per_Day__c FROM Timecard__c]);

        /**Timecard__c tc1=new Timecard__c();
        tc1.Employee__c=emp2.id;
        tc1.Project__c=prj.id;
        tc1.Invoice__c=inv.id;
        tc1.Total__c=1000;
        tc1.Status__c='Approved';
        tc1.Hours__c=10;
        tc1.Client_Pay__c=100;
        tc1.Date_Of_Service__c=Date.Today().addDays(-40);
        system.debug('==================='+ tc.Date_Of_Service__c);
        Insert tc1;**/



        list<Timecard__c >lstTimeCards =[select id, name ,Timecard__c.project__r.name,Timecard__c.project__r.Account_Manager__r.Name,project__r.owner.name, Work_Description__c,
                   Timecard__c.Employee__r.Name,Date_Of_Service__c,Balance_Due__c, Hours__c, invoice__r.Service_Term_From__c,invoice__r.Service_Term_To__c,
                    Client_Pay__c from Timecard__c where project__c =:inv.Project__c and Date_Of_Service__c >= :inv.Service_Term_From__c and Date_Of_Service__c  <= :inv.Service_Term_To__c order by Employee__c];
        system.debug('==================='+lstTimeCards );



        list<Account>accRec=[SELECT Id, Name,BillingStreet, BillingCity, BillingState,
            BillingPostalCode, BillingCountry FROM Account WHERE Id=:acc.id];

        Test.setCurrentPage(Page.ShowAllTimecards2);
        ApexPages.currentPage().getParameters().put('id',inv.id);
        ApexPages.StandardController sc = new ApexPages.standardController(inv);
        ShowallTimeCatdsCtrl2 objTimecrd = new ShowallTimeCatdsCtrl2(sc);
        ShowallTimeCatdsCtrl2.timeCardWrapClass tem = new ShowallTimeCatdsCtrl2.timeCardWrapClass();
        //ShowallTimeCatdsCtrl2.wrapclass tem1=new ShowallTimeCatdsCtrl2.wrapclass(lstToInsert[0],123,'hi',123);

        objTimecrd.onload();
        objTimecrd.calculateData();
        objTimecrd.check = false;
        objTimecrd.empname = emp2.Name;
        objTimecrd.headCheckselection();
        objTimecrd.calculateData();
        objTimecrd.check = true;
        objTimecrd.headCheckselection();
        objTimecrd.calculateData();
        objTimecrd.eeName = emp2.Name;
        objTimecrd.subCheck = false;
        objTimecrd.ChildCheckSelection();
        objTimecrd.calculateData();
        objTimecrd.subCheck = true;
        objTimecrd.ChildCheckSelection();
        objTimecrd.calculateData();
        objTimecrd.eName = emp2.Name;
        objTimecrd.calculateEmpDataSub();
        objTimecrd.selectcheckbox();
        objTimecrd.timecards();
        objTimecrd.generateinvoice();
        objTimecrd.saveinvoice();
        objTimecrd.sendPdf();
        objTimecrd.downloadPDF();
        objTimecrd.saveandnew();
        objTimecrd.cancelInv();
        objTimecrd.getallAttachments();
        objTimecrd.getalTimecrds();
        objTimecrd.calculateDataAmount();
        objTimecrd.selectDeselect();
        objTimecrd.dosave();
        objTimecrd.redirectInvPage();
        System.debug(objTimecrd.parentCheckBoxVal);
        System.debug(objTimecrd.recordTypename);
        System.debug(objTimecrd.isExport);
        System.debug(objTimecrd.totalAmount);
        System.debug(objTimecrd.allBool);
        System.debug(objTimecrd.product);
        System.debug(objTimecrd.defalval);
        System.debug(objTimecrd.attachment);
        System.debug(objTimecrd.newwrap.hoursAndUnitprice);
        System.debug(objTimecrd.newwrap.totHrs);
    }
}