| /** | 
|  * @file        ADSO-10126, ADSO-10128, ADSO-10129 - Operations and Operation Costs display | 
|  * @description Verify operation cost instances display result after filtering applied either via accounts form / navigation panel | 
|  * @author      Wong Jia Hui (jiahui.wong@3ds.com) | 
|  * @copyright   Dassault Systèmes | 
|  */ | 
| import { qCustomMatcher } from '../../../e2elib/lib/src/main/qmatchers.const'; | 
| import { AppMP, Demo, Scenario } from '../../../libmp/appmp'; | 
| import { DataFoodBaseEntity, DataFoodBaseEntityName } from '../../../libmp/data/data.navigation'; | 
| import { ListEntityColumnName } from '../../../libmp/forms/navigationpanel/form.navigationpanel'; | 
|   | 
| describe('ADSO-10126, ADSO-10128, ADSO-10129 - Verify OperationCost form display result after filter applied', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   let errMsg = ''; | 
|   let compareStringArray = [DataFoodBaseEntityName.HUFermenter, DataFoodBaseEntityName.HUStrainer, DataFoodBaseEntityName.HUFinishing, DataFoodBaseEntityName.HUPackaging]; | 
|   beforeAll(async () => { | 
|     jasmine.addMatchers(qCustomMatcher); | 
|     await appMP.login(); | 
|   }); | 
|   | 
|   afterAll(async () => { | 
|     await appMP.cleanupAndLogout(); | 
|   }); | 
|   | 
|   afterEach(async () => { | 
|     await appMP.checkToastMessage(); | 
|   }); | 
|   | 
|   describe('ADSO-10126 - Verify OperationCost display result after filter applied via FilterByAccount checkbox and navigation panel', () => { | 
|     it(`Setup - ${AppMP.getDemoDataPath(Demo.Food, Scenario.Base)}`, async () => { | 
|       await appMP.createDemoDataset(Demo.Food, Scenario.Base, false); | 
|     }); | 
|   | 
|     it(`Setup - Open view ${appMP.viewOperationCost.viewPath}. Open navigation panel and click Home button to reset navigation to root operations.`, async () => { | 
|       // Go to operation cost view and make sure operation, operation acc, and opertion cost form is opened | 
|       await appMP.viewOperationCost.switchTo(); | 
|       await appMP.formNavigation.openNavigationPanel(); | 
|       // Click on home button on navigation panel to reset filter (if there is any filter set in navigation panel) | 
|       // FIXME: CL219809 - Home button does not reset hidden child, due to changes of checkbox behavior. | 
|       // Use this only if the targeted row is visible in the list | 
|       await appMP.formNavigation.resetNaviToRoot(); | 
|     }); | 
|   | 
|     it('Setup - Click StockingPoints and Units button and then resize "DisplayName" column', async () => { | 
|       // Open 'StockingPoints and Units' list (ListEntity) in navigation panel by clicking on 'StockingPoints and Units' button (ButtonNavEntity) | 
|       await appMP.formNavigation.toggleEntityList(); | 
|       // Resize DisplayName column in case DisplayName value will be show as "Hungary Pl..." | 
|       await appMP.formNavigation.listEntity.resizeColumnWithCoveredName(ListEntityColumnName.DisplayName, 200); | 
|     }); | 
|   | 
|     it('Step 1 - Toggle ON Filter by Accounts in Operation Costs form.', async () => { | 
|       // toggle on Filter by acocunts in operation cost form (it should be uncheck by default) | 
|       await appMP.viewOperationCost.frmOperationCost.toggleFilterByAccount(true); | 
|       expect(await appMP.viewOperationCost.frmOperationCost.cbFilterByAccounts.isChecked()).toBe(true, 'Checkbox FilterByAccounts should be checked'); | 
|     }); | 
|   | 
|     it('Step 2 - In Operations Accounts form, select Rework cost account and verify Operation costs showing no cost', async () => { | 
|       // toggle on Filter by acocunts in operation cost form (it should be uncheck by default) | 
|       await appMP.viewOperationCost.frmOperationCost.toggleFilterByAccount(true); | 
|       expect(await appMP.viewOperationCost.frmOperationCost.cbFilterByAccounts.isChecked()).toBe(true, 'Checkbox FilterByAccounts should be checked'); | 
|       // Select "Rework cost account" in operation account form | 
|       await appMP.viewOperationCost.frmOperationsAccount.listOperationAccount.selectOperationAccountRowByName('Rework cost'); | 
|       // Verify there is no any row in operation cost form | 
|       expect(await appMP.viewOperationCost.frmOperationCost.listOperationCost.getOperationCostRowCount()).toEqual(0, 'There should be no any instances show after filtered by "Rework cost account"'); | 
|     }); | 
|   | 
|     it('Step 3 - Select Labor cost account in Operation Accounts list and check DE Fermenter in the navigation panel', async () => { | 
|       // Select Labor cost in operation account form and check "DE Fermenter" unit in navigation panel | 
|       await appMP.viewOperationCost.frmOperationsAccount.listOperationAccount.selectOperationAccountRowByName('Labor cost'); | 
|   | 
|       // Check leaf units DE Fermenter | 
|       await appMP.formNavigation.listEntity.toggleEntityRowCheckbox(true, DataFoodBaseEntityName.DEFermenter, DataFoodBaseEntity.deUnitsParents); | 
|       const row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.DEFermenter); | 
|       expect(await row.isChecked()).toBe(true, 'DE Fermenter row checkbox should be checked'); | 
|     }); | 
|   | 
|     it('Step 4 - Verify Operations Costs showing 1 Labor cost of DE Fermenter', async () => { | 
|       // Verify operation cost form display only show instances with "Labor cost" and "DE Fermenter" unit | 
|       const operationCostRows = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getAllOperationCostRows(); | 
|       for (const row of operationCostRows) { | 
|         const accountColumnCellValue = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getCellValueFromRow('Account', row); | 
|         expect(accountColumnCellValue).toEqual('Labor cost', 'All rows in OperationCostList should have Account value as "Labor cost"'); | 
|         const unitColumnCellValue = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getCellValueFromRow('Unit', row); | 
|         expect(unitColumnCellValue).toEqual('DE Fermenter', 'All rows in OperationCostList should have Unit value as "DE Fermenter"'); | 
|       } | 
|     }); | 
|   | 
|     it('Step 5 - Toggle OFF Filter by Accounts in Operation Costs form. Verify there are two operation costs of DE Fermenter: 1 Labor cost and 1 Operating cost', async () => { | 
|       const rowCountBeforeToggleOffFilter = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getOperationCostRowCount(); | 
|       // toggle off Filter by account in operation cost form | 
|       await appMP.viewOperationCost.frmOperationCost.toggleFilterByAccount(false); | 
|       expect(await appMP.viewOperationCost.frmOperationCost.cbFilterByAccounts.isChecked()).toBe(false, 'Checkbox FilterByAccounts should be uncheck'); | 
|       expect(await appMP.viewOperationCost.frmOperationCost.listOperationCost.getOperationCostRowCount()).toBeGreaterThan(rowCountBeforeToggleOffFilter, 'Number of row in OperationCost form should increase after unchecked FilterByAccount'); | 
|       // Verify operation cost form display only show instances with "DE Fermenter" unit with other account other than "Labor cost" | 
|       const operationCostRows = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getAllOperationCostRows(); | 
|       for (const row of operationCostRows) { | 
|         const unitColumnCellValue = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getCellValueFromRow('Unit', row); | 
|         expect(unitColumnCellValue).toEqual('DE Fermenter', 'All rows in OperationCostList should have Unit value as "DE Fermenter"'); | 
|       } | 
|     }); | 
|   | 
|     it('Cleanup - Toggle off Filter By Account in operation cost; click Home button in navigation panel to reset filter in StockingPoints and Units list and collapse the list', async () => { | 
|       // Toggle off Filter By Account in operation cost | 
|       await appMP.viewOperationCost.frmOperationCost.toggleFilterByAccount(false); | 
|       expect(await appMP.viewOperationCost.frmOperationCost.cbFilterByAccounts.isChecked()).toBe(false, 'Checkbox FilterByAccounts should be uncheck'); | 
|       // uncheck leaf units DE Fermenter. | 
|       await appMP.formNavigation.resetNaviToRoot(); | 
|       // Collapse Denmark Plant | 
|       const row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.DenmarkPlant, DataFoodBaseEntity.plantsParent); | 
|       await row.collapseRow(); | 
|     }); | 
|   }); | 
|   | 
|   describe('ADSO-10128 - Verify OperationCost display result after filter applied via navigation panel (filter by parent unit)', () => { | 
|     it('Step 1 - In navigation panel, select Hungary Plant unit', async () => { | 
|       // Check Hungary Plant unit in navigation panel | 
|       await appMP.formNavigation.listEntity.toggleEntityRowCheckbox(true, DataFoodBaseEntityName.HungaryPlant, DataFoodBaseEntity.plantsParent); | 
|       const row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.HungaryPlant); | 
|       expect(await row.isChecked()).toBe(true, 'Hungary Plant row checkbox should be checked'); | 
|     }); | 
|   | 
|     it('Step 2 - Verify Operations list shows all operations related to HU Fermenter(1), HU Packaging(8) and HU Strainer(4)', async () => { | 
|       // Get all operation rows show and verify if the Unit value is either "HU Fermenter", "HU Strainer", "HU Finishing" or "HU Packaging" | 
|       const operationRows = await appMP.viewOperationCost.frmOperations.listOperations.getAllOperationRows(); | 
|       errMsg = 'Unit value of UnitCost row should be either "HU Fermenter", "HU Finishing", "HU Packaging" or "HU Strainer"'; | 
|       const isAllRowsValid = await appMP.viewOperationCost.frmOperations.listOperations.verifyAllRowsSatisfyColumnValuesByUnit(operationRows, compareStringArray); | 
|       expect(isAllRowsValid).toBe(true, errMsg); | 
|     }); | 
|   | 
|     it('Step 3 - Verify Operations Costs list shows all operation costs related to HU Fermenter(2), HU Finishing(16), HU Packaging(16) and HU Strainer(8)', async () => { | 
|       // Get all operation cost rows show and verify if the Unit value is either "HU Fermenter", "HU Strainer", "HU Finishing" or "HU Packaging" | 
|       const operationCostRows = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getAllOperationCostRows(); | 
|       const isAllRowsValid = await appMP.viewOperationCost.frmOperationCost.listOperationCost.verifyAllRowsSatisfyColumnValuesByUnit(operationCostRows, compareStringArray); | 
|       expect(isAllRowsValid).toBe(true, errMsg); | 
|     }); | 
|   | 
|     it('Cleanup - Toggle off Filter By Account in operation cost; click Home button in navigation panel to reset filter in StockingPoints and Units list', async () => { | 
|       // Toggle off Filter By Account in operation cost | 
|       await appMP.viewOperationCost.frmOperationCost.toggleFilterByAccount(false); | 
|       expect(await appMP.viewOperationCost.frmOperationCost.cbFilterByAccounts.isChecked()).toBe(false, 'Checkbox FilterByAccounts should be uncheck'); | 
|   | 
|       // Uncheck Hungary Plant unit in navigation panel | 
|       await appMP.formNavigation.listEntity.toggleEntityRowCheckbox(false, DataFoodBaseEntityName.HungaryPlant, DataFoodBaseEntity.plantsParent); | 
|     }); | 
|   }); | 
|   | 
|   describe('ADSO-10129 - Verify OperationCost display result after filter applied via navigation panel (filter by leaf units)', () => { | 
|     it('Step 1 - In navigation panel, select leaf Operations HU Fermenter', async () => { | 
|       // Check HU Fermenter unit in navigation panel | 
|       await appMP.formNavigation.listEntity.toggleEntityRowCheckbox(true, DataFoodBaseEntityName.HUFermenter, DataFoodBaseEntity.huUnitsParent); | 
|       const row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.HUFermenter); | 
|       expect(await row.isChecked()).toBe(true, 'HU Fermenter row checkbox should be checked'); | 
|     }); | 
|   | 
|     it('Step 2 - In navigation panel, select leaf Operations HU Strainer', async () => { | 
|       // Check HU Strainer unit in navigation panel | 
|       await appMP.formNavigation.listEntity.toggleEntityRowCheckbox(true, DataFoodBaseEntityName.HUStrainer, DataFoodBaseEntity.huUnitsParent); | 
|       const row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.HUStrainer); | 
|       expect(await row.isChecked()).toBe(true, 'HU Strainer row checkbox should be checked'); | 
|     }); | 
|   | 
|     it('Step 3 - Verify Operations list show 1 operation of HU Fermenter and 4 operations of HU Strainer', async () => { | 
|       compareStringArray = [DataFoodBaseEntityName.HUFermenter, DataFoodBaseEntityName.HUStrainer]; | 
|       // Get all operation rows show and verify if the Unit value is either "HU Fermenter" or "HU Strainer" | 
|       const operationRows = await appMP.viewOperationCost.frmOperations.listOperations.getAllOperationRows(); | 
|       errMsg = 'Unit value of UnitCost row should be either "HU Fermenter" or "HU Strainer"'; | 
|       const isAllRowsValid = await appMP.viewOperationCost.frmOperations.listOperations.verifyAllRowsSatisfyColumnValuesByUnit(operationRows, compareStringArray); | 
|       expect(isAllRowsValid).toBe(true, errMsg); | 
|     }); | 
|   | 
|     it('Step 4 - Verify Operation Costs list showing 2 costs for HU Fermenter and 8 costs for HU Strainer', async () => { | 
|       // Get all operation cost rows show and verify if the Unit value is either "HU Fermenter" or "HU Strainer" | 
|       const operationCostRows = await appMP.viewOperationCost.frmOperationCost.listOperationCost.getAllOperationCostRows(); | 
|       const isAllRowsValid = await appMP.viewOperationCost.frmOperationCost.listOperationCost.verifyAllRowsSatisfyColumnValuesByUnit(operationCostRows, compareStringArray); | 
|       expect(isAllRowsValid).toBe(true, errMsg); | 
|     }); | 
|   | 
|     it('Cleanup - Collapse Hungary Plant, Plants, Europe rows', async () => { | 
|       // Uncheck HU Fermenter & HU Strainer unit in navigation panel | 
|       await appMP.formNavigation.resetNaviToRoot(); | 
|       // Collapse Hungary Plant row | 
|       let row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.HungaryPlant, DataFoodBaseEntity.plantsParent); | 
|       await row.collapseRow(); | 
|       // Collapse Plants row | 
|       row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.Plants, [DataFoodBaseEntityName.Europe]); | 
|       await row.collapseRow(); | 
|       // Collapse Europe row | 
|       row = await appMP.formNavigation.listEntity.getRowByCellValue(ListEntityColumnName.DisplayName, DataFoodBaseEntityName.Europe); | 
|       await row.collapseRow(); | 
|     }); | 
|   }); | 
| }); |