| /** | 
|  * @file         ADSO-10105 | 
|  * @description  Create unit cost by drag & drop single unit onto account | 
|  * @testcategory Web - Financials - Units | 
|  * @author       Gay Er Xuan (erxuan.gay@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 { ColumnIDValueMap } from '../../../libappbase/listbase'; | 
| import { AppMP, Demo, Scenario } from '../../../libmp/appmp'; | 
| import { DataFoodBaseEntity, DataFoodBaseEntityName } from '../../../libmp/data/data.navigation'; | 
| import { DataFoodBaseAccountName, DataFoodBaseAccountCostDriver, DataFoodBaseAccountUoM, CostLabel } from '../../../libmp/data/data.account'; | 
| import { ListUnitCostColumn } from '../../../libmp/forms/form.unitcost'; | 
|   | 
| describe('ADSO-10105 - Create unit cost by drag & drop single unit onto account', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   let listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost; | 
|   let dlgUnitCost = listUnitCost.dlgUnitCost; | 
|   let stockingPointRow: ListRow; | 
|   let accountRow: ListRow; | 
|   let newDEFermenterStartDate: Date; | 
|   let newDEFermenterStartString: string; | 
|   let endOfPlanningString: string; | 
|   let sopYear: string; | 
|   | 
|   const accDefaultCost = 100; | 
|   const newCost = 200; | 
|   const entity = DataFoodBaseEntityName.DEFermenter; | 
|   const accName = DataFoodBaseAccountName.ChangeoverCost; | 
|   const accParentName = DataFoodBaseAccountName.CostOfSales; | 
|   const costDriver = DataFoodBaseAccountCostDriver.Changeover; | 
|   | 
|   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.viewPeriod.viewPath} and get the start and end of planning period`, async () => { | 
|     await appMP.viewPeriod.switchTo(); | 
|     const formPeriod = appMP.viewPeriod.frmPeriod; | 
|     ({ sopYear, eopString: endOfPlanningString } = await formPeriod.getStartAndEndOfPlanning()); | 
|     newDEFermenterStartDate = new Date(Number(sopYear), 1, 1); | 
|     newDEFermenterStartString = `1-Feb-${sopYear}`; | 
|   }); | 
|   | 
|   it(`Setup - Open view ${appMP.viewAccount.viewPath}`, async () => { | 
|     await appMP.viewAccount.switchTo(); | 
|   }); | 
|   | 
|   it(`Setup - Configure the ${accName} account with default cost "${accDefaultCost}"`, async () => { | 
|     const listAccount = appMP.viewAccount.frmAccount.listAccount; | 
|   | 
|     const parentRow = await listAccount.getRow({ Name: accParentName }); | 
|     await parentRow.expandRow(); | 
|   | 
|     const accRow = await listAccount.getRow({ Name: accName }); | 
|     const dlgAccount = await listAccount.openAcountDialogViaEditContextMenu(accRow); | 
|   | 
|     await dlgAccount.efCost.sendInput(accDefaultCost.toString()); | 
|     expect(await dlgAccount.clickOK()).toBe(true, `Should be able to edit cost of ${accName} to ${accDefaultCost.toString()}`); | 
|   }); | 
|   | 
|   it(`Setup - Open view ${appMP.viewUnitCost.viewPath}`, async () => { | 
|     await appMP.viewUnitCost.switchTo(); | 
|   }); | 
|   | 
|   it(`Setup - Verify no ${accName} created for ${entity} in "Unit Costs" list`, async () => { | 
|     listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost; | 
|     // Filter by DE Fermenter | 
|     await appMP.formNavigation.filterByEntity(entity, DataFoodBaseEntity.deUnitsParents); | 
|     stockingPointRow = await appMP.formNavigation.listEntity.getEntityRowByName(entity); | 
|     // Verify no changeover cost created | 
|     const row = await listUnitCost.getRowByValue([{ columnID: ListUnitCostColumn.Account, value: accName }]).catch(() => { | 
|       // do nothing as error is thrown due to no row is found | 
|     }); | 
|     expect(row).toBeUndefined(`No ${accName} should be created for ${entity}`); | 
|   }); | 
|   | 
|   it(`Step 1 - Drag unit "${entity}" from navigation panel and drop onto "${accName}" account and verify default values in the pop up dialog`, async () => { | 
|     const listAccount = appMP.viewUnitCost.frmUnitAccount.listAccount; | 
|   | 
|     accountRow = await listAccount.getRow({ Account: accName }); // Get account row | 
|     dlgUnitCost = await listUnitCost.dragEntityToCreateUnitCost(stockingPointRow, accountRow); | 
|     expect(await dlgUnitCost.isVisible()).toBe(true, 'Unit cost dialog should be visible'); | 
|   | 
|     // Verify dialog default value | 
|     const feedback = await listUnitCost.dlgUnitCost.verifyDialogValue(accName, costDriver, entity, new Date(Number(sopYear), 0, 1), undefined, undefined, 100); | 
|     expect(feedback.length).toBe(0, feedback.join('. ')); | 
|   }); | 
|   | 
|   it(`Step 2 - Set start value to "1-Feb-(year of SOP)" and cost value to "${newCost}" in the dialog. Then click Ok button`, async () => { | 
|     // Update dialog value and confirm the dialog | 
|     await dlgUnitCost.updateUnitCostValue(accName, costDriver, entity, newDEFermenterStartDate, undefined, undefined, newCost); | 
|     expect(await listUnitCost.dlgUnitCost.efCost.getComponentLabel()).toBe(CostLabel.euro(costDriver), `Label of cost should be "${CostLabel.euro(costDriver)}"`); | 
|     expect(await dlgUnitCost.clickOK()).toBe(true, 'Should be able to create unit cost'); | 
|   }); | 
|   | 
|   it('Step 3 - In the "Unit Cost" list, verify unit cost row created with correct values', async () => { | 
|     let newDeDefermenterRow: ListRow | undefined; | 
|     const columnValueMap = [ | 
|       { columnID: ListUnitCostColumn.Unit, value: entity }, | 
|       { columnID: ListUnitCostColumn.Account, value: accName }, | 
|       { columnID: ListUnitCostColumn.CostDriver, value: costDriver }, | 
|       { columnID: ListUnitCostColumn.Start, value: newDEFermenterStartString }, | 
|       { columnID: ListUnitCostColumn.End, value: endOfPlanningString }, | 
|       { columnID: ListUnitCostColumn.UoM, value: `${DataFoodBaseAccountUoM.EuroPer}${costDriver}` }, | 
|     ]; | 
|   | 
|     try { | 
|       await listUnitCost.getRowByValue(columnValueMap); | 
|     } catch { | 
|       const values = columnValueMap.map((el: ColumnIDValueMap) => el.value); | 
|       expect(newDeDefermenterRow).toBeDefined(`New row with values "${values.join(', ')}" should be found in "UnitCost" list`); | 
|     } | 
|   }); | 
| }); |