/** 
 | 
 * @file         ADSO-10148 
 | 
 * @description  General settings Shelf Life - not usable if mature + expire within period 
 | 
 * @testcategory Web - Shelf life 
 | 
 * @author       Umar Adkhamov (umar.adkhamov@3ds.com) 
 | 
 * @copyright    Dassault Systèmes 
 | 
 */ 
 | 
import { AppMP, Demo, Scenario } from '../../libmp/appmp'; 
 | 
import { qCustomMatcher } from '../../e2elib/lib/src/main/qmatchers.const'; 
 | 
import { ListProductContextMenuItem } from '../../libmp/forms/form.product'; 
 | 
import { 
 | 
  DataMatrixProductPlanningAttributeName, 
 | 
  DataMatrixProductPlanningRowName, 
 | 
  DataMatrixProductPlanningValue, 
 | 
} from '../../libmp/data/data.supplyplanning'; 
 | 
import { DialogSmartPlanDirectionRadioButton } from '../../libmp/dialogs/dialog.smartplan'; 
 | 
import { DataLowFatStrawberry12 } from '../../libmp/data/data.navigation'; 
 | 
import { LogMessage } from '../../libappbase/logmessage'; 
 | 
import { startOfPlanningYear } from '../../libmp/data/data.period'; 
 | 
  
 | 
describe('ADSO-10148 - General settings Shelf Life, not usable if mature + expire within period', () => { 
 | 
  const appMP = AppMP.getInstance(); 
 | 
  const datesToBeChecked: string[] = [ 
 | 
    `1-Jan-${startOfPlanningYear}`, 
 | 
    `1-Feb-${startOfPlanningYear}`, 
 | 
    `1-Mar-${startOfPlanningYear}`, 
 | 
    `1-Apr-${startOfPlanningYear}`, 
 | 
  ]; 
 | 
  const listProduct = appMP.viewProduct.frmProduct.listProduct; 
 | 
  const formProductPlanning = appMP.viewSupplyPlanning.frmProductPlanning; 
 | 
  const meRowName = DataMatrixProductPlanningRowName.LowFat12PKBulgaria; 
 | 
  const mePlanningValue = +(DataMatrixProductPlanningValue._10000.replace(',', '')); 
 | 
  
 | 
  beforeAll(async () => { 
 | 
    jasmine.addMatchers(qCustomMatcher); 
 | 
    await appMP.login(); 
 | 
  }); 
 | 
  
 | 
  afterAll(async () => { 
 | 
    await appMP.viewProduct.reset(); 
 | 
    await appMP.cleanupAndLogout(); 
 | 
  }); 
 | 
  
 | 
  afterEach(async () => { 
 | 
    await appMP.checkToastMessage(); 
 | 
  }); 
 | 
  
 | 
  it(`Setup - ${AppMP.getDemoDataPath(Demo.Food, Scenario.Base)}`, async () => { 
 | 
    await appMP.createDemoDataset(Demo.Food, Scenario.Base); 
 | 
  }); 
 | 
  
 | 
  it(`Setup - Open view ${appMP.viewProduct.viewPath}. Set new Shelf-life and Maturation values to "${DataLowFatStrawberry12.name}"`, async () => { 
 | 
    // Open Products view 
 | 
    await appMP.viewProduct.switchTo(); 
 | 
  
 | 
    const productRow = await listProduct.getRow({Name: DataLowFatStrawberry12.name}, DataLowFatStrawberry12.parents); 
 | 
    const [dialog] = await listProduct.selectContextMenu(ListProductContextMenuItem.Edit, productRow); 
 | 
    await dialog.pnlAdvanced.clickTab(); 
 | 
    await dialog.updateDialogValues({ShelfLifeEnabled: 'true', ShelfLife: '145', MaturationEnabled: 'true', Maturation: '45'}); 
 | 
    await dialog.clickOK(); 
 | 
  }); 
 | 
  
 | 
  it(`Setup - Open view ${appMP.viewGeneralSettings.viewPath}. Uncheck "If Expired Within Period/If Mature Within Period" checkboxes`, async () => { 
 | 
    // Open General Settings view 
 | 
    await appMP.viewGeneralSettings.switchTo(); 
 | 
    const formGeneralSettings = appMP.viewGeneralSettings.frmGeneralSettings; 
 | 
  
 | 
    // Uncheck "If Expired Within Period/If Mature Within Period" checkboxes 
 | 
    await formGeneralSettings.updateDialogValues({UsableIfMature: 'false', UsableIfExpired: 'false'}); 
 | 
  
 | 
    // Verify the checkboxes are unchecked 
 | 
    expect(await formGeneralSettings.cbIsUsableIfExpiredWithinPeriod.isChecked()).toBe(false, LogMessage.checkbox_isChecked('Is usable if expired within period')); 
 | 
    expect(await formGeneralSettings.cbIsUsableIfMatureWithinPeriod.isChecked()).toBe(false, LogMessage.checkbox_isChecked('Is usable if matured within period')); 
 | 
  
 | 
    // Click on Apply button to save changes 
 | 
    const [isApplyButtonClickable, btnDisabledTooltip] = await formGeneralSettings.btnApply.getIsClickable(); 
 | 
    expect(isApplyButtonClickable).toBe(true, LogMessage.btn_notClickable('Apply', btnDisabledTooltip)); 
 | 
    await formGeneralSettings.btnApply.click(); 
 | 
  }); 
 | 
  
 | 
  it(`Step 1 - Open view ${appMP.viewSupplyPlanning.viewPath} and reset plan`, async () => { 
 | 
    // Open General Settings view 
 | 
    await appMP.viewSupplyPlanning.switchTo(); 
 | 
    // Reset plan 
 | 
    await appMP.abpPlan.resetPlanAll(); 
 | 
  }); 
 | 
  
 | 
  it(`Step 2 - Select "${DialogSmartPlanDirectionRadioButton.Upstream}" Smart Plan for "${meRowName}"`, async () => { 
 | 
    // Select first row to be able to use DOWN key on the MatrixEditor 
 | 
    await formProductPlanning.meProductPlanning.selectByRow(0); 
 | 
    // HACK: Scroll to the desired row by pressing DOWN key 
 | 
    await formProductPlanning.meProductPlanning.scrollToRowByRowHeader(meRowName); 
 | 
    // Set "Upstream" Smart Plan direction 
 | 
    const dlgSmartPlan = await formProductPlanning.meProductPlanning.startSettingSmartPlanDirection(0, datesToBeChecked[0]); 
 | 
    await dlgSmartPlan.selectSmartPlanDirection(DialogSmartPlanDirectionRadioButton.Upstream); 
 | 
  
 | 
    // Verify if optimizer run finish 
 | 
    const isOptimizerFinished = await appMP.abpScenarioSelection.verifyIsOptimizerCompleted(5000); 
 | 
    expect(isOptimizerFinished).toBe(true, 'Optimizer triggered after change smart plan direction should be finished in 1 second.'); 
 | 
  }); 
 | 
  
 | 
  it(`Step 3 - Set new ${DataMatrixProductPlanningAttributeName.TotalSupply} for "${meRowName}" and verify its utilization`, async () => { 
 | 
    // Set Total Supply value 
 | 
    await formProductPlanning.meProductPlanning.setTotalSupply(0, datesToBeChecked[0], mePlanningValue); 
 | 
  
 | 
    // Verify if optimizer run finish 
 | 
    const isOptimizerFinished = await appMP.abpScenarioSelection.verifyIsOptimizerCompleted(5000); 
 | 
    expect(isOptimizerFinished).toBe(true, 'Optimizer triggered after entered Total Supply value should be finished in 5 second.'); 
 | 
  
 | 
    // Verify that the quantity is not used to supply demand on the periods of January and Feb SOPYear 
 | 
    for (let index = 0; index < 2; index++) { 
 | 
      const cell = await formProductPlanning.meProductPlanning.getCell(meRowName, DataMatrixProductPlanningAttributeName.InventoryEnd, datesToBeChecked[index]); 
 | 
      expect(await cell.getValue()).toBe( 
 | 
        DataMatrixProductPlanningValue._10000, 
 | 
        `${DataMatrixProductPlanningAttributeName.InventoryEnd} value should be ${DataMatrixProductPlanningValue._10000} for ${datesToBeChecked[index]}`, 
 | 
      ); 
 | 
    } 
 | 
  
 | 
    // Verify that the quantity is used to supply demand on the periods of March SOPYear and April SOPYear 
 | 
    for (let index = 2; index < 4; index++) { 
 | 
      const cell = await formProductPlanning.meProductPlanning.getCell(meRowName, DataMatrixProductPlanningAttributeName.InventoryEnd, datesToBeChecked[index]); 
 | 
      const cellValue = await cell.getValue(); 
 | 
      // As we can't direct convert "10,000" type string value to number. Thus, we have to replace "," to empty string in order to convert 
 | 
      const cellValueInNumber = +(cellValue.replace(',', '')); 
 | 
      expect(cellValueInNumber).toBeLessThan( 
 | 
        mePlanningValue, 
 | 
        `${DataMatrixProductPlanningAttributeName.InventoryEnd} value should not be ${DataMatrixProductPlanningValue._10000} for ${datesToBeChecked[index]}`, 
 | 
      ); 
 | 
    } 
 | 
  }); 
 | 
}); 
 |