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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
 * @file        ADSO-10177
 * @description Create one Stocking cost from context menu (list/action bar)
 * @author      Mehrab Kamrani (mehrab.hassan@3ds.com)
 * @copyright   Dassault Systèmes
 */
import { qCustomMatcher } from '../../../e2elib/lib/src/main/qmatchers.const';
import { AppMP, Demo, Scenario } from '../../../libmp/appmp';
import { DialogStockingCost } from '../../../libmp/dialogs/dialog.stockingcost';
import { ListStockingCostColumn } from '../../../libmp/forms/form.stockingcost';
import { CostLabel, DataFoodBaseAccountCost, DataFoodBaseAccountCostDriver, DataFoodBaseAccountName, DataFoodBaseAccountTimeUnit, DataFoodBaseAccountUoM } from '../../../libmp/data/data.account';
import { DataFoodBaseEntityName } from '../../../libmp/data/data.navigation';
import { DataFoodBaseStockingCostStartDate } from '../../../libmp/data/data.stockingcost';
import { ActionTriggerType } from '../../../libappbase/utils';
import { startOfPlanningYear } from '../../../libmp/data/data.period';
 
describe('ADSO-10177 - Create one Stocking cost from context menu (list and action bar)', () => {
  const appMP = AppMP.getInstance();
  const viewStockingCost = appMP.viewStockingCost;
  const listStockingCost = viewStockingCost.frmStockingCost.lstStockingCost;
  const formNavigation = appMP.formNavigation;
  const listEntity = formNavigation.listEntity;
 
  // Variables used in multiple "it"
  const entity = DataFoodBaseEntityName.Europe;
  const stockingPoint = DataFoodBaseEntityName.DCAustria;
  const accountName = DataFoodBaseAccountName.GeneralFixedCosts;
  const accountParentName = DataFoodBaseAccountName.CostOfSales;
  const costDriver = DataFoodBaseAccountCostDriver.Fixed;
  const timeUnit = DataFoodBaseAccountTimeUnit.Month;
  const uom = DataFoodBaseAccountUoM.EuroPerMonth;
  const cost = DataFoodBaseAccountCost._122_22.toString();
  const newCost = DataFoodBaseAccountCost._15000;
  const newCostInString = newCost.toString();
  const newCostInStringWComma = newCost.toLocaleString();
  const deSPArray: string[] = [DataFoodBaseEntityName.DEWarehouse, DataFoodBaseEntityName.DEWarehousePackagingMaterial, DataFoodBaseEntityName.DEWarehouseRawMaterial];
  const date1JanSOPYearMinus1 = `1-Jan-${startOfPlanningYear - 1}`;
  const date1Feb = DataFoodBaseStockingCostStartDate._1FebWithoutYear;
  const date1Mar = DataFoodBaseStockingCostStartDate._1MarWithoutYear;
  const dateLastMonthOfPlanning = `1-Dec-${startOfPlanningYear}`;
  const expectedDropdownCount = 17;
  const chartLegendGroup = 'DashboardChartSeriesSenarioAnalysisCostPerPeriodBaseCost';
 
  let sopString: string;
  let eopString: string;
  let sopYear: string;
  let dlgStockingCost: DialogStockingCost;
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    // Reset
    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.viewPeriod.viewPath}, get start and end of planning.`, async () => {
    // Open Periods view
    await appMP.viewPeriod.switchTo();
    ({ sopYear, eopString, sopString } = await appMP.viewPeriod.frmPeriod.getStartAndEndOfPlanning());
  });
 
  it(`Setup - Open view ${appMP.viewAccount.viewPath}, select account "${accountName}" (child of "${accountParentName}"), change the Cost to ${cost}.`, async () => {
    await appMP.viewAccount.switchTo();
    // Edit General fixed costs to have 122.22 for its cost
    const generalFixedCostRow = await appMP.viewAccount.frmAccount.listAccount.getRow({ Name: accountName }, [{ Name: accountParentName }]);
    const dlgAccount = await appMP.viewAccount.frmAccount.listAccount.openAcountDialogViaEditContextMenu(generalFixedCostRow);
    await dlgAccount.createEditAccount(undefined, undefined, cost, timeUnit);
  });
 
  it(`Step 1 - Open view ${viewStockingCost.viewPath}.`, async () => {
    await viewStockingCost.switchTo();
  });
 
  it(`Step 2 - In left navigation panel, click Stocking points and units button to show the list. Select unit ${entity}.`, async () => {
    await formNavigation.toggleEntityList();
    const row = await listEntity.toggleEntityRowCheckbox(true, entity);
    const isChecked = await row.isChecked();
    expect(isChecked).toBe(true, `Unit '${entity}' should be checked.`);
  });
 
  it('Step 3 - In Stocking Costs list, right click Create.', async () => {
    // Create new Stocking Cost
    dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu);
    expect(dlgStockingCost).toBeDefined('Stocking Cost Dialog should be visible.');
  });
 
  it('Step 4 - In Stocking Costs dialog, Verify default value', async () => {
    // Verify that Stocking Costs dialog fields have correct default values
    expect(await dlgStockingCost.ddlAccount.getSelectedString()).toBe(accountName, `Default Account should be: ${accountName}`);
    expect(await dlgStockingCost.ddlCostDriver.getSelectedString()).toBe(costDriver, `Default Cost Driver should be: ${costDriver}`);
    expect(await dlgStockingCost.getStartDate()).toBe(sopString, `Default Start should be: ${sopString}`);
    expect(await dlgStockingCost.ddslTimeUnit.getSelectedString()).toBe(timeUnit, `Default Time Unit should be: ${timeUnit}`);
    expect(await dlgStockingCost.efCost.getText()).toBe(cost, `Default Cost should be: ${cost}`);
    // Cost label UoM in dialog should match with UoM of selected SP
    const selectedSP = await dlgStockingCost.ddlStockingPoint.getSelectedString();
    const costLabel = deSPArray.includes(selectedSP) ? CostLabel.dollar(timeUnit) : CostLabel.euro(timeUnit);
    expect(await dlgStockingCost.efCost.getComponentLabel()).toBe(costLabel, `Cost label should be: ${costLabel}`);
  });
 
  it(`Step 5 - In the dialog, Verify that stocking point dropdown list has ${expectedDropdownCount} SPs beneath ${entity}`, async () => {
    // Verify that stocking point dropdown list has 17 SPs beneath Europe
    const isDropDownCountCorrect = await dlgStockingCost.verifyDropDownCount(dlgStockingCost.ddlStockingPoint, expectedDropdownCount);
    expect(isDropDownCountCorrect).toBe(true, `There should be exactly ${expectedDropdownCount} items in the Stocking Point DropDown List`);
  });
 
  it('Step 6 - In the dialog, modify value of Cost and Stocking Point then Click OK', async () => {
    // modify value of Cost and Stocking Point then Click OK
    await dlgStockingCost.updateDialog(undefined, undefined, stockingPoint, undefined, newCost);
    await dlgStockingCost.clickOK();
  });
 
  it(`Step 7 - Verify row created with values from step 4 & 6. Additionally verify: UoM = ${uom}, Start = 1-Jan (SOP year) and End = End of planning horizon`, async () => {
    // Verify that new stocking is created with correct value
    const isNewStockingCostExisted = await listStockingCost.isStockingCostExisted(stockingPoint, accountName, costDriver, newCostInStringWComma, uom, sopString, eopString);
    expect(isNewStockingCostExisted).toBe(true, 'New Stocking Cost should have correct value.');
  });
 
  it(`Step 8 - Verify previous cost for ${stockingPoint} as following: Start = ${date1JanSOPYearMinus1} and End = 1-Jan (SOP year)`, async () => {
    // Get the previous Unit Cost based on start date (1-Jan-SOPYear minus 1)
    const dcAustriaStockingCostRow = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint },
      { columnID: ListStockingCostColumn.Start, value: date1JanSOPYearMinus1 },
    ]);
    // Verify the End is set correctly
    const dcAustriaEnd = await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, dcAustriaStockingCostRow);
    expect(dcAustriaEnd).toBe(sopString, `End should be ${sopString}`);
  });
 
  it(`Step 9 - Open view ${appMP.viewScenarioAnalysisCost.viewPath} and verify correct value for cost starting from 1-Jan-SOP year`, 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(accountName);
 
    // Uncheck Europe and check DC- Austria in the navigation panel
    await listEntity.toggleEntityRowCheckbox(false, entity);
    const entityRowDCAustria = await listEntity.toggleEntityRowCheckbox(true, stockingPoint, [entity]);
    expect(await entityRowDCAustria.isChecked()).toBe(true, `${stockingPoint} row checkbox should be checked`);
 
    // Get the cost value from the chart for 1-Jan-SOP Year and verify whether it is as expected
    await appMP.viewScenarioAnalysisCost.frmCost.chartCost.waitForStable();
    const chartValues = await appMP.viewScenarioAnalysisCost.frmCost.chartCost.getChartDataValue(chartLegendGroup, [accountName], [sopString, `${date1Feb}${sopYear}`, `${date1Mar}${sopYear}`, dateLastMonthOfPlanning]);
    expect(chartValues[0].values[0]).toBe(newCostInString, `Cost should be ${newCostInString} starting for ${sopString}`);
    expect(chartValues[0].values[1]).toBe(newCostInString, `Cost should be ${newCostInString} starting for ${date1Feb}${sopYear}`);
    expect(chartValues[0].values[2]).toBe(newCostInString, `Cost should be ${newCostInString} starting for ${date1Mar}${sopYear}`);
    expect(chartValues[0].values[3]).toBe(newCostInString, `Cost should be ${newCostInString} starting for last month of Planning (${dateLastMonthOfPlanning})`);
  });
 
  it(`Step 10 - Open view ${viewStockingCost.viewPath}. Delete the newly created stocking cost`, async () => {
    // Uncheck DC - Austria and check Europe in the navigation panel
    await formNavigation.resetNaviToRoot();
    const entityRowEurope = await listEntity.toggleEntityRowCheckbox(true, entity);
    expect(await entityRowEurope.isChecked()).toBe(true, `${entity} row checkbox should be checked`);
    // Delete the newly created stocking cost
    await viewStockingCost.switchTo();
    const newStockingCostRow = await listStockingCost.getStockingCost(stockingPoint, newCostInStringWComma);
    await listStockingCost.deleteStockingCost(newStockingCostRow);
    // Verify that new stocking is deleted
    const isNewStockingCostExisted = await listStockingCost.isStockingCostExisted(stockingPoint, accountName, costDriver, newCostInStringWComma, uom, sopString, eopString);
    expect(isNewStockingCostExisted).toBe(false, 'New Stocking Cost should be deleted from Stocking Cost list');
  });
 
  it('Step 11 - Repeat step 3-9 by clicking Create button from the action bar', async () => {
    // Step 3 - Create stocking cost using Create button from the action bar
    dlgStockingCost = await listStockingCost.openStockingCostDialogViaAbp();
 
    // Step 4 - Verify that Stocking Costs dialog fields have correct default values
    expect(await dlgStockingCost.ddlAccount.getSelectedString()).toBe(accountName, `Default Account should be: ${accountName}`);
    expect(await dlgStockingCost.ddlCostDriver.getSelectedString()).toBe(costDriver, `Default Cost Driver should be: ${costDriver}`);
    expect(await dlgStockingCost.getStartDate()).toBe(sopString, `Default Start should be: ${sopString}`);
    expect(await dlgStockingCost.ddslTimeUnit.getSelectedString()).toBe(timeUnit, `Default Time Unit should be: ${timeUnit}`);
    expect(await dlgStockingCost.efCost.getText()).toBe(cost, `Default Cost should be: ${cost}`);
    // Cost label UoM in dialog should match with UoM of selected SP
    const selectedSP = await dlgStockingCost.ddlStockingPoint.getSelectedString();
    const costLabel = deSPArray.includes(selectedSP) ? CostLabel.dollar(timeUnit) : CostLabel.euro(timeUnit);
    expect(await dlgStockingCost.efCost.getComponentLabel()).toBe(costLabel, `Cost label should be: ${costLabel}`);
 
    // Step 5 - Verify that stocking point dropdown list has 17 SPs beneath Europe
    const isDropDownCountCorrect = await dlgStockingCost.verifyDropDownCount(dlgStockingCost.ddlStockingPoint, expectedDropdownCount);
    expect(isDropDownCountCorrect).toBe(true, `There should be exactly ${expectedDropdownCount} items in the Stocking Point DropDown List`);
 
    // Step 6 - modify value of Cost and Stocking Point then Click OK
    await dlgStockingCost.updateDialog(undefined, undefined, stockingPoint, undefined, newCost);
    await dlgStockingCost.clickOK();
 
    // Step 7 -  Verify that new stocking is created with correct value
    const isNewStockingCostExisted = await listStockingCost.isStockingCostExisted(stockingPoint, accountName, costDriver, newCostInStringWComma, uom, sopString, eopString);
    expect(isNewStockingCostExisted).toBe(true, 'New Stocking Cost should have correct value.');
 
    // Step 8 - Get the previous Unit Cost based on start date (1-Jan-SOPYear minus 1)
    const dcAustriaStockingCostRow = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint },
      { columnID: ListStockingCostColumn.Start, value: date1JanSOPYearMinus1 },
    ]);
    // Verify the End is set correctly
    const dcAustriaEnd = await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, dcAustriaStockingCostRow);
    expect(dcAustriaEnd).toBe(sopString, `End should be ${sopString}`);
 
    // Step 9 - Open ViewScenarioAnalysis
    await appMP.viewScenarioAnalysisCost.switchTo();
    await appMP.viewScenarioAnalysisCost.frmCost.drpdAccount.selectItemSOP(accountName);
    // Uncheck Europe and check DC- Austria in the navigation panel
    await listEntity.toggleEntityRowCheckbox(false, entity);
    const entityRowDCAustria = await listEntity.toggleEntityRowCheckbox(true, stockingPoint, [entity]);
    expect(await entityRowDCAustria.isChecked()).toBe(true, `${stockingPoint} row checkbox should be checked`);
    // Get the cost value from the chart for 1-Jan-SOP Year and verify whether it is as expected
    await appMP.viewScenarioAnalysisCost.frmCost.chartCost.waitForStable();
    const chartValues = await appMP.viewScenarioAnalysisCost.frmCost.chartCost.getChartDataValue(chartLegendGroup, [accountName, accountName, accountName, accountName], [sopString, `${date1Feb}${sopYear}`, `${date1Mar}${sopYear}`, dateLastMonthOfPlanning]);
    expect(chartValues[0].values[0]).toBe(newCostInString, `Cost should be ${newCostInString} starting for ${sopString}`);
    expect(chartValues[0].values[1]).toBe(newCostInString, `Cost should be ${newCostInString} starting for ${date1Feb}${sopYear}`);
    expect(chartValues[0].values[2]).toBe(newCostInString, `Cost should be ${newCostInString} starting for ${date1Mar}${sopYear}`);
    expect(chartValues[0].values[3]).toBe(newCostInString, `Cost should be ${newCostInString} starting for last month of Planning (${dateLastMonthOfPlanning})`);
  });
});