yanweiyuan3
2023-10-10 d901b1ab0ee0b690f5ac211b9cdb1db3a58bca86
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
/**
 * @file         ADSO-10184 - Edit single stocking cost - not unique cost encountered
 * @description  Edit single stocking cost and enter existed start date to verify ok button in dialog is clickable
 * @testcategory Web - Financials - Stocking points
 * @author       Wong Jia Hui (jiahui.wong@3ds.com)
 * @copyright    Dassault Systèmes
 */
import { qCustomMatcher } from '../../../e2elib/lib/src/main/qmatchers.const';
import { ListRow } from '../../../e2elib/lib/src/pageobjects/list/listrow.component';
import { LogMessage } from '../../../libappbase/logmessage';
import { AppMP, Demo, Scenario } from '../../../libmp/appmp';
import { DataFoodBaseEntityName } from '../../../libmp/data/data.navigation';
import { DataFoodBaseStockingCostStartDate } from '../../../libmp/data/data.stockingcost';
import { DataFoodBaseAccountCost, DataFoodBaseAccountCostDriver, DataFoodBaseAccountName } from '../../../libmp/data/data.account';
import { ListStockingCostColumn } from '../../../libmp/forms/form.stockingcost';
import { ColumnIDValueMap } from '../../../libappbase/listbase';
import { ActionTriggerType } from '../../../libappbase/utils';
import { startOfPlanningYear } from '../../../libmp/data/data.period';
 
describe('ADSO-10184 - Edit single stocking cost - not unique cost encountered', () => {
  // Component used in this script
  const appMP = AppMP.getInstance();
  const listStockingCost = appMP.viewStockingCost.frmStockingCost.lstStockingCost;
  let dlgStockingCost = listStockingCost.dlgStockingCost;
 
  // Variable used across multiple steps
  const stockingPoint = DataFoodBaseEntityName.DCAustria;
  const account = DataFoodBaseAccountName.GeneralFixedCosts;
  const costDriver = DataFoodBaseAccountCostDriver.Fixed;
  const expectedTooltip = 'Identical cost definition exists. Stocking cost must be unique by Account, Cost driver and Start date.';
  let sopYear: string;
  const stockingCostStartDate1 = `1-Jan-${startOfPlanningYear - 1}`;
  const stockingCostStartWithoutYear = DataFoodBaseStockingCostStartDate._1JanWithoutYear;
  const editStartDateWithoutYear = DataFoodBaseStockingCostStartDate._1FebWithoutYear;
  let stockingCostStartDate2 = '';
  let editStartDate = '';
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    await appMP.cleanupAndLogout();
  });
 
  afterEach(async () => {
    await appMP.checkToastMessage();
  });
 
  it(`Setup - ${AppMP.getDemoDataPath(Demo.Food, Scenario.Base)}`, async () => {
    await appMP.createDemoDataset(Demo.Food, Scenario.Base, false);
  });
 
  it(`Setup - Open view ${appMP.viewPeriod.viewPath} to get the start of planning (SOP) year`, async () => {
    await appMP.viewPeriod.switchTo();
    const formPeriod = appMP.viewPeriod.frmPeriod;
    ({ sopYear } = await formPeriod.getStartAndEndOfPlanning());
    stockingCostStartDate2 = `${stockingCostStartWithoutYear}${sopYear}`;
    editStartDate = `${editStartDateWithoutYear}${sopYear}`;
  });
 
  it(`Setup - Open view ${appMP.viewStockingCost.viewPath}. \
      Ensure there are 2 stocking cost for ${stockingPoint} with start ${stockingCostStartDate1} and ${stockingCostStartWithoutYear}SOP year`, async () => {
    await appMP.viewStockingCost.switchTo();
    const startDateArray = [stockingCostStartDate1, stockingCostStartDate2];
    for (const startDate of startDateArray) {
      const scValueMap: ColumnIDValueMap[] = [
        { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint },
        { columnID: ListStockingCostColumn.Start, value: startDate },
      ];
 
      try {
        await listStockingCost.getRowByValue(scValueMap);
      } catch {
        dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu);
        await dlgStockingCost.updateDialog(account, costDriver, stockingPoint, new Date(startDate), DataFoodBaseAccountCost._1000);
        const [isOkButtonClickable, btnDisabledTooltip] = await dlgStockingCost.btnOk.verifyIsButtonClickable();
        expect(isOkButtonClickable).toBe(true, LogMessage.btn_notClickable('Ok', btnDisabledTooltip));
        await dlgStockingCost.clickOK();
      }
 
      const scRow: ListRow = await listStockingCost.getRowByValue(scValueMap);
      expect(scRow).toBeDefined(LogMessage.row_notFound(`SP = ${stockingPoint}, Start = ${startDate}`));
    }
  });
 
  it(`Step 1 - Edit cost of ${stockingPoint} with ${stockingCostStartDate1} to ${stockingCostStartWithoutYear}SOP year and verify ok button in dialog is disbaled`, async () => {
    const stockingCostRow = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint },
      { columnID: ListStockingCostColumn.Start, value: stockingCostStartDate1 },
    ]);
    dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu, stockingCostRow);
    await dlgStockingCost.dtsStart.setDate(new Date(stockingCostStartDate2));
    const [isOkButtonClickable, btnDisabledTooltip] = await dlgStockingCost.btnOk.verifyIsButtonClickable(1000);
    expect(isOkButtonClickable).toBe(false, LogMessage.btn_isEnabled('Ok'));
    expect(btnDisabledTooltip).toBe(expectedTooltip, LogMessage.tooltip_notMatched(expectedTooltip, btnDisabledTooltip));
  });
 
  it(`Step 2 - Change start value to ${editStartDateWithoutYear}SOP year and verify ok button in dialog is enabled`, async () => {
    await dlgStockingCost.dtsStart.setDate(new Date(editStartDate));
    const [isOkButtonClickable, btnDisabledTooltip] = await dlgStockingCost.btnOk.verifyIsButtonClickable();
    expect(isOkButtonClickable).toBe(true, LogMessage.btn_notClickable('Ok', btnDisabledTooltip));
    await dlgStockingCost.clickOK();
  });
 
  it(`Step 3 - Verify stocking costs for ${stockingPoint} has start date ${stockingCostStartDate2} and ${editStartDate}`, async () => {
    const startDateArray = [stockingCostStartDate2, editStartDate];
    for (const startDate of startDateArray) {
      const scRow = await listStockingCost
        .getRowByValue([
          { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint },
          { columnID: ListStockingCostColumn.Start, value: startDate },
        ])
        .catch(() => {
          // do nothing as error is thrown due to no row is found
        });
      expect(scRow).toBeDefined(LogMessage.row_notFound(`SP = ${stockingPoint}, Start = ${startDate}`));
    }
  });
});