Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
 * @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]}`,
      );
    }
  });
});