yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
 * @file         ADSO-10101 - Create unit cost for Fixed cost driver (from list context menu)
 * @description  Create unit cost for Fixed cost driver (from list context menu)
 * @testcategory Web - Financials - Units
 * @author       Umar Adkhamov (umar.adkhamov@3ds.com)
 * @copyright    Dassault Systemes
 */
import { qCustomMatcher } from '../../../e2elib/lib/src/main/qmatchers.const';
import { AppMP, Demo, Scenario } from '../../../libmp/appmp';
import { ListUnitCostColumn } from '../../../libmp/forms/form.unitcost';
import { CostLabel, DataFoodBaseAccountName, DataFoodBaseAccountUoM } from '../../../libmp/data/data.account';
import { startOfPlanningYear } from '../../../libmp/data/data.period';
 
describe('ADSO-10101 - Create unit cost for Fixed cost driver (from list context menu)', () => {
  const appMP = AppMP.getInstance();
  const entity = 'DE Fermenter';
  const account = DataFoodBaseAccountName.GeneralFixedCosts;
  const costDriver = 'Fixed';
  const timeUnit = 'Year';
  const cost = 100.23;
  let eopString: string;
  let sopYear: string;
  const uom = DataFoodBaseAccountUoM.EuroPerMonth;
  const janSOPMinus1 = `1-Jan-${startOfPlanningYear - 1}`;
 
  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}. Get start and end of planning`, async () => {
    // Open Periods view
    await appMP.viewPeriod.switchTo();
    const formPeriod = appMP.viewPeriod.frmPeriod;
    ({ sopYear, eopString } = await formPeriod.getStartAndEndOfPlanning());
  });
 
  it(`Step 1 - Open view ${appMP.viewUnitCost.viewPath}. Verify General Fixed Costs account exists with UoM as ${uom}`, async () => {
    await appMP.viewUnitCost.switchTo();
 
    const accountRow = await appMP.viewUnitCost.frmUnitAccount.listAccount.getRow({ Account: account });
    await appMP.viewUnitCost.frmUnitAccount.listAccount.verifyRowValues(accountRow, { 'Default UoM': uom });
  });
 
  it('Step 2 - Verify navigation panel is show and open Stocking points and units list', async () => {
    // Verify if navigation panel is showed by default
    expect(await appMP.formNavigation.isVisible()).toBe(true, 'Navigation panel should be visible');
    // Open 'StockingPoints and Units' list (ListEntity) in navigation panel by clicking on 'StockingPoints and Units' button (ButtonNavEntity)
    await appMP.formNavigation.btnEntity.click();
    expect(await appMP.formNavigation.listEntity.isVisible()).toBe(true, 'Entitiy list in navigation panel should be visible');
  });
 
  it(`Step 3 - Check ${entity} units checkbox`, async () => {
    // Resize DisplayName column incase DisplayName value will be show as "Denmerk Pl..."
    const entityDisplayNameColumn = await appMP.formNavigation.listEntity.getColumnByValue('DisplayName');
    await entityDisplayNameColumn.resizeColumn(100);
    // Check 2 leaf units DE Fermenter (to get row in hierarchy list can refer to getBookmarkByName function)
    const deFermenterUnitRow = await appMP.formNavigation.listEntity.getEntityRowByName(entity, ['Europe', 'Plants', 'Denmark Plant']);
    expect(deFermenterUnitRow).toBeDefined(`${entity} row should be found`);
    await appMP.formNavigation.listEntity.scrollToRow(deFermenterUnitRow);
    await deFermenterUnitRow.checkboxClick();
    expect(await deFermenterUnitRow.isChecked()).toBe(true, `${entity} row checkbox should be checked`);
  });
 
  it(`Step 4: Verify Exactly 1 cost exists for ${entity} with start = ${janSOPMinus1}`, async () => {
    const unitCostRows = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getAllRows();
    let counter = 0;
    for (const row of unitCostRows) {
      const cellValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow('Unit', row);
      if (cellValue === entity) {
        counter++;
      }
    }
    expect(counter).toBe(1, `There should be exactly 1 cost exists for ${entity}`);
    const unitCostRow = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Unit, value: entity }]);
    const startValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow(ListUnitCostColumn.Start, unitCostRow);
    expect(startValue).toBe(janSOPMinus1, `Cost for unit '${entity}' should have start = ${janSOPMinus1}`);
  });
 
  it('Step 5 - Input data for unit account', async () => {
    // Create new Unit Cost
    const dlgUnitCost = await appMP.viewUnitCost.frmUnitCost.listUnitCost.openEditDialog();
    let btnMessage = '';
 
    // Verify that dlgUnitCost fields have correct values
    expect(await dlgUnitCost.verifyDropDownCount(dlgUnitCost.ddlAccount, 3)).toBe(true, 'There should be exactly 3 items in the Account DropDownList');
    const values = [account, DataFoodBaseAccountName.ChangeoverCost, DataFoodBaseAccountName.ShiftPatternCosts];
    expect(await dlgUnitCost.verifyDropDownContainValues(dlgUnitCost.ddlAccount, values)).toBe(true, `${values.join(', ')} should exist in Account drop down`);
 
    expect(await dlgUnitCost.verifyDropDownCount(dlgUnitCost.ddlCostDriver, 4)).toBe(true, 'There should be exactly 4 items in the Cost Driver DropDownList');
    const driverValues = [costDriver, 'Number of units', 'Changeover', 'Staffing'];
    expect(await dlgUnitCost.verifyDropDownContainValues(dlgUnitCost.ddlCostDriver, driverValues)).toBe(true, `${driverValues.join(', ')} should exist in Cost Driver drop down`);
 
    // Update value in dialog
    await dlgUnitCost.updateUnitCostValue(account, costDriver, entity, new Date(Number(sopYear), 1, 1), timeUnit, 1, cost);
    // Verify that Cost Label displays correct value
    expect(await dlgUnitCost.efCost.getComponentLabel()).toBe(CostLabel.euro(timeUnit), `Cost label should be ${CostLabel.euro(timeUnit)}`);
    // Confirm dialog
    const isUnitCostCreate = await dlgUnitCost.clickOK();
    if (!isUnitCostCreate) {
      btnMessage = await dlgUnitCost.getOKButtonTooltip();
    }
    expect(isUnitCostCreate).toBe(true, `Values for new Unit Cost should be inserted successfully. OK button disabled with tooltip ${btnMessage}`);
 
    // Click Cancel if create is not allowed
    if (!isUnitCostCreate) {
      await dlgUnitCost.clickCancel();
    }
  });
 
  it('Step 6 - Verify the new Unit Cost is created with correct details', async () => {
    // Get the newly created Unit Cost based on start date (1-Feb-SOP Year)
    const unitCostRow = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Start, value: `1-Feb-${sopYear}` }]);
 
    // Verify the values are set correctly
    let cellValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow(ListUnitCostColumn.Account, unitCostRow);
    expect(cellValue).toBe(account, `Account name should be ${account}`);
 
    cellValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow(ListUnitCostColumn.CostDriver, unitCostRow);
    expect(cellValue).toBe(costDriver, `Cost Driver should be ${costDriver}`);
 
    cellValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow(ListUnitCostColumn.Cost, unitCostRow);
    // Round the cost to compare, as the cost in the list is rounded
    const roundedCost = Math.round(cost).toString();
    expect(cellValue).toBe(roundedCost, `Cost should be ${roundedCost}`);
 
    cellValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow(ListUnitCostColumn.UoM, unitCostRow);
    expect(cellValue).toBe(`${DataFoodBaseAccountUoM.EuroPer}${timeUnit}`, `Time unit should be ${DataFoodBaseAccountUoM.EuroPer}${timeUnit}`);
 
    cellValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, unitCostRow);
    expect(cellValue).toBe(eopString, `End should be ${eopString}`);
  });
 
  it('Step 7 - Verify the previous Unit Cost ', async () => {
    // Get the previous Unit Cost based on start date (1-Jan-SOPYear minus 1)
    const unitCostRow = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Start, value: janSOPMinus1 }]);
    // Verify the End is set correctly
    const cellValue = await appMP.viewUnitCost.frmUnitCost.listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, unitCostRow);
    expect(cellValue).toBe(`1-Feb-${sopYear}`, `End should be 1-Feb-${sopYear}`);
  });
 
  it(`Step 8 - Open view ${appMP.viewScenarioAnalysisCost.viewPath} and verify if the values are correct`, async () => {
    // Open ViewScenarioAnalysis
    await appMP.viewScenarioAnalysisCost.switchTo();
 
    // Select another account before choosing General fixed cost, else chart not refreshed to what we need
    await appMP.viewScenarioAnalysisCost.frmCost.drpdAccount.selectItemSOP(DataFoodBaseAccountName.OperatingCost);
    await appMP.viewScenarioAnalysisCost.frmCost.drpdAccount.selectItemSOP(account);
 
    // Get the cost value from the chart for 1-Feb-SOP Year and verify whether it is as expected
    const chartValues = await appMP.viewScenarioAnalysisCost.frmCost.chartCost.getChartDataValue('DashboardChartSeriesSenarioAnalysisCostPerPeriodBaseCost', [account, account, account, account], [`1-Feb-${sopYear}`, `1-Mar-${sopYear}`, `1-Apr-${sopYear}`, `1-Dec-${+sopYear + 1}`]);
    // Calculate monthly cost and limit decimal points to 4
    const expectedCostPerMonth = (cost / 12).toFixed(4);
 
    // Verify that starting from 1-Feb-SOP year the the chart displays the expectedCostPerMonth
    expect(chartValues[0].values[0]).toBe(expectedCostPerMonth, `Value should be ${expectedCostPerMonth} starting from 1-Feb-${sopYear}`);
    expect(chartValues[1].values[0]).toBe(expectedCostPerMonth, `Value should be ${expectedCostPerMonth} starting from 1-Mar-${sopYear}`);
    expect(chartValues[2].values[0]).toBe(expectedCostPerMonth, `Value should be ${expectedCostPerMonth} starting from 1-Apr-${sopYear}`);
    expect(chartValues[3].values[0]).toBe(expectedCostPerMonth, `Value should be ${expectedCostPerMonth} starting from 1-Dec-${+sopYear + 1}`);
  });
});