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
/**
 * @file          ADSO-10196
 * @description   Products in Stocking Points and Inventory costs display (filter by leaf pisps selection from navigation panel)
 * @testCategory  Web - Financials - Inventory
 * @author        Gay Er Xuan (erxuan.gay@3ds.com)
 * @copyright     Dassault Systèmes
 */
import { qCustomMatcher } from '../../../e2elib/lib/src/main/qmatchers.const';
import { AppMP, Demo, Scenario } from '../../../libmp/appmp';
import { asyncEvery } from '../../../libappbase/utils';
import { ListRow } from '../../../e2elib/lib/src/pageobjects/list/listrow.component';
import { DataFoodBaseProductName, DataFoodBaseEntityName, DataLowFatVanilla6 } from '../../../libmp/data/data.navigation';
import { ListColumnInventoryPISP } from '../../../libmp/forms/form.inventorycostpisp';
 
describe('ADSO-10196 - Products in Stocking Points and Inventory costs display (filter by leaf pisps selection from navigation panel)', () => {
  const appMP = AppMP.getInstance();
  const listInventoryPISP = appMP.viewInventoryCosts.frmInventoryCostPISP.lstInventoryPISP;
  const listAccountCosts = appMP.viewInventoryCosts.frmInventoryCosts.lstAccountCosts;
  const stockingPointParents = [DataFoodBaseEntityName.Europe];
  const stockingPoints: string[] = [DataFoodBaseEntityName.FRWarehouse, DataFoodBaseEntityName.HUWarehouse];
  const stockingPointsStr: string = stockingPoints.join(', ');
  const products: string[] = [DataFoodBaseProductName.LowfatVanilla6pk, DataFoodBaseProductName.LowfatVanilla12pk];
  const productsStr: string = products.join(', ');
  const expectedNrOfProducts = 4;
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    // Reset Navigation Form
    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(`Step 1 - Open view ${appMP.viewInventoryCosts.viewPath}`, async () => {
    await appMP.viewInventoryCosts.switchTo();
  });
 
  it('Step 2 - By default, Filter by Accounts toggled Off', async () => {
    const isFilterByAccount = await appMP.viewInventoryCosts.frmInventoryCosts.cbFilterByAccounts.isChecked();
    expect(isFilterByAccount).toBe(false, 'Filter by Accounts should be defaulted to off');
  });
 
  it(`Step 3 - In navigation panel, select stocking points (${stockingPoints.join(', ')}) and products (${products.join(', ')})`, async () => {
    // Open StockingPoints and Units list
    await appMP.formNavigation.toggleEntityList();
    // Select stocking point
    for (const stockingPoint of stockingPoints) {
      await appMP.formNavigation.filterByEntity(stockingPoint, stockingPointParents);
    }
    // Close StockingPoints and Units list
    await appMP.formNavigation.toggleEntityList(false);
    // Open Product list
    await appMP.formNavigation.toggleProductList();
    // Select product
    await appMP.formNavigation.filterByProduct({ Name: DataFoodBaseProductName.LowfatVanilla6pk }, DataLowFatVanilla6.parents); // Both share same parent
    await appMP.formNavigation.filterByProduct({ Name: DataFoodBaseProductName.LowfatVanilla12pk }, DataLowFatVanilla6.parents);
  });
 
  it('Step 4 - Verify products in Stocking Points and Inventory Cost list are correct', async () => {
    const feedback: (listName: string, feedbackType?: 1 | 2) => string = (listName: string, feedbackType: number = 1): string => {
      switch (feedbackType) {
        case 1:
          return `There should be a total of ${expectedNrOfProducts} PISPs of '${productsStr}' products in '${listName}' list. Got ${inventoryPISPRowCount} instead.`;
        case 2:
          return `'${listName}' list should show relevant products (expected total number of rows: ${expectedNrOfProducts}, expected product names: ${productsStr}, products belong to: ${stockingPointsStr}).`;
        default:
          return '';
      }
    };
 
    // To wait for list InventoryPISP update after filtering applied
    await listInventoryPISP.waitForScreenUpdate();
 
    // Verify products in Stocking Points list shows correct rows
    const inventoryPISPRowCount = await listInventoryPISP.getRowCount();
    const inventoryPISPAllRows = await listInventoryPISP.getAllRows();
    const isPISPShowingRelevantRow = await asyncEvery(inventoryPISPAllRows, async (inventoryPISPRow: ListRow) => {
      const productName = await listInventoryPISP.getCellValueFromRow(ListColumnInventoryPISP.Product, inventoryPISPRow); // await (await inventoryPISPRow.getCell(ListColumnInventoryPISP.Product)).getValue();
      const stockingPointName = await listInventoryPISP.getCellValueFromRow(ListColumnInventoryPISP.StockingPoint, inventoryPISPRow); // await (await inventoryPISPRow.getCell(ListColumnInventoryPISP.StockingPoint)).getValue();
      const result = products.indexOf(productName) > -1 && stockingPoints.indexOf(stockingPointName) > -1;
      return result;
    });
 
    expect(inventoryPISPRowCount === expectedNrOfProducts).toBe(true, feedback('Products in Stocking Points'));
    expect(isPISPShowingRelevantRow).toBe(true, feedback('Products in Stocking Points', 2));
 
    // Verify Inventory Costs list shows correct rows
    const inventoryCostRowCount = await listAccountCosts.getRowCount();
    const inventoryCostAllRows = await listInventoryPISP.getAllRows();
    const isInventoryCostShowingRelevantRow = await asyncEvery(inventoryCostAllRows, async (inventoryCostRow: ListRow) => {
      const productName = await listInventoryPISP.getCellValueFromRow(ListColumnInventoryPISP.Product, inventoryCostRow); // await (await inventoryCostRow.getCell(ListColumnInventoryPISP.Product)).getValue();
      const stockingPointName = await listInventoryPISP.getCellValueFromRow(ListColumnInventoryPISP.StockingPoint, inventoryCostRow); // await (await inventoryCostRow.getCell(ListColumnInventoryPISP.StockingPoint)).getValue();
      const result = products.indexOf(productName) > -1 && stockingPoints.indexOf(stockingPointName) > -1;
      return result;
    });
    expect(inventoryCostRowCount === expectedNrOfProducts).toBe(true, feedback('Inventory Costs'));
    expect(isInventoryCostShowingRelevantRow).toBe(true, feedback('Inventory Costs', 2));
 
    // Verify no non-leaf level pisps are shown in both lists
    const lowfatInventoryCostRow = await listAccountCosts.getInventoryCostByName(DataFoodBaseProductName.Lowfat).catch(() => {
      // do nothing as error is thrown due to no row is found
    });
    expect(lowfatInventoryCostRow).toBeUndefined('Lowfat as a non-leaf PISP should not be in Inventory Account Cost list');
    const lowfatPISPRow = await listInventoryPISP.getPISPByName(DataFoodBaseProductName.Lowfat).catch(() => {
      // do nothing as error is thrown due to no row is found
    });
    expect(lowfatPISPRow).toBeUndefined('Lowfat as a non-leaf PISP should not be in Inventory Product in Stocking Point list');
  });
});