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
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
/**
 * @file        ADSO-10189
 * @description Copy stocking cost via action bar or context menu - single cost selection
 * @testcategory Web - Financials - Stocking points
 * @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 { DataFoodBaseStockingCostStartDate } from '../../../libmp/data/data.stockingcost';
import { DataFoodBaseAccountCost, DataFoodBaseAccountCostDriver, DataFoodBaseAccountLengthOfTime, DataFoodBaseAccountName, DataFoodBaseAccountTimeUnit, DataFoodBaseAccountUoM } from '../../../libmp/data/data.account';
import { ListStockingCostColumn } from '../../../libmp/forms/form.stockingcost';
import { ActionTriggerType } from '../../../libappbase/utils';
import { startOfPlanningYear } from '../../../libmp/data/data.period';
 
describe('ADSO-10189 - Copy single stocking cost via action bar or context menu', () => {
  const appMP = AppMP.getInstance();
  const listStockingCost = appMP.viewStockingCost.frmStockingCost.lstStockingCost;
  let sopYear: string;
  let eopString: string;
  const stockingPointAustria = DataFoodBaseEntityName.DCAustria;
  const stockingPointMorocco = DataFoodBaseEntityName.DCMorocco;
  const account = DataFoodBaseAccountName.GeneralFixedCosts;
  const costDriver = DataFoodBaseAccountCostDriver.Fixed;
  const uom = DataFoodBaseAccountUoM.EuroPerMonth;
  const timeUnit = DataFoodBaseAccountTimeUnit.Month;
  const cost = DataFoodBaseAccountCost._1000;
  const lengthOfTime = DataFoodBaseAccountLengthOfTime._1;
  const oriStart = `1-Jan-${startOfPlanningYear - 1}`;
  const oriDateWithoutYear = DataFoodBaseStockingCostStartDate._1FebWithoutYear;
 
  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;
    ({ sopYear, eopString } = await formPeriod.getStartAndEndOfPlanning());
  });
 
  it(`Step 1 - Open view ${appMP.viewStockingCost.viewPath}`, async () => {
    await appMP.viewStockingCost.switchTo();
  });
 
  it(`Step 2 - Copy "${stockingPointAustria}" via list menu`, async () => {
    const stockingCostRow = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointAustria },
      { columnID: ListStockingCostColumn.Account, value: account },
    ]);
    const dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu, stockingCostRow, true);
    // Verify fields' values in dialog
    const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointAustria, new Date(oriStart), timeUnit, lengthOfTime, cost);
    expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. \n'));
    // Verify OK button is disabled with precondition
    let canCopy = await dlgStockingCost.clickOK();
    let btnDisabledTooltip = '';
    if (!canCopy) {
      btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip();
    }
    expect(canCopy).toBe(false, `OK button should be disabled. OK button disabled with tooltip: ${btnDisabledTooltip}`);
    expect(btnDisabledTooltip).toBe('Identical cost definition exists. Stocking cost must be unique by Account, Cost driver and Start date.', 'Disabled tooltip should match');
 
    // Update start value
    const editStartValueInString = `${oriDateWithoutYear}${sopYear}`;
    const editStartValue = new Date(editStartValueInString);
    await dlgStockingCost.dtsStart.setDate(editStartValue);
    canCopy = await dlgStockingCost.clickOK();
    btnDisabledTooltip = '';
    if (!canCopy) {
      btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip();
    }
    expect(canCopy).toBe(true, `OK button should be clickable. OK button disabled with tooltip: ${btnDisabledTooltip}`);
  });
 
  it('Step 3 - Verify values being correct for new and previous stocking cost', async () => {
    const previousUnitCost = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointAustria },
      { columnID: ListStockingCostColumn.Account, value: account },
      { columnID: ListStockingCostColumn.Start, value: oriStart },
    ]);
    const newSCStartString = `${oriDateWithoutYear}${sopYear}`;
    const newStartDate = new Date(newSCStartString);
    const newUnitCost = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointAustria },
      { columnID: ListStockingCostColumn.Account, value: account },
      { columnID: ListStockingCostColumn.Start, value: newSCStartString },
    ]);
 
    const dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu, newUnitCost);
    const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointAustria, newStartDate, timeUnit, lengthOfTime, cost);
    expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. '));
    await dlgStockingCost.clickCancel();
    // Verify UoM, Start, and End column value of the new row
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.UoM, newUnitCost)).toBe(uom, `UoM should be ${uom}`);
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, newUnitCost)).toBe(newSCStartString, `Start should be ${newSCStartString}`);
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, newUnitCost)).toBe(eopString, `End should be ${eopString}`);
    // Verify Start and End column value of the previous stocking cost (Previous Stocking cost start = new Stocking cost start)
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, previousUnitCost)).toBe(oriStart, `Start should be ${oriStart}`);
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, previousUnitCost)).toBe(newSCStartString, `End should be ${newSCStartString}`);
  });
 
  it(`Step 4 - Copy "${stockingPointMorocco}" via button in action bar`, async () => {
    const stockingCostRow = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointMorocco },
      { columnID: ListStockingCostColumn.Account, value: account },
    ]);
    // Select the row
    await stockingCostRow.leftClick();
 
    // Click on "Copy" button in the action bar and wait for dialog to appear
    const dlgStockingCost = await appMP.viewStockingCost.frmStockingCost.openCopyStockingCostDialog();
 
    // Verify fields' values in dialog
    const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointMorocco, new Date(oriStart), timeUnit, 1, cost);
    expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. '));
 
    // Verify OK button is disabled with precondition
    let canCopy = await dlgStockingCost.clickOK();
    let btnDisabledTooltip = '';
    if (!canCopy) {
      btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip();
    }
    expect(canCopy).toBe(false, `OK button should be disabled. OK button disabled with tooltip: ${btnDisabledTooltip}`);
    expect(btnDisabledTooltip).toBe('Identical cost definition exists. Stocking cost must be unique by Account, Cost driver and Start date.', 'Disabled tooltip should match');
 
    // Update start value and click OK button
    const editStartValueInString = `${oriDateWithoutYear}${sopYear}`;
    const editStartValue = new Date(editStartValueInString);
    await dlgStockingCost.dtsStart.setDate(editStartValue);
    canCopy = await dlgStockingCost.clickOK();
    btnDisabledTooltip = '';
    if (!canCopy) {
      btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip();
    }
    expect(canCopy).toBe(true, `OK button should be clickable. OK button disabled with tooltip: ${btnDisabledTooltip}`);
  });
 
  it('Step 5 - Verify values being correct for new and previous stocking cost', async () => {
    const previousUnitCost = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointMorocco },
      { columnID: ListStockingCostColumn.Account, value: account },
      { columnID: ListStockingCostColumn.Start, value: oriStart },
    ]);
    const newSCStartString = `${oriDateWithoutYear}${sopYear}`;
    const newStartDate = new Date(newSCStartString);
    const newUnitCost = await listStockingCost.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointMorocco },
      { columnID: ListStockingCostColumn.Account, value: account },
      { columnID: ListStockingCostColumn.Start, value: newSCStartString },
    ]);
 
    const dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu, newUnitCost);
    const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointMorocco, newStartDate, timeUnit, lengthOfTime, cost);
    expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. \n'));
    await dlgStockingCost.clickCancel();
    // Verify UoM, Start, and End column value of the new row
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.UoM, newUnitCost)).toBe(uom, `UoM should be ${uom}`);
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, newUnitCost)).toBe(newSCStartString, `Start should be ${newSCStartString}`);
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, newUnitCost)).toBe(eopString, `End should be ${eopString}`);
    // Verify Start and End column value of the previous stocking cost (Previous Stocking cost start = new Stocking cost start)
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, previousUnitCost)).toBe(oriStart, `Start should be ${oriStart}`);
    expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, previousUnitCost)).toBe(newSCStartString, `End should be ${newSCStartString}`);
  });
});