| /** | 
|  * @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')); | 
|   }); | 
| }); |