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
/**
 * @file         ADSO-10102
 * @description  Create unit cost for number of units cost driver from action bar
 * @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 { AppMP, Demo, Scenario } from '../../../libmp/appmp';
import { CostLabel, DataFoodBaseAccountTimeUnit, DataFoodBaseAccountUoM } from '../../../libmp/data/data.account';
import { DialogUnitCost } from '../../../libmp/dialogs/dialog.unitcost';
import { ListUnitCost, ListUnitCostColumn } from '../../../libmp/forms/form.unitcost';
 
describe('ADSO-10102 - Create unit cost for number of units cost driver from action bar', () => {
  const appMP = AppMP.getInstance();
  let listUnitCost: ListUnitCost;
  let dlgUnitCost: DialogUnitCost;
  let btnMessage = '';
  let startOfPlanningDate: Date;
  let newDEFermenterStartDate: Date;
  let newDEFermenterStartString: string;
  let startOfPlanningString: string;
  let endOfPlanningString: string;
  let sopYear: string;
 
  const timeUnit = DataFoodBaseAccountTimeUnit.Month;
 
  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;
    ({ startOfPlanningDate, sopYear, sopString: startOfPlanningString, eopString: endOfPlanningString } = await formPeriod.getStartAndEndOfPlanning());
    newDEFermenterStartDate = new Date(startOfPlanningDate.getFullYear(), 2, 1);
    newDEFermenterStartString = `1-Mar-${sopYear}`;
  });
 
  it(`Setup - Open view ${appMP.viewAccount.viewPath}. Create Number of units account`, async () => {
    // Open account view
    await appMP.viewAccount.switchTo();
    const listAccount = appMP.viewAccount.frmAccount.listAccount;
    await listAccount.createAccount('Cost of sales', 'Number of units', '', '0', 'Number of units', '100', 'Year', '1');
  });
 
  it(`Setup - Open view ${appMP.viewUnitCost.viewPath}. Create new DE Fermenter unit cost for the new account and cost driver with start = start of planning`, async () => {
    // Open unit cost view
    await appMP.viewUnitCost.switchTo();
    listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost;
    // Filter by DE Fermenter
    await appMP.formNavigation.filterByEntity('DE Fermenter', ['Europe', 'Plants', 'Denmark Plant']);
    // Create new DE Fermenter unit cost
    dlgUnitCost = await listUnitCost.openEditDialog();
    await dlgUnitCost.updateUnitCostValue('Number of units', 'Number of units', 'DE Fermenter', startOfPlanningDate);
    const canCreate = await dlgUnitCost.clickOK();
    if (!canCreate) {
      btnMessage = await dlgUnitCost.getOKButtonTooltip();
    }
    expect(canCreate).toBe(true, `Should be able to create unit cost for Number of units. OK button disabled with tooltip ${btnMessage}`);
  });
 
  it('Step 1 - Create unit cost for number of units cost driver from action bar', async () => {
    // Create unit cost
    await listUnitCost.focus();
    await appMP.abpData.btnCreate.click();
    await dlgUnitCost.waitUntilPresent();
    await dlgUnitCost.updateUnitCostValue('Number of units', 'Number of units', 'DE Fermenter', newDEFermenterStartDate, timeUnit, 1, 100.23);
    expect(await dlgUnitCost.efCost.getComponentLabel()).toBe(CostLabel.euro(timeUnit), `Label of cost should be ${CostLabel.euro(timeUnit)}`);
    const canCreate = await dlgUnitCost.clickOK();
    if (!canCreate) {
      btnMessage = await dlgUnitCost.getOKButtonTooltip();
    }
    expect(canCreate).toBe(true, `Should be able to create unit cost for Number of units. OK button disabled with tooltip ${btnMessage}`);
  });
 
  it('Step 2 - Verify unit cost created with correct values', async () => {
    // Verify row created with correct values in dialog
    const previousDEDefermenter = await listUnitCost.getUnitCostRowByValues('DE Fermenter', 'Number of units', 'Number of units', startOfPlanningString);
    const newDEDefermenter = await listUnitCost.getUnitCostRowByValues('DE Fermenter', 'Number of units', 'Number of units', newDEFermenterStartString);
    dlgUnitCost = await listUnitCost.openEditDialog(newDEDefermenter);
    const verifyAfterDialogFeedback = await dlgUnitCost.verifyDialogValue('Number of units', 'Number of units', 'DE Fermenter', newDEFermenterStartDate, timeUnit, 1, 100.23);
    expect(verifyAfterDialogFeedback.length).toBe(0, verifyAfterDialogFeedback.join('. '));
    await dlgUnitCost.clickCancel();
    if (newDEDefermenter !== undefined && previousDEDefermenter !== undefined) {
      // Verify UoM, Start, and End column value of the new row
      expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.UoM, newDEDefermenter)).toBe(DataFoodBaseAccountUoM.EuroPerMonth, `UoM should be ${DataFoodBaseAccountUoM.EuroPerMonth}`);
      expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Start, newDEDefermenter)).toBe(newDEFermenterStartString, `Start should be ${newDEFermenterStartString}`);
      expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, newDEDefermenter)).toBe(endOfPlanningString, `End should be ${endOfPlanningString}`);
      // Verify Start and End column value of the previous unit cost
      expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Start, previousDEDefermenter)).toBe(startOfPlanningString, `Start should be ${startOfPlanningString}`);
      expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, previousDEDefermenter)).toBe(newDEFermenterStartString, `End should be ${newDEFermenterStartString}`);
    } else {
      expect(newDEDefermenter).toBeDefined('New DE Fermenter should be created');
    }
  });
 
  it(`Step 3 - Open view ${appMP.viewScenarioAnalysisCost.viewPath}. Verify cost in scenario analysis chart`, async () => {
    // Switch to scenario analysis account view
    await appMP.viewScenarioAnalysisCost.switchTo();
    await appMP.viewScenarioAnalysisCost.frmCost.drpdAccount.selectItem('Number of units');
    const chartValues = await appMP.viewScenarioAnalysisCost.frmCost.chartCost.getChartDataValue('DashboardChartSeriesSenarioAnalysisCostPerPeriodBaseCost', ['Number of units'], [newDEFermenterStartString]);
    expect(chartValues[0].values[0]).toBe('100.23', `Value should be 100.23 starting from ${newDEFermenterStartString}`);
  });
});