renhao
2023-09-21 1aa9f2bb83dd9e4b7517f1cbf06b0db53979bb31
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
/**
 * @file         ADSO-10106
 * @description  Create unit cost by drag & drop multiple units onto account
 * @testcategory Web - Financials - Units
 * @author       Gay Er Xuan (erxuan.gay@3ds.com)
 * @copyright    Dassault Systemes
 */
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 { DataFoodBaseEntity, DataFoodBaseEntityName } from '../../../libmp/data/data.navigation';
import { DataFoodBaseUnitCostCost } from '../../../libmp/data/data.unitcost';
import { DataFoodBaseAccountName, DataFoodBaseAccountCost, DataFoodBaseAccountCostDriver, DataFoodBaseAccountLengthOfTime, DataFoodBaseAccountTimeUnit, DataFoodBaseAccountUoM, CostLabel } from '../../../libmp/data/data.account';
import { ListUnitCostColumn } from '../../../libmp/forms/form.unitcost';
 
describe('ADSO-10106 - Create unit cost by drag & drop multiple units onto account', () => {
  const appMP = AppMP.getInstance();
  const listAccount = appMP.viewAccount.frmAccount.listAccount;
  const listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost;
  let dlgUnitCost = listUnitCost.dlgUnitCost;
  let accountRow: ListRow;
  let newUnitStartDate: Date;
  let newUnitStartString: string;
  let endOfPlanningString: string;
  let sopYear: string;
  const account = DataFoodBaseAccountName.GeneralFixedCosts;
  const costDriver = DataFoodBaseAccountCostDriver.Fixed;
  const timeUnit = DataFoodBaseAccountTimeUnit.Quarter;
  const lengthOfTime = DataFoodBaseAccountLengthOfTime._2;
  const cost = DataFoodBaseAccountCost._122_22;
  const newCost = DataFoodBaseUnitCostCost._200;
  const units: string[] = [DataFoodBaseEntityName.DEFermenter, DataFoodBaseEntityName.DEPackaging];
  const unitParents: string[] = DataFoodBaseEntity.deUnitsParents;
  let canUpdate: boolean;
  let tooltip = '';
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    // Reset navigation
    await appMP.formNavigation.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, false);
  });
 
  it(`Setup - Open view ${appMP.viewPeriod.viewPath}. Get start and end of planning`, async () => {
    // Open Periods view
    await appMP.viewPeriod.switchTo();
    const formPeriod = appMP.viewPeriod.frmPeriod;
    ({ sopYear, eopString: endOfPlanningString } = await formPeriod.getStartAndEndOfPlanning());
    newUnitStartDate = new Date(Number(sopYear), 0, 1);
    newUnitStartString = `1-Jan-${sopYear}`;
  });
 
  it(`Setup - Open view ${appMP.viewAccount.viewPath}. Configure ${account}`, async () => {
    // Open account view
    await appMP.viewAccount.switchTo();
    await (await listAccount.getRow({ Name: DataFoodBaseAccountName.CostOfSales })).expandRow();
    const accRow = await listAccount.getRow({ Name: account });
    const dlgAccount = await listAccount.openAcountDialogViaEditContextMenu(accRow);
    await dlgAccount.updateDialogValues({ CostDriver: costDriver, Cost: cost.toString(), TimeUnit: timeUnit, LengthOfTime: lengthOfTime.toString() });
    canUpdate = await dlgAccount.clickOK();
    tooltip = canUpdate ? '' : await dlgAccount.getOKButtonTooltip();
    expect(canUpdate).toBe(true, LogMessage.btn_notClickable('OK', tooltip));
  });
 
  it(`Step 1 - Open view ${appMP.viewUnitCost.viewPath}. Create new ${units.join(', ')} unit costs for ${account} by drag and drop`, async () => {
    // Open unit cost view
    await appMP.viewUnitCost.switchTo();
    // Get account row
    accountRow = await appMP.viewUnitCost.frmUnitAccount.listAccount.getRow({ Account: account });
    // Open navigation panel and get stocking point row
    await appMP.formNavigation.openNavigationPanel();
    await appMP.formNavigation.toggleEntityList();
    const entityRows: ListRow[] = [];
    for (const unit of units) {
      const row = await appMP.formNavigation.listEntity.getEntityRowByName(unit, unitParents);
      if (row) {
        entityRows.push(row);
      }
    }
    dlgUnitCost = await listUnitCost.dragEntitiesToCreateUnitCost(entityRows, accountRow);
    // Verify dialog default value
    const feedback = await dlgUnitCost.verifyDialogValue(account, costDriver, undefined, newUnitStartDate, timeUnit, lengthOfTime, cost);
    expect(feedback.length).toBe(0, feedback.join('. \n'));
    expect(units.indexOf(await dlgUnitCost.ddlUnit.getSelectedString()) > -1).toBe(true, `Unit should be defaulted to any of ${units.join(', ')}`);
    expect(await dlgUnitCost.ddlUnit.isDisabled()).toBe(true, 'Unit drop down list should be disabled by default');
    // Update dialog value and confirm the dialog
    await dlgUnitCost.efCost.sendInput(newCost.toString());
    expect(await dlgUnitCost.efCost.getComponentLabel()).toBe(CostLabel.euro(`${lengthOfTime} ${timeUnit}`), `Label of cost should be ${CostLabel.euro(`${lengthOfTime} ${timeUnit}`)}`);
    canUpdate = await dlgUnitCost.clickOK();
    tooltip = canUpdate ? '' : await dlgUnitCost.getOKButtonTooltip();
    expect(canUpdate).toBe(true, LogMessage.btn_notClickable('OK', tooltip));
  });
 
  it('Step 2 - Verify multiple unit costs created with correct values', async () => {
    // Verify rows created with correct values in dialog
    for (const unit of units) {
      const newUnit = await listUnitCost.getUnitCostRowByValues(unit, account, costDriver, newUnitStartString);
      dlgUnitCost = await listUnitCost.openEditDialog(newUnit);
      const verifyAfterDialogFeedback = await dlgUnitCost.verifyDialogValue(account, costDriver, unit, newUnitStartDate, undefined, undefined, newCost);
      expect(verifyAfterDialogFeedback.length).toBe(0, verifyAfterDialogFeedback.join('. \n'));
      await dlgUnitCost.clickCancel();
      // Verify row created with correct values in list
      if (newUnit !== undefined) {
        // Verify UoM, Start, and End column value of the new row
        expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.UoM, newUnit)).toBe(`${DataFoodBaseAccountUoM.EuroPer}${lengthOfTime} ${timeUnit}`, `UoM of new ${unit} should be ${DataFoodBaseAccountUoM.EuroPer}${lengthOfTime} ${timeUnit}`);
        expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Start, newUnit)).toBe(newUnitStartString, `Start of new ${unit} should be ${newUnitStartString}`);
        expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, newUnit)).toBe(endOfPlanningString, `End of new ${unit} should be ${endOfPlanningString}`);
      } else {
        expect(newUnit).toBeDefined(`New ${unit} for ${account} that starts on ${newUnitStartString} should be created`);
      }
    }
  });
});