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
/**
 * @file         ADSO-10119 - Delete one or more unit costs (via list and action bar button)
 * @description  Delete one or more unti cost via context menu and action bar button
 * @testcategory Web - Financials - Units
 * @author       Wong Jia Hui (jiahui.wong@3ds.com)
 * @copyright    Dassault Systemes
 */
import { qCustomMatcher } from '../../../e2elib/lib/src/main/qmatchers.const';
import { ListRow } from '../../../e2elib/lib/src/pageobjects/list/listrow.component';
import { LogMessage } from '../../../libappbase/logmessage';
import { AppMP, Demo, Scenario } from '../../../libmp/appmp';
import { DataFoodBaseAccountName } from '../../../libmp/data/data.account';
import { ListUnitCostColumn, ListUnitCostContextMenuItem } from '../../../libmp/forms/form.unitcost';
 
describe('ADSO-10119 - Delete one or more unit costs (via list and action bar button)', () => {
  const appMP = AppMP.getInstance();
  const listUnitAccount = appMP.viewUnitCost.frmUnitAccount.listAccount;
  const formUnitCost = appMP.viewUnitCost.frmUnitCost;
  const listUnitCost = formUnitCost.listUnitCost;
  const accChangeoverCost = DataFoodBaseAccountName.ChangeoverCost;
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    // Clear demo data
    await appMP.viewUnitCost.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 no cost is created in ${accChangeoverCost} account`, async () => {
    await appMP.viewUnitCost.switchTo();
    await listUnitAccount.selectRow({ Account: accChangeoverCost });
 
    await formUnitCost.toggleFilterByAccount(true);
    const unitCostRowCount = await listUnitCost.getRowCount();
    expect(unitCostRowCount).toBe(0, 'There should be no any row in UnitCost list');
    await formUnitCost.toggleFilterByAccount(false);
  });
 
  it('Step 1 - Select 1 unit cost and delete via "Delete" context menu', async () => {
    const unitCostRow = await listUnitCost.getRowByIndex(0);
    const { Unit, Account, CostDriver, Start } = await listUnitCost.getCellValuesFromRow(unitCostRow, ListUnitCostColumn);
    await listUnitCost.deleteUnitCostViaContextMenu([unitCostRow]);
 
    const deletedUnitCostRow = await listUnitCost.getUnitCostRowByValues(Unit, Account, CostDriver, Start).catch(() => {
      // do nothing as error is thrown due to no row is found
    });
    expect(deletedUnitCostRow).toBeUndefined(`UnitCost row with ${Unit} unit, ${Account} account, ${CostDriver} cost driver and ${Start} start value should be deleted`);
  });
 
  it('Step 2 - Select 2 unit cost and delete via "Delete" action bar button', async () => {
    const unitCostRows: ListRow[] = [];
    const units: string[] = [];
    const accounts: string[] = [];
    const costDrivers: string[] = [];
    const starts: string[] = [];
    for (let count = 0; count < 2; count++) {
      const row = await listUnitCost.getRowByIndex(count);
      const { Unit, Account, CostDriver, Start } = await listUnitCost.getCellValuesFromRow(row, ListUnitCostColumn);
      units.push(Unit);
      accounts.push(Account);
      costDrivers.push(CostDriver);
      starts.push(Start);
      unitCostRows.push(row);
    }
 
    await listUnitCost.deleteUnitCostViaContextMenu(unitCostRows);
 
    for (let count = 0; count < 2; count++) {
      const deletedUnitCostRow = await listUnitCost.getUnitCostRowByValues(units[count], accounts[count], costDrivers[count], starts[count]).catch(() => {
        // do nothing as error is thrown due to no row is found
      });
      expect(deletedUnitCostRow).toBeUndefined(`UnitCost row with ${units[count]} unit, ${accounts[count]} account, ${costDrivers[count]} cost driver and ${starts[count]} start value should be deleted`);
    }
  });
 
  it(`Step 3 - Select ${accChangeoverCost} account and verify "Delete" context menu and action bar button is disabled`, async () => {
    await listUnitAccount.selectRow({ Account: accChangeoverCost });
 
    await formUnitCost.toggleFilterByAccount(true);
    const isDeleteButtonDisabled = !(await appMP.abpData.btnDelete.isClickable());
    expect(isDeleteButtonDisabled).toBe(true, LogMessage.btn_isEnabled('Delete'));
 
    await listUnitCost.rightClick();
    await listUnitCost.cmMenu.waitUntilPresent();
    const isDeleteContextMenuDisabled = await listUnitCost.cmMenu.isDisabled(ListUnitCostContextMenuItem.MenuDelete);
    expect(isDeleteContextMenuDisabled).toBe(true, LogMessage.menu_isEnabled('Delete'));
  });
});