| /** | 
|  * @file         ADSO-10181 | 
|  * @description  Uniqueness check on stocking costs dialog | 
|  * @testcategory Web - Financials - Stocking points | 
|  * @author       Adrian Foo (adrian.foo@3ds.com) | 
|  * @copyright    Dassault Systèmes | 
|  */ | 
| 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 { LogMessage } from '../../../libappbase/logmessage'; | 
| import { AppMP, Demo, Scenario } from '../../../libmp/appmp'; | 
| import { DataFoodBaseEntityName } from '../../../libmp/data/data.navigation'; | 
| import { DataFoodBaseAccountName } from '../../../libmp/data/data.account'; | 
| import { DialogStockingCost } from '../../../libmp/dialogs/dialog.stockingcost'; | 
| import { ListStockingCostColumn } from '../../../libmp/forms/form.stockingcost'; | 
| import { ActionTriggerType } from '../../../libappbase/utils'; | 
|   | 
| describe('ADSO-10181 - Uniqueness check on stocking costs dialog', () => { | 
|   // Component used in this script | 
|   const appMP = AppMP.getInstance(); | 
|   const viewStockingCost = appMP.viewStockingCost; | 
|   const navigationPanel = appMP.formNavigation; | 
|   const formStockingCost = viewStockingCost.frmStockingCost; | 
|   const listStockingCost = formStockingCost.lstStockingCost; | 
|   | 
|   // Variable used across multiple steps | 
|   let sopYear: string; | 
|   let startDate: Date; | 
|   let startDate2: Date; | 
|   let dialog: DialogStockingCost; | 
|   | 
|   // Test data | 
|   let startDateStr = '1-Jan'; | 
|   let startDateStr2 = '1-Feb'; | 
|   const cost = 15000; | 
|   const cost2 = 20000; | 
|   | 
|   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} to get the start of planning (SOP) year`, async () => { | 
|     await appMP.viewPeriod.switchTo(); | 
|     const formPeriod = appMP.viewPeriod.frmPeriod; | 
|     ({ sopYear } = await formPeriod.getStartAndEndOfPlanning()); | 
|     startDateStr = `${startDateStr}-${sopYear}`; | 
|     startDateStr2 = `${startDateStr2}-${sopYear}`; | 
|     startDate = new Date(startDateStr); | 
|     startDate2 = new Date(startDateStr2); | 
|   }); | 
|   | 
|   it(`Setup - Open view ${viewStockingCost.viewPath}`, async () => { | 
|     await viewStockingCost.switchTo(); | 
|   }); | 
|   | 
|   it('Setup - Ensure a stocking cost with value - Account = "General fixed costs", Stocking point = \ | 
|   "DC - Austria", Start = "1-Jan-(SOP year), Cost = 15000 (Eur/Month)" exists in "Stocking \ | 
|   Cost" list', async () => { | 
|     let stockingCostRow: ListRow | undefined; | 
|   | 
|     await navigationPanel.filterByEntity(DataFoodBaseEntityName.DCAustria, [DataFoodBaseEntityName.Europe]); | 
|   | 
|     const searchCriteria: ColumnIDValueMap[] = [ | 
|       { columnID: ListStockingCostColumn.Account, value: DataFoodBaseAccountName.GeneralFixedCosts }, | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: DataFoodBaseEntityName.DCAustria }, | 
|       { columnID: ListStockingCostColumn.Start, value: startDateStr }, | 
|       { columnID: ListStockingCostColumn.Cost, value: cost.toLocaleString('en') }, | 
|     ]; | 
|   | 
|     try { | 
|       stockingCostRow = await listStockingCost.getRowByValue(searchCriteria); | 
|     } catch { | 
|       dialog = await listStockingCost.openStockingCostDialog(ActionTriggerType.ContextMenu); | 
|       await dialog.updateDialog(DataFoodBaseAccountName.GeneralFixedCosts, undefined, DataFoodBaseEntityName.DCAustria, startDate, cost); | 
|       const [isClickable, tooltip] = await dialog.btnOk.verifyIsButtonClickable(); | 
|       expect(isClickable).toBe(true, LogMessage.btn_notClickable('Ok', tooltip)); | 
|       await dialog.btnOk.click(); | 
|       stockingCostRow = await listStockingCost.getRowByValue(searchCriteria); | 
|     } | 
|     expect(stockingCostRow).toBeDefined(LogMessage.row_notFound(`${DataFoodBaseAccountName.GeneralFixedCosts}, ${DataFoodBaseEntityName.DCAustria}, ${startDate.toString()}, ${cost.toString()}`)); | 
|   }); | 
|   | 
|   it('Step 1 - In "Stocking Costs" list, click "Create" button on action bar', async () => { | 
|     dialog = await listStockingCost.openStockingCostDialogViaAbp(); | 
|     const [isClickable, tooltip] = await dialog.btnOk.verifyIsButtonClickable(); | 
|     expect(isClickable).toBe(false, LogMessage.btn_notDisabled('Ok')); | 
|     const expectedTooltip = 'Identical cost definition exists. Stocking cost must be unique by Account, Cost driver and Start date.'; | 
|     expect(tooltip).toBe(expectedTooltip, `Expect tooltip shown with precondition "${expectedTooltip}", but getting "${tooltip}"`); | 
|   }); | 
|   | 
|   it('Step 2 - Modify the dialog value with "Start = 1-Feb (SOP Year)", "Cost = 20000"', async () => { | 
|     await dialog.updateDialog(DataFoodBaseAccountName.GeneralFixedCosts, undefined, DataFoodBaseEntityName.DCAustria, startDate2, cost2); | 
|     const [isClickable, tooltip] = await dialog.btnOk.verifyIsButtonClickable(); | 
|     expect(isClickable).toBe(true, LogMessage.btn_notClickable('Ok', tooltip)); | 
|     await dialog.btnOk.click(); | 
|     await listStockingCost.waitForScreenUpdate(); | 
|   }); | 
|   | 
|   it('Step 3 - Verify that a new stocking cost created with value in step 2', async () => { | 
|     const searchCriteria: ColumnIDValueMap[] = [ | 
|       { columnID: ListStockingCostColumn.Account, value: DataFoodBaseAccountName.GeneralFixedCosts }, | 
|       { columnID: ListStockingCostColumn.StockingPoint, value: DataFoodBaseEntityName.DCAustria }, | 
|       { columnID: ListStockingCostColumn.Start, value: startDateStr2 }, | 
|       { columnID: ListStockingCostColumn.Cost, value: cost2.toLocaleString('en') }, | 
|     ]; | 
|   | 
|     const rowFound = await listStockingCost.getRowByValue(searchCriteria); | 
|     expect(rowFound).toBeDefined(`Expect ${DataFoodBaseAccountName.GeneralFixedCosts} of ${DataFoodBaseEntityName.DCAustria} with startd date = ${startDateStr}, cost = ${cost} to be found in "Stocking Cost" list`); | 
|   }); | 
| }); |