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
/**
 * @file        ADSO-10113
 * @description Batch edit cost of unit cost
 * @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 { DataFoodBaseEntity, DataFoodBaseEntityName } from '../../../libmp/data/data.navigation';
import { startOfPlanningYear } from '../../../libmp/data/data.period';
import { DataFoodBaseUnitCost } from '../../../libmp/data/data.unitcost';
import { ListUnitCostColumn } from '../../../libmp/forms/form.unitcost';
 
describe('ADSO-10113 - Batch edit cost of unit cost', () => {
  const appMP = AppMP.getInstance();
  let listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost;
  let dlgUnitCost = listUnitCost.dlgUnitCost;
  const account = DataFoodBaseUnitCost.Account;
  const costDriver = DataFoodBaseUnitCost.CostDriver;
  const unit = DataFoodBaseEntityName.DEFermenter;
  const uom = DataFoodBaseUnitCost.UoM;
  const firstUnitCostStart = `1-Jan-${startOfPlanningYear - 1}`;
  const secondUnitCostStart = `1-Jan-${startOfPlanningYear}`;
  let secondUnitCostEnd = '';
  const editedCost = DataFoodBaseUnitCost.EditCost;
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    // Clear demo data
    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.viewUnitCost.viewPath}. Verify 1 ${unit} exist with ${firstUnitCostStart} as start date`, async () => {
    // Open unit cost view
    await appMP.viewUnitCost.switchTo();
    listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost;
    // Filter by DE Fermenter
    await appMP.formNavigation.filterByEntity(unit, DataFoodBaseEntity.deUnitsParents);
    // 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`);
    const unitCostRow = await listUnitCost.getRowByIndex(0);
    const unitCostStart = await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Start, unitCostRow);
    expect(unitCostStart).toBe(firstUnitCostStart, `Start of the ${unit} unit cost should be ${firstUnitCostStart}`);
  });
 
  it(`Setup - Create a new ${unit} unit cost with different cost and start value`, async () => {
    // Create new DE Fermenter unit cost
    dlgUnitCost = await listUnitCost.openEditDialog();
    await dlgUnitCost.updateUnitCostValue(account, costDriver, unit, new Date(secondUnitCostStart));
    let btnDisabledTooltip = '';
    const canClickOk = await dlgUnitCost.clickOK(1000);
    if (!canClickOk) {
      btnDisabledTooltip = await dlgUnitCost.getOKButtonTooltip();
    }
    expect(canClickOk).toBe(true, `OK button should be clickable. Ok button disabled with tooltip: ${btnDisabledTooltip}`);
    const unitCostRow = await listUnitCost.getUnitCostRowByValues(unit, account, costDriver, secondUnitCostStart);
    expect(unitCostRow).toBeDefined(`New created ${unit} Unit Cost row with start date ${secondUnitCostStart} should be found`);
    if (unitCostRow !== undefined) {
      secondUnitCostEnd = await listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, unitCostRow);
    }
  });
 
  it('Step 1 - Open batch edit unit cost dialog and verify the fields', async () => {
    // Open batch edit dialog
    const rows = await listUnitCost.getAllRows();
    dlgUnitCost = await listUnitCost.openEditDialog(rows);
    // Verify all field disabled
    expect(await dlgUnitCost.ddlAccount.isDisabled()).toBe(true, 'Account drop down list should be disabled');
    expect(await dlgUnitCost.ddlCostDriver.isDisabled()).toBe(true, 'Cost driver drop down list should be disabled');
    expect(await dlgUnitCost.ddlUnit.isDisabled()).toBe(true, 'Unit drop down list should be disabled');
    expect(await dlgUnitCost.dtsStart.isDisabled()).toBe(true, 'Start date time selector should be disabled');
    expect(await dlgUnitCost.ddlTimeUnit.isDisabled()).toBe(true, 'Time unit drop down list should be disabled');
    expect(await dlgUnitCost.efLengthOfTime.isDisabled()).toBe(true, 'Length of time field should be disabled');
    expect(await dlgUnitCost.efCost.isDisabled()).toBe(true, 'Cost field should be disabled');
    // Verify checkbox to enable edit time unit, length of time, and cost are exist and unchecked
    expect(await dlgUnitCost.cbBatchEditTimeUnit.isVisible()).toBe(true, 'Time unit checkbox should be visible in the dialog');
    expect(await dlgUnitCost.cbBatchEditTimeUnit.isChecked()).toBe(false, 'Time unit checkbox should be unchecked by default');
    expect(await dlgUnitCost.cbBatchEditLengthOfTime.isVisible()).toBe(true, 'Length of time checkbox should be visible in the dialog');
    expect(await dlgUnitCost.cbBatchEditLengthOfTime.isChecked()).toBe(false, 'Length of time checkbox should be unchecked by default');
    expect(await dlgUnitCost.cbBatchEditCost.isVisible()).toBe(true, 'Cost checkbox should be visible in the dialog');
    expect(await dlgUnitCost.cbBatchEditCost.isChecked()).toBe(false, 'Cost checkbox should be unchecked by default');
  });
 
  it('Step 2 - Batch edit cost value and verify the changes', async () => {
    // Enable and edit cost
    await dlgUnitCost.toggleBatchEditCostCheckbox(true);
    expect(await dlgUnitCost.cbBatchEditCost.isChecked()).toBe(true, 'Cost field should be checked');
    expect(await dlgUnitCost.efCost.isDisabled()).toBe(false, 'Cost field should be enabled after checkbox is checked');
    await dlgUnitCost.efCost.sendInput(editedCost);
    let btnDisabledTooltip = '';
    const canClickOk = await dlgUnitCost.clickOK(1000);
    if (!canClickOk) {
      btnDisabledTooltip = await dlgUnitCost.getOKButtonTooltip();
    }
    expect(canClickOk).toBe(true, `OK button should be clickable. Ok button disabled with tooltip: ${btnDisabledTooltip}`);
  });
 
  it('Step 3 - Verify cost updated for both unit cost, while all other values remain unchanged', async () => {
    // Verify cost updated for both unit cost in list
    const firstUnitCost = await listUnitCost.getRowByIndex(0);
    const secondUnitCost = await listUnitCost.getRowByIndex(1);
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Cost, firstUnitCost)).toBe(editedCost, 'Cost of first unit cost should be updated to 999');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Cost, secondUnitCost)).toBe(editedCost, 'Cost of second unit cost should be updated to 999');
 
    // Verify other values remain unchanged for first unit cost
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Unit, firstUnitCost)).toBe(unit, 'Unit of first unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Account, firstUnitCost)).toBe(account, 'Account of first unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.CostDriver, firstUnitCost)).toBe(costDriver, 'Cost driver of first unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.UoM, firstUnitCost)).toBe(uom, 'UoM of first unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Start, firstUnitCost)).toBe(firstUnitCostStart, 'Start of first unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, firstUnitCost)).toBe(secondUnitCostStart, 'End of first unit cost should remain unchanged');
    // Verify other values remain unchanged for second unit cost
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Unit, secondUnitCost)).toBe(unit, 'Unit of second unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Account, secondUnitCost)).toBe(account, 'Account of second unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.CostDriver, secondUnitCost)).toBe(costDriver, 'Cost driver of second unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.UoM, secondUnitCost)).toBe(uom, 'UoM of second unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.Start, secondUnitCost)).toBe(secondUnitCostStart, 'Start of second unit cost should remain unchanged');
    expect(await listUnitCost.getCellValueFromRow(ListUnitCostColumn.End, secondUnitCost)).toBe(secondUnitCostEnd, 'End of second unit cost should remain unchanged');
  });
});