| /** | 
|  * @file        ADSO-10189 | 
|  * @description Copy stocking cost via action bar or context menu - single cost selection | 
|  * @testcategory Web - Financials - Stocking points | 
|  * @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 { DataFoodBaseStockingCostStartDate } from '../../../libmp/data/data.stockingcost'; | 
| import { DataFoodBaseAccountCost, DataFoodBaseAccountCostDriver, DataFoodBaseAccountLengthOfTime, DataFoodBaseAccountName, DataFoodBaseAccountTimeUnit, DataFoodBaseAccountUoM } from '../../../libmp/data/data.account'; | 
| import { ListStockingCostColumn } from '../../../libmp/forms/form.stockingcost'; | 
| import { ActionTriggerType } from '../../../libappbase/utils'; | 
| import { startOfPlanningYear } from '../../../libmp/data/data.period'; | 
|   | 
| describe('ADSO-10189 - Copy single stocking cost via action bar or context menu', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   const listStockingCost = appMP.viewStockingCost.frmStockingCost.lstStockingCost; | 
|   let sopYear: string; | 
|   let eopString: string; | 
|   const stockingPointAustria = DataFoodBaseEntityName.DCAustria; | 
|   const stockingPointMorocco = DataFoodBaseEntityName.DCMorocco; | 
|   const account = DataFoodBaseAccountName.GeneralFixedCosts; | 
|   const costDriver = DataFoodBaseAccountCostDriver.Fixed; | 
|   const uom = DataFoodBaseAccountUoM.EuroPerMonth; | 
|   const timeUnit = DataFoodBaseAccountTimeUnit.Month; | 
|   const cost = DataFoodBaseAccountCost._1000; | 
|   const lengthOfTime = DataFoodBaseAccountLengthOfTime._1; | 
|   const oriStart = `1-Jan-${startOfPlanningYear - 1}`; | 
|   const oriDateWithoutYear = DataFoodBaseStockingCostStartDate._1FebWithoutYear; | 
|   | 
|   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}. Get start and end of planning`, async () => { | 
|     // Open Periods view | 
|     await appMP.viewPeriod.switchTo(); | 
|     const formPeriod = appMP.viewPeriod.frmPeriod; | 
|     ({ sopYear, eopString } = await formPeriod.getStartAndEndOfPlanning()); | 
|   }); | 
|   | 
|   it(`Step 1 - Open view ${appMP.viewStockingCost.viewPath}`, async () => { | 
|     await appMP.viewStockingCost.switchTo(); | 
|   }); | 
|   | 
|   it(`Step 2 - Copy "${stockingPointAustria}" via list menu`, async () => { | 
|     const stockingCostRow = await listStockingCost.getRowByValue([ | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointAustria }, | 
|       { columnID: ListStockingCostColumn.Account, value: account }, | 
|     ]); | 
|     const dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu, stockingCostRow, true); | 
|     // Verify fields' values in dialog | 
|     const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointAustria, new Date(oriStart), timeUnit, lengthOfTime, cost); | 
|     expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. \n')); | 
|     // Verify OK button is disabled with precondition | 
|     let canCopy = await dlgStockingCost.clickOK(); | 
|     let btnDisabledTooltip = ''; | 
|     if (!canCopy) { | 
|       btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip(); | 
|     } | 
|     expect(canCopy).toBe(false, `OK button should be disabled. OK button disabled with tooltip: ${btnDisabledTooltip}`); | 
|     expect(btnDisabledTooltip).toBe('Identical cost definition exists. Stocking cost must be unique by Account, Cost driver and Start date.', 'Disabled tooltip should match'); | 
|   | 
|     // Update start value | 
|     const editStartValueInString = `${oriDateWithoutYear}${sopYear}`; | 
|     const editStartValue = new Date(editStartValueInString); | 
|     await dlgStockingCost.dtsStart.setDate(editStartValue); | 
|     canCopy = await dlgStockingCost.clickOK(); | 
|     btnDisabledTooltip = ''; | 
|     if (!canCopy) { | 
|       btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip(); | 
|     } | 
|     expect(canCopy).toBe(true, `OK button should be clickable. OK button disabled with tooltip: ${btnDisabledTooltip}`); | 
|   }); | 
|   | 
|   it('Step 3 - Verify values being correct for new and previous stocking cost', async () => { | 
|     const previousUnitCost = await listStockingCost.getRowByValue([ | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointAustria }, | 
|       { columnID: ListStockingCostColumn.Account, value: account }, | 
|       { columnID: ListStockingCostColumn.Start, value: oriStart }, | 
|     ]); | 
|     const newSCStartString = `${oriDateWithoutYear}${sopYear}`; | 
|     const newStartDate = new Date(newSCStartString); | 
|     const newUnitCost = await listStockingCost.getRowByValue([ | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointAustria }, | 
|       { columnID: ListStockingCostColumn.Account, value: account }, | 
|       { columnID: ListStockingCostColumn.Start, value: newSCStartString }, | 
|     ]); | 
|   | 
|     const dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu, newUnitCost); | 
|     const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointAustria, newStartDate, timeUnit, lengthOfTime, cost); | 
|     expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. ')); | 
|     await dlgStockingCost.clickCancel(); | 
|     // Verify UoM, Start, and End column value of the new row | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.UoM, newUnitCost)).toBe(uom, `UoM should be ${uom}`); | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, newUnitCost)).toBe(newSCStartString, `Start should be ${newSCStartString}`); | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, newUnitCost)).toBe(eopString, `End should be ${eopString}`); | 
|     // Verify Start and End column value of the previous stocking cost (Previous Stocking cost start = new Stocking cost start) | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, previousUnitCost)).toBe(oriStart, `Start should be ${oriStart}`); | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, previousUnitCost)).toBe(newSCStartString, `End should be ${newSCStartString}`); | 
|   }); | 
|   | 
|   it(`Step 4 - Copy "${stockingPointMorocco}" via button in action bar`, async () => { | 
|     const stockingCostRow = await listStockingCost.getRowByValue([ | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointMorocco }, | 
|       { columnID: ListStockingCostColumn.Account, value: account }, | 
|     ]); | 
|     // Select the row | 
|     await stockingCostRow.leftClick(); | 
|   | 
|     // Click on "Copy" button in the action bar and wait for dialog to appear | 
|     const dlgStockingCost = await appMP.viewStockingCost.frmStockingCost.openCopyStockingCostDialog(); | 
|   | 
|     // Verify fields' values in dialog | 
|     const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointMorocco, new Date(oriStart), timeUnit, 1, cost); | 
|     expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. ')); | 
|   | 
|     // Verify OK button is disabled with precondition | 
|     let canCopy = await dlgStockingCost.clickOK(); | 
|     let btnDisabledTooltip = ''; | 
|     if (!canCopy) { | 
|       btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip(); | 
|     } | 
|     expect(canCopy).toBe(false, `OK button should be disabled. OK button disabled with tooltip: ${btnDisabledTooltip}`); | 
|     expect(btnDisabledTooltip).toBe('Identical cost definition exists. Stocking cost must be unique by Account, Cost driver and Start date.', 'Disabled tooltip should match'); | 
|   | 
|     // Update start value and click OK button | 
|     const editStartValueInString = `${oriDateWithoutYear}${sopYear}`; | 
|     const editStartValue = new Date(editStartValueInString); | 
|     await dlgStockingCost.dtsStart.setDate(editStartValue); | 
|     canCopy = await dlgStockingCost.clickOK(); | 
|     btnDisabledTooltip = ''; | 
|     if (!canCopy) { | 
|       btnDisabledTooltip = await dlgStockingCost.btnOk.getTooltip(); | 
|     } | 
|     expect(canCopy).toBe(true, `OK button should be clickable. OK button disabled with tooltip: ${btnDisabledTooltip}`); | 
|   }); | 
|   | 
|   it('Step 5 - Verify values being correct for new and previous stocking cost', async () => { | 
|     const previousUnitCost = await listStockingCost.getRowByValue([ | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointMorocco }, | 
|       { columnID: ListStockingCostColumn.Account, value: account }, | 
|       { columnID: ListStockingCostColumn.Start, value: oriStart }, | 
|     ]); | 
|     const newSCStartString = `${oriDateWithoutYear}${sopYear}`; | 
|     const newStartDate = new Date(newSCStartString); | 
|     const newUnitCost = await listStockingCost.getRowByValue([ | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: stockingPointMorocco }, | 
|       { columnID: ListStockingCostColumn.Account, value: account }, | 
|       { columnID: ListStockingCostColumn.Start, value: newSCStartString }, | 
|     ]); | 
|   | 
|     const dlgStockingCost = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu, newUnitCost); | 
|     const verifyBeforeDialogFeedback = await dlgStockingCost.verifyDialogValue(account, costDriver, stockingPointMorocco, newStartDate, timeUnit, lengthOfTime, cost); | 
|     expect(verifyBeforeDialogFeedback.length).toBe(0, verifyBeforeDialogFeedback.join('. \n')); | 
|     await dlgStockingCost.clickCancel(); | 
|     // Verify UoM, Start, and End column value of the new row | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.UoM, newUnitCost)).toBe(uom, `UoM should be ${uom}`); | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, newUnitCost)).toBe(newSCStartString, `Start should be ${newSCStartString}`); | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, newUnitCost)).toBe(eopString, `End should be ${eopString}`); | 
|     // Verify Start and End column value of the previous stocking cost (Previous Stocking cost start = new Stocking cost start) | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.Start, previousUnitCost)).toBe(oriStart, `Start should be ${oriStart}`); | 
|     expect(await listStockingCost.getCellValueFromRow(ListStockingCostColumn.End, previousUnitCost)).toBe(newSCStartString, `End should be ${newSCStartString}`); | 
|   }); | 
| }); |