@isTest
public with sharing class OpportunityMessageControllerTest {

    static testMethod void myTest1() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCodeD__c='000000',
            PostCode__c='000000'
        );
        insert accIE; 
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE'
        );
        insert pricebook;
         
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct'
        );
        insert opp;
         //画面迁移--留言画面
        PageReference page = new PageReference('/apex/OpportunityMessagePopUp?raid=' + opp.Id );
        System.Test.setCurrentPage(page);
        
        OpportunityMessageController controller = new OpportunityMessageController();
        

        //取得询价
        Opportunity opp1 = [select Id, Name, OCN_Internal_Notes__c from Opportunity where Id = :opp.Id];

        //初始化
        controller.init1();
        System.assertEquals('', controller.ra1.OCN_Internal_Notes__c);
        
        //发送按钮
        controller.ra1.OCN_Internal_Notes__c = 'test1';

        //保存后
        controller.saveBtn();
    }

    static testMethod void myTest2() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCodeD__c='000000',
            PostCode__c='000000'
        );
        insert accIE; 
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE'
        );
        insert pricebook;
         
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            OCN_Internal_Notes__c = 'test1',
            SalesChannel__c = 'direct'
        );
        insert opp;
         //画面迁移--留言画面
        PageReference page = new PageReference('/apex/OpportunityMessagePopUp?raid=' + opp.Id );
        System.Test.setCurrentPage(page);
        
        OpportunityMessageController controller = new OpportunityMessageController();
        

        //取得询价
        Opportunity opp1 = [select Id, Name, OCN_Internal_Notes__c from Opportunity where Id = :opp.Id];

        //初始化
        controller.init();
        //System.assertEquals('', controller.ra1.OCN_Internal_Notes__c);
        
        //发送按钮
        controller.ra1 = opp1;
        controller.ra1.OCN_Internal_Notes__c = '';

        //保存后
        controller.saveBtn();
    }
}