@isTest
private class SWOTriggerHandlerTest {
    static testMethod void testMethod1() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD'];
        Id pricebookId = Test.getStandardPricebookId();
        
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            CurrencyIsoCode = 'CNY'
        );
        insert pricebook;
        
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.IsActive = true;
        product1.ProductCode = 'product1';
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
        insert product1;

        User_FaultInfo__c uf = new User_FaultInfo__c();
        // uf.Name = 'Test';
        insert uf;

         List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        Profile prof = [select Id from Profile where Name ='SSBG DEALER IE'];
        Account dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'BS';
        dealer.PostCode__c='000000';
        insert dealer;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        User testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = '00e28000001sZE6',TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');

        User user2 = new User();
        user2.LastName = 'test2';
        user2.FirstName = 'test2';
        user2.Alias = 'test2';
        user2.Email = 'test2@test.com';
        user2.Username = 'Xin_Prectech@olympus.com.cn';
        user2.CommunityNickname = 'test2';
        user2.IsActive = true;
        user2.EmailEncodingKey = 'ISO-2022-JP';
        user2.TimeZoneSidKey = 'Asia/Tokyo';
        user2.LocaleSidKey = 'ja_JP';
        user2.LanguageLocaleKey = 'ja';
        user2.ProfileId = '00e28000001sZE6';//System.Label.SystemAdmin;
        insert user2;

        SWO__c swo = new SWO__c();
        swo.Name = 'Test';
        swo.QUANTITY__c = 22;
        swo.ESTIMATED_LABOUR_HOURS__c = 22;
        swo.LABOUR_RATE__c = 22;
        swo.OFFICE__c = 'Beijing';
        swo.SWO_PRIORITY__c = 'Medium';
        swo.SWO_STATUS__c = 'Close Denied';
        swo.TYPE__c = 'Service';
        swo.ASSIGNEDTO__c = user2.Id;
        swo.DEPARTMENT__c = 'Field Service';
        swo.REASON__c = 'Replacement';
        swo.PRODUCT_TYPE__c = 'NDT';
        swo.ITEM__c = product1.Id;
        swo.INSTRUMENT_RECEIVE_DATE__c = Datetime.now();
        swo.INSTRUMENT_SHIP_DATE__c = Datetime.now().addDays(1);
        swo.DIAGNOSIS_START__c = Datetime.now();
        swo.DIAGNOSIS_END__c = Datetime.now().addDays(1);
        swo.PO_RECEIVE_DATE__c = Datetime.now();
        swo.Quotation_send__c = Datetime.now().addDays(1);
        swo.REPAIR_START__c = Datetime.now();
        swo.REPAIR_END__c = Datetime.now().addDays(1);

        swo.CALIBRATION_START__c = Datetime.now();
        swo.CALIBRATION_END__c = Datetime.now().addDays(1);

        swo.FQC_START__c = Datetime.now();
        swo.FQC_end__c = Datetime.now().addDays(1);

        swo.Repair_DateTime__c = Datetime.now();
        swo.DELIVERED_TO_SERVICE__c = Datetime.now().addDays(1);
        swo.CASE_NUMBER__c = uf.Id;

        insert swo;
        swo.SWO_STATUS__c = 'Quotation approved';
        update swo;
        swo.SWO_STATUS__c = 'Quotation for approval';
        update swo;
        swo.SWO_STATUS__c = 'Parts Hold';
        update swo;
        swo.SWO_STATUS__c = 'Delivered to Technician';
        update swo;
        swo.SWO_STATUS__c = 'Ready to Quote';
        update swo;
        swo.SWO_STATUS__c = 'Ready for Sales order';
        update swo;
        swo.SWO_STATUS__c = 'Repair';
        update swo;
        swo.SWO_STATUS__c = 'In Queue';
        update swo;
        swo.SWO_STATUS__c = 'Close cancel';
        update swo;
        swo.SWO_STATUS__c = 'Close Denied';
        update swo;
        swo.SWO_STATUS__c = 'Parts request for diagnosis';
        update swo;
        swo.SWO_STATUS__c = 'Parts ready for diagnosis';
        update swo;
        swo.SWO_STATUS__c = 'Ready to ship';
        update swo;
        swo.SWO_STATUS__c = 'Ready for Customer pickup';
        update swo;
        User user3 = user2;
        user3.Id = null;
        user3.LastName = 'test3';
        user3.FirstName = 'test3';
        user3.Alias = 'test3';
        user3.Email = 'test3@test.com';
        user3.Username = 'Dai_Prectech@olympus.com.cn';
        user3.CommunityNickname = 'test3';
        insert user3;
        swo.ASSIGNEDTO__c = user3.Id;
        update swo;
    }
}