haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
/**
 * @file         ADSO-10114
 * @description  Edit unit cost - multiple costs selection of same cost driver (only update Time unit & length of time)
 * @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 { DataFoodBaseEntityName } from '../../../libmp/data/data.navigation';
import { DataFoodBaseAccountName } from '../../../libmp/data/data.account';
import { DialogUnitCost } from '../../../libmp/dialogs/dialog.unitcost';
import { ListUnitCostColumn, ListUnitCost } from '../../../libmp/forms/form.unitcost';
import { startOfPlanningYear } from '../../../libmp/data/data.period';
 
describe('ADSO-10114 -  Edit unit cost - multiple costs selection of same cost driver', () => {
  const appMP = AppMP.getInstance();
  const unit = DataFoodBaseEntityName.DEFermenter;
  const account = DataFoodBaseAccountName.GeneralFixedCosts;
  let costDriver: string;
  let startDate: Date; // Existing unit's cost
  let cost: string; // Existing unit's cost
  const janSOPMinus1 = `1-Jan-${startOfPlanningYear - 1}`;
  const janSOP = `1-Jan-${startOfPlanningYear}`;
  const newStartDate = new Date(janSOP);
  const newCost = 100;
  const newTimeUnit = 'Quarter';
  const newLengthTime = 2;
  let listUnitCost: ListUnitCost;
  let dlgUnitCost: DialogUnitCost;
 
  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.viewUnitCost.viewPath}. Verify ${unit} exist`, async () => {
    // Open unit cost view
    await appMP.viewUnitCost.switchTo();
    listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost;
    // Filter by DE Fermenter
    await appMP.formNavigation.filterByEntity(unit, [DataFoodBaseEntityName.Europe, DataFoodBaseEntityName.Plants, DataFoodBaseEntityName.DenmarkPlant]);
    // Verify 1 DE Fermenter Unit Cost exist in the list
    await listUnitCost.waitForScreenUpdate();
    expect(await listUnitCost.getRowCount()).toBe(1, `Exactly one ${unit} Unit Cost should exist in the list`);
  });
 
  it(`Step 1 - Create second ${unit} Unit Cost by copying the existing`, async () => {
    // Get the Unit Cost list
    listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost;
 
    // Get the Unit Cost row based on Unit and Account name
    const unitCostRow = await listUnitCost.getRowByIndex(0);
 
    // Open UnitCost dialog for copying
    await listUnitCost.openEditDialog(unitCostRow, true);
    dlgUnitCost = listUnitCost.dlgUnitCost;
    await dlgUnitCost.waitUntilPresent();
    // Store current values for Cost Driver, Start Date and Cost to verify that they will remain unchanged after batch edit below
    ({ costDriver, startDate, cost } = await dlgUnitCost.getDialogValues());
 
    await dlgUnitCost.updateUnitCostValue(undefined, undefined, undefined, newStartDate, undefined, undefined, newCost);
    await dlgUnitCost.clickOK();
  });
 
  it('Step 2 - Open Batch Edit dialog and verify the fields are disabled and batch edit checkboxes are present', async () => {
    await listUnitCost.selectListRowsByIndex([0], true);
    await listUnitCost.openEditDialog((await listUnitCost.getInboundSelectedRows())[0], false);
    const verifyDialogFields = await dlgUnitCost.verifyBatchEditFieldAccess();
    expect(verifyDialogFields.length).toBe(0, `${verifyDialogFields.join('\n')}`);
  });
 
  it('Step 3 - Batch edit Unit Costs', async () => {
    // Click checkbox to enable Time Unit field and verify it is enabled
    await dlgUnitCost.cbBatchEditTimeUnit.click();
    expect(await dlgUnitCost.ddlTimeUnit.isDisabled()).toBe(false, '"Time Unit" field should be enabled after its checkbox is checked');
    // Click checkbox to enable Length of Time field and verify it is enabled
    await dlgUnitCost.cbBatchEditLengthOfTime.click();
    expect(await dlgUnitCost.ddlTimeUnit.isDisabled()).toBe(false, '"Length of Time" field should be enabled after its checkbox is checked');
    // Update the values
    await dlgUnitCost.updateUnitCostValue(undefined, undefined, undefined, undefined, newTimeUnit, newLengthTime);
    await dlgUnitCost.clickOK();
  });
 
  it('Step 4 - Verify that "Time Unit" and "Length of Time" values are updated and other values remain the same', async () => {
    // get previous and new Unit Cost based on start date
    const previousUnit = await listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Start, value: janSOPMinus1 }]);
    const newUnit = await listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Start, value: janSOP }]);
 
    // Verify values of the previous Unit Cost
    await previousUnit.leftClick();
    await listUnitCost.openEditDialog(previousUnit);
    await dlgUnitCost.waitUntilPresent();
    let verifyDialogValuesFeedback = await dlgUnitCost.verifyDialogValue(account, costDriver, unit, startDate, newTimeUnit, newLengthTime, Number(cost));
    expect(verifyDialogValuesFeedback.length).toBe(0, verifyDialogValuesFeedback.join('. '));
    await dlgUnitCost.clickCancel();
 
    // Verify values of the new Unit Cost
    await listUnitCost.openEditDialog(newUnit);
    await dlgUnitCost.waitUntilPresent();
    verifyDialogValuesFeedback = await dlgUnitCost.verifyDialogValue(account, costDriver, unit, newStartDate, newTimeUnit, newLengthTime, newCost);
    expect(verifyDialogValuesFeedback.length).toBe(0, verifyDialogValuesFeedback.join('. '));
    await dlgUnitCost.clickCancel();
  });
});