| /** | 
|  * @file         ADSO-10114 | 
|  * @description  Edit unit cost - multiple costs selection of same cost driver (only update Time unit & length of time) | 
|  * @testCategory Web - Financials - Units | 
|  * @author       Umar Adkhamov (umar.adkhamov@3ds.com) | 
|  * @copyright    Dassault Systemes | 
|  */ | 
| import { qCustomMatcher } from '../../../e2elib/lib/src/main/qmatchers.const'; | 
| import { AppMP, Demo, Scenario } from '../../../libmp/appmp'; | 
| import { DataFoodBaseEntityName } from '../../../libmp/data/data.navigation'; | 
| import { DataFoodBaseAccountName } from '../../../libmp/data/data.account'; | 
| import { DialogUnitCost } from '../../../libmp/dialogs/dialog.unitcost'; | 
| import { ListUnitCostColumn, ListUnitCost } from '../../../libmp/forms/form.unitcost'; | 
| import { startOfPlanningYear } from '../../../libmp/data/data.period'; | 
|   | 
| describe('ADSO-10114 -  Edit unit cost - multiple costs selection of same cost driver', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   const unit = DataFoodBaseEntityName.DEFermenter; | 
|   const account = DataFoodBaseAccountName.GeneralFixedCosts; | 
|   let costDriver: string; | 
|   let startDate: Date; // Existing unit's cost | 
|   let cost: string; // Existing unit's cost | 
|   const janSOPMinus1 = `1-Jan-${startOfPlanningYear - 1}`; | 
|   const janSOP = `1-Jan-${startOfPlanningYear}`; | 
|   const newStartDate = new Date(janSOP); | 
|   const newCost = 100; | 
|   const newTimeUnit = 'Quarter'; | 
|   const newLengthTime = 2; | 
|   let listUnitCost: ListUnitCost; | 
|   let dlgUnitCost: DialogUnitCost; | 
|   | 
|   beforeAll(async () => { | 
|     jasmine.addMatchers(qCustomMatcher); | 
|     await appMP.login(); | 
|   }); | 
|   | 
|   afterAll(async () => { | 
|     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 ${unit} exist`, async () => { | 
|     // Open unit cost view | 
|     await appMP.viewUnitCost.switchTo(); | 
|     listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost; | 
|     // Filter by DE Fermenter | 
|     await appMP.formNavigation.filterByEntity(unit, [DataFoodBaseEntityName.Europe, DataFoodBaseEntityName.Plants, DataFoodBaseEntityName.DenmarkPlant]); | 
|     // Verify 1 DE Fermenter Unit Cost exist in the list | 
|     await listUnitCost.waitForScreenUpdate(); | 
|     expect(await listUnitCost.getRowCount()).toBe(1, `Exactly one ${unit} Unit Cost should exist in the list`); | 
|   }); | 
|   | 
|   it(`Step 1 - Create second ${unit} Unit Cost by copying the existing`, async () => { | 
|     // Get the Unit Cost list | 
|     listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost; | 
|   | 
|     // Get the Unit Cost row based on Unit and Account name | 
|     const unitCostRow = await listUnitCost.getRowByIndex(0); | 
|   | 
|     // Open UnitCost dialog for copying | 
|     await listUnitCost.openEditDialog(unitCostRow, true); | 
|     dlgUnitCost = listUnitCost.dlgUnitCost; | 
|     await dlgUnitCost.waitUntilPresent(); | 
|     // Store current values for Cost Driver, Start Date and Cost to verify that they will remain unchanged after batch edit below | 
|     ({ costDriver, startDate, cost } = await dlgUnitCost.getDialogValues()); | 
|   | 
|     await dlgUnitCost.updateUnitCostValue(undefined, undefined, undefined, newStartDate, undefined, undefined, newCost); | 
|     await dlgUnitCost.clickOK(); | 
|   }); | 
|   | 
|   it('Step 2 - Open Batch Edit dialog and verify the fields are disabled and batch edit checkboxes are present', async () => { | 
|     await listUnitCost.selectListRowsByIndex([0], true); | 
|     await listUnitCost.openEditDialog((await listUnitCost.getInboundSelectedRows())[0], false); | 
|     const verifyDialogFields = await dlgUnitCost.verifyBatchEditFieldAccess(); | 
|     expect(verifyDialogFields.length).toBe(0, `${verifyDialogFields.join('\n')}`); | 
|   }); | 
|   | 
|   it('Step 3 - Batch edit Unit Costs', async () => { | 
|     // Click checkbox to enable Time Unit field and verify it is enabled | 
|     await dlgUnitCost.cbBatchEditTimeUnit.click(); | 
|     expect(await dlgUnitCost.ddlTimeUnit.isDisabled()).toBe(false, '"Time Unit" field should be enabled after its checkbox is checked'); | 
|     // Click checkbox to enable Length of Time field and verify it is enabled | 
|     await dlgUnitCost.cbBatchEditLengthOfTime.click(); | 
|     expect(await dlgUnitCost.ddlTimeUnit.isDisabled()).toBe(false, '"Length of Time" field should be enabled after its checkbox is checked'); | 
|     // Update the values | 
|     await dlgUnitCost.updateUnitCostValue(undefined, undefined, undefined, undefined, newTimeUnit, newLengthTime); | 
|     await dlgUnitCost.clickOK(); | 
|   }); | 
|   | 
|   it('Step 4 - Verify that "Time Unit" and "Length of Time" values are updated and other values remain the same', async () => { | 
|     // get previous and new Unit Cost based on start date | 
|     const previousUnit = await listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Start, value: janSOPMinus1 }]); | 
|     const newUnit = await listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Start, value: janSOP }]); | 
|   | 
|     // Verify values of the previous Unit Cost | 
|     await previousUnit.leftClick(); | 
|     await listUnitCost.openEditDialog(previousUnit); | 
|     await dlgUnitCost.waitUntilPresent(); | 
|     let verifyDialogValuesFeedback = await dlgUnitCost.verifyDialogValue(account, costDriver, unit, startDate, newTimeUnit, newLengthTime, Number(cost)); | 
|     expect(verifyDialogValuesFeedback.length).toBe(0, verifyDialogValuesFeedback.join('. ')); | 
|     await dlgUnitCost.clickCancel(); | 
|   | 
|     // Verify values of the new Unit Cost | 
|     await listUnitCost.openEditDialog(newUnit); | 
|     await dlgUnitCost.waitUntilPresent(); | 
|     verifyDialogValuesFeedback = await dlgUnitCost.verifyDialogValue(account, costDriver, unit, newStartDate, newTimeUnit, newLengthTime, newCost); | 
|     expect(verifyDialogValuesFeedback.length).toBe(0, verifyDialogValuesFeedback.join('. ')); | 
|     await dlgUnitCost.clickCancel(); | 
|   }); | 
| }); |