yanweiyuan3
2023-10-10 d901b1ab0ee0b690f5ac211b9cdb1db3a58bca86
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
/**
 * @file         ADSO-10170
 * @description  Copy operation cost via action bar (single cost selection Operating cost)
 * @testcategory Web - Financials - Operations
 * @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 { DataOperationAccount, DataOperationCostCost, DataOperationCostCostDriver, DataOperationCostUoM } from '../../../libmp/data/data.operationcost';
import { startOfPlanningYear } from '../../../libmp/data/data.period';
import { ListColumnOperationCost } from '../../../libmp/forms/form.operationcost';
 
describe('ADSO-10170 - Copy operation cost via action bar (single cost selection Operating cost)', () => {
  const appMP = AppMP.getInstance();
  const listOperationCost = appMP.viewOperationCost.frmOperationCost.listOperationCost;
  const dlgOperationCost = listOperationCost.dlgOperationCost;
  let eopString: string;
  let sopYear: string;
  const unit = DataFoodBaseEntityName.DEFermenter;
  const unitParents = DataFoodBaseEntity.deUnitsParents;
  const firstCostStartString = `1-Jan-${startOfPlanningYear - 1}`;
  let newCostStartString = '1-Feb-'; // Year to be assigned after getting sopYear
  const account = DataOperationAccount.OperatingCostAccountName;
  const costDriver = DataOperationCostCostDriver.Volume;
  let operation: string;
  const cost = DataOperationCostCost.Cost700;
  const uom = DataOperationCostUoM.EuroPerMT;
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    // Reset views and navigation
    await appMP.formNavigation.reset();
    await appMP.viewOperationCost.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;
    ({ eopString, sopYear } = await formPeriod.getStartAndEndOfPlanning());
    newCostStartString = newCostStartString + sopYear;
  });
 
  it(`Setup - Open view ${appMP.viewOperationCost.viewPath}. Verify operating cost exists for ${unit} for ${firstCostStartString} and Cost = ${cost}`, async () => {
    // Open operation cost view
    await appMP.viewOperationCost.switchTo();
    // Toggle ON Filter by Accounts
    const cbFilterByAcc = appMP.viewOperationCost.frmOperationCost.cbFilterByAccounts;
    await appMP.viewOperationCost.frmOperationCost.toggleFilterByAccount(true);
    expect(await cbFilterByAcc.isChecked()).toBe(true, 'Filter by Accounts should be toggled to ON');
    // Click on operation account
    const accRow = await appMP.viewOperationCost.frmOperationsAccount.listOperationAccount.getOperationAccountByName(account);
    await accRow.leftClick();
    // Filter by unit
    await appMP.formNavigation.filterByEntity(unit, unitParents);
    // Verify 1 operation cost exist in the list
    await listOperationCost.waitForScreenUpdate();
    expect(await listOperationCost.getRowCount()).toBe(1, `There should be exactly one operating cost exists for ${unit}`);
    // Verify account, start, and cost of the operation cost
    const operationCost = await listOperationCost.getRowByIndex(0);
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.Account, operationCost)).toBe(account, `Account of the ${unit} operation cost should be ${account}`);
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.Start, operationCost)).toBe(firstCostStartString, `Start of the ${unit} operation cost should be ${firstCostStartString}`);
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.Cost, operationCost)).toBe(cost.toString(), `Cost of the ${unit} operation cost should be ${cost}`);
  });
 
  it('Step 1 - Open copy single operation cost dialog via action bar, verify the default value in dialog and OK button disabled with precondition', async () => {
    // Open copy dialog
    const operationCostRow = await listOperationCost.getRowByIndex(0);
    operation = await listOperationCost.getCellValueFromRow(ListColumnOperationCost.Operation, operationCostRow);
    await operationCostRow.leftClick();
    await appMP.abpData.btnCopy.click();
    await dlgOperationCost.waitUntilPresent();
    // Verify field value in dialog
    const verifyBeforeDialogFeedbacks: string[] = await dlgOperationCost.verifyDialogValue(account, costDriver, operation, new Date(firstCostStartString), cost);
    expect(verifyBeforeDialogFeedbacks.length).toBe(0, `${verifyBeforeDialogFeedbacks.join(', \n')}`);
    // Verify OK button is disabled with precondition
    expect(await dlgOperationCost.clickOK()).toBe(false, 'OK button should be disabled');
    expect(await dlgOperationCost.getDialogFeedback()).toBe('Identical cost definition exists. Operation cost must be unique by Account, Cost driver and Start date.', 'Feedback text should match');
  });
 
  it('Step 2 - Update start date and verify operation cost created successfully', async () => {
    // Update start value
    await dlgOperationCost.dtsStart.setDate(new Date(newCostStartString));
    expect(await dlgOperationCost.clickOK()).toBe(true, 'OK button should be enabled');
    // Verify row created with correct values in dialog
    const previousOperationCostRow = await listOperationCost.getRowByCellValue(ListColumnOperationCost.Start, firstCostStartString);
    const newOperationCost = await listOperationCost.getRowByCellValue(ListColumnOperationCost.Start, newCostStartString);
    await listOperationCost.openCreateEditUnitCostDialog(newOperationCost);
    const verifyFeedbacks = await dlgOperationCost.verifyDialogValue(account, costDriver, operation, new Date(newCostStartString), cost);
    expect(verifyFeedbacks.length).toBe(0, `${verifyFeedbacks.join(', \n')}`);
    await dlgOperationCost.clickCancel();
    // Verify UoM, Start, and End column value of the new row
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.UoM, newOperationCost)).toBe(uom, `UoM should be ${uom}`);
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.Start, newOperationCost)).toBe(newCostStartString, `Start should be ${newCostStartString}`);
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.End, newOperationCost)).toBe(eopString, `End should be ${eopString}`);
    // Verify Start and End column value of the previous operation cost
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.Start, previousOperationCostRow)).toBe(firstCostStartString, `Start should be ${firstCostStartString}`);
    expect(await listOperationCost.getCellValueFromRow(ListColumnOperationCost.End, previousOperationCostRow)).toBe(newCostStartString, `End should be ${newCostStartString}`);
  });
});