| /** | 
|  * @file         ADSO-10193 | 
|  * @description  Products in Stocking points and Inventory costs display (filter by accounts) | 
|  * @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 { DataInventoryAccount, DataInventoryCostCostDriver } from '../../../libmp/data/data.inventorycost'; | 
| import { DataLowFatVanilla6, DataFoodBaseEntity, DataFoodBaseEntityName } from '../../../libmp/data/data.navigation'; | 
| import { ListColumnAccountCosts } from '../../../libmp/forms/form.inventorycosts'; | 
| import { QConsole } from '../../../e2elib/lib/src/helper/qconsole'; | 
| import { startOfPlanningYear } from '../../../libmp/data/data.period'; | 
|   | 
| describe('ADSO-10193 - Products in Stocking points and Inventory costs display (filter by accounts)', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   const listInventoryCost = appMP.viewInventoryCosts.frmInventoryCosts.lstAccountCosts; | 
|   const cbFilterByAcc = appMP.viewInventoryCosts.frmInventoryCosts.cbFilterByAccounts; | 
|   const stockingPoint = DataFoodBaseEntityName.HUWarehouse; | 
|   const stockingPointParents = DataFoodBaseEntity.huWarehouseParent; | 
|   const product = DataLowFatVanilla6.name; | 
|   const accInventoryLocationPreferenceCost = DataInventoryAccount.InventoryLocationPreferenceCost; | 
|   const accInventoryValue = DataInventoryAccount.InventoryValue; | 
|   const accInventoryHoldingCost = DataInventoryAccount.InventoryHoldingCost; | 
|   const newCostCostDriver = DataInventoryCostCostDriver.InventoryHolding; | 
|   const newCostStart = new Date(`1-Jan-${startOfPlanningYear}`); | 
|   const newCostCost = 100; | 
|   | 
|   beforeAll(async () => { | 
|     jasmine.addMatchers(qCustomMatcher); | 
|     await appMP.login(); | 
|   }); | 
|   | 
|   afterAll(async () => { | 
|     // Reset views and navigation | 
|     await appMP.formNavigation.reset(); | 
|     await appMP.viewInventoryCosts.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.viewInventoryCosts.viewPath}. Create a new inventory cost`, async () => { | 
|     // Open Inventory Cost View | 
|     await appMP.viewInventoryCosts.switchTo(); | 
|     // Create new inventory cost | 
|     await listInventoryCost.createNewInventoryCost(accInventoryHoldingCost, newCostCostDriver, product, stockingPoint, newCostStart, newCostCost); | 
|   }); | 
|   | 
|   it('Step 1 - Reset filtering in navigation form and toggle ON Filter by Accounts in Inventory Costs form', async () => { | 
|     // Open navigation form | 
|     await appMP.formNavigation.openNavigationPanel(); | 
|     await appMP.formNavigation.resetNaviToRoot(); | 
|     // Toggle ON Filter by Accounts | 
|     await appMP.viewInventoryCosts.frmInventoryCosts.toggleFilterByAccount(true); | 
|     expect(await cbFilterByAcc.isChecked()).toBe(true, 'Filter by Accounts should be toggled to ON'); | 
|   }); | 
|   | 
|   it(`Step 2 - Select ${accInventoryLocationPreferenceCost} and verify inventory cost showing no cost`, async () => { | 
|     // Select inventory account | 
|     const acc = await appMP.viewInventoryCosts.frmInventoryAccounts.lstAccounts.getAccountByName(accInventoryLocationPreferenceCost); | 
|     await acc.leftClick(); | 
|     await listInventoryCost.waitForScreenUpdate(); | 
|     // Verify inventory cost list showing no cost | 
|     expect(await listInventoryCost.getRowCount()).toBe(0, `No cost should be shown for ${accInventoryLocationPreferenceCost}`); | 
|   }); | 
|   | 
|   it(`Step 3 - Select ${accInventoryValue} and filter in navigation panel, then verify inventory cost showing correct cost`, async () => { | 
|     // Select inventory account | 
|     const acc = await appMP.viewInventoryCosts.frmInventoryAccounts.lstAccounts.getAccountByName(accInventoryValue); | 
|     await acc.leftClick(); | 
|     // Filter in navigation panel | 
|     await appMP.formNavigation.filterByEntity(stockingPoint, stockingPointParents); | 
|     await appMP.formNavigation.filterByProduct({ Name: product }, DataLowFatVanilla6.parents); | 
|     await QConsole.waitForStable(1000); | 
|     // Verify list showing correct value | 
|     const allRows = await listInventoryCost.getAllRows(); | 
|     expect(await listInventoryCost.matchColumnValueFromRows(allRows, ListColumnAccountCosts.Product, product)).toBe(true, `Inventory cost list should contain only rows with ${product} as product`); | 
|     expect(await listInventoryCost.matchColumnValueFromRows(allRows, ListColumnAccountCosts.StockingPoint, stockingPoint)).toBe(true, `Inventory cost list should contain only rows with ${stockingPoint} as stocking point`); | 
|     expect(await listInventoryCost.matchColumnValueFromRows(allRows, ListColumnAccountCosts.Account, accInventoryValue)).toBe(true, `Inventory cost list should contain only rows with ${accInventoryValue} as account`); | 
|   }); | 
|   | 
|   it('Step 4 - Toggle OFF Filter by Accounts and verify there is one more cost instance', async () => { | 
|     // Record old instance count | 
|     const oldAllRows = await listInventoryCost.getAllRows(); | 
|     const oldRowCount = oldAllRows.length; | 
|     // Toggle OFF Filter by Accounts | 
|     await appMP.viewInventoryCosts.frmInventoryCosts.toggleFilterByAccount(false); | 
|     expect(await cbFilterByAcc.isChecked()).toBe(false, 'Filter by Accounts should be toggled to OFF'); | 
|     // Verify one more row is shown in the list | 
|     const newRowCount = await listInventoryCost.getRowCount(); | 
|     expect(newRowCount - oldRowCount).toBe(1, 'There should be one more cost shown in the list after toggle Filter by Accounts to OFF'); | 
|     // Verify value of the additional instance | 
|     const newRow = listInventoryCost.findInventoryCost(product, stockingPoint, accInventoryHoldingCost, newCostCostDriver, newCostCost); | 
|     expect(newRow).toBeDefined('The values of the additional instance does not match'); | 
|   }); | 
| }); |