| /** | 
|  * @file        ADSO-50240, ADSO-50242 | 
|  * @description Create & edit leaf customer order | 
|  * @author      Clarence (ccn7@3ds.com) | 
|  * @copyright   Dassault Systèmes | 
|  */ | 
| import { AppMP, Demo, Scenario } from '../../libmp/appmp'; | 
| import { DataMetalBaseProductName, dataMetalsProducts, dataMetalsProductsProvider } from '../../libmp/data/data.product'; | 
| import { DataMetalBaseSalesSegmentName, dataMetalsSalesSegment, dataMetalsSalesSegmentProvider } from '../../libmp/data/data.salessegment'; | 
| import { DataMetalStockingPointName } from '../../libmp/data/data.stockingpoint'; | 
| import { StepList } from '../../libappsop/listsop'; | 
| import { DialogCustomerOrder, DialogCustomerOrderFields } from '../../libmp/dialogs/dialog.customerorder'; | 
| import { StepDialog } from '../../libappsop/dialogsop'; | 
| import { ListCustomerOrdersColumn, ListCustomerOrdersContextMenuItem } from '../../libmp/forms/form.customerorders'; | 
| import { StepActionBarPage } from '../../libappsop/actionbarpagesop'; | 
| import { startOfPlanningYear } from '../../libmp/data/data.period'; | 
| import { StepNavigationPanel } from '../../libmp/forms/navigationpanel/form.navigationpanel'; | 
|   | 
| describe('ADSO-50240 ADSO-50242 - Create and edit leaf customer order', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   const janSOP = `1-Jan-${startOfPlanningYear}`; | 
|   const jan12SOP = `12-Jan-${startOfPlanningYear}`; | 
|   const febSOP = `1-Feb-${startOfPlanningYear}`; | 
|   const listCustomerOrders = appMP.viewCustomerOrders.formCustomerOrders.listCustomerOrders; | 
|   let dlgCustomerOrder: DialogCustomerOrder; | 
|   const valuedlgCustomerOrderJan12: DialogCustomerOrderFields = {SalesSegment: DataMetalBaseSalesSegmentName.AllOrganics, Product: DataMetalBaseProductName.BCCBNarrow, | 
|                                                                  StockingPoint: DataMetalStockingPointName.NorthAmerica, OrderDate: jan12SOP, Quantity: '4567', Price: '8888'}; | 
|   // Default customer and order fields empty | 
|   const valuedlgCustomerOrderJan12Extended: DialogCustomerOrderFields = {...valuedlgCustomerOrderJan12, CustomerName: '', CustomerID: '', OrderID: '', OrderLineID: ''}; | 
|   const valueListCustomerOrderJan12: ListCustomerOrdersColumn = {'Sales segment': DataMetalBaseSalesSegmentName.AllOrganics, Product: DataMetalBaseProductName.BCCBNarrow, | 
|                                                                  'Stocking point': DataMetalStockingPointName.NorthAmerica, 'Order date': jan12SOP, Quantity: '4,567'}; | 
|   // Edit dialog values | 
|   const valueDlgEditCustomerOrderFeb12: DialogCustomerOrderFields = {SalesSegment: DataMetalBaseSalesSegmentName.SpecialCan, Product: DataMetalBaseProductName.BCCBWide, | 
|                                                                      StockingPoint: DataMetalStockingPointName.Asia, OrderDate: febSOP, Quantity: '8888', Price: '9999', | 
|                                                                      CustomerName: 'CustName', CustomerID: 'CustID', OrderID: 'OrderID', OrderLineID: 'OrderLID'}; | 
|   const valueListEditCustomerOrderFeb12: ListCustomerOrdersColumn = {'Sales segment': DataMetalBaseSalesSegmentName.SpecialCan, Product: DataMetalBaseProductName.BCCBWide, | 
|                                                                      'Stocking point': DataMetalStockingPointName.Asia, 'Order date': febSOP, Quantity: '8,888', Price: '9,999', | 
|                                                                      'Customer name': 'CustName', 'Customer ID': 'CustID', 'Order ID': 'OrderID', 'Order line ID': 'OrderLID'}; | 
|   | 
|   beforeAll(async () => { | 
|     await appMP.login(); | 
|   }); | 
|   | 
|   afterAll(async () => { | 
|     await appMP.resetActiveView(appMP.viewCustomerOrders); | 
|     await appMP.cleanupAndLogout(); | 
|   }); | 
|   | 
|   afterEach(async () => { | 
|     await appMP.checkToastMessage(); | 
|   }); | 
|   | 
|   describe('ADSO-50240 - Create leaf customer order', () => { | 
|     it(`Step 1 - ${AppMP.getDemoDataPath(Demo.Metals, Scenario.Base)}.`, async () => { | 
|       await appMP.createDemoDataset(Demo.Metals, Scenario.Base, false); | 
|     }); | 
|   | 
|     it(`Step 2 - Open view ${appMP.viewCustomerOrders.viewPath}.`, async () => { | 
|       await appMP.viewCustomerOrders.switchTo(); | 
|     }); | 
|   | 
|     it(`Step 3 - ${StepList.rightClickSelectMenu(listCustomerOrders.title, ListCustomerOrdersContextMenuItem.Create.Label)}`, async () => { | 
|       [dlgCustomerOrder] = await listCustomerOrders.selectContextMenu(ListCustomerOrdersContextMenuItem.Create); | 
|     }); | 
|   | 
|     it(`Step 4 - ${StepDialog.verifyValueNotExist(DialogCustomerOrder.title, 'Sales segment', DataMetalBaseSalesSegmentName.Cans)} ${StepDialog.updateDialogValues(DialogCustomerOrder.title, {SalesSegment: DataMetalBaseSalesSegmentName.AllOrganics})}`, async () => { | 
|       // Verify only leaf sales segment for user to choose (verify higher level segment not present) | 
|       await dlgCustomerOrder.ddlSalesSegment.verifyValueNotExist(DataMetalBaseSalesSegmentName.Cans); | 
|   | 
|       // Choose a leaf segment | 
|       await dlgCustomerOrder.updateDialogValues({SalesSegment: DataMetalBaseSalesSegmentName.AllOrganics}); | 
|     }); | 
|   | 
|     it(`Step 5 - ${StepDialog.verifyValueNotExist(DialogCustomerOrder.title, 'Product', DataMetalBaseProductName.BCCanBody)} ${StepDialog.updateDialogValues(DialogCustomerOrder.title, {Product: DataMetalBaseProductName.BCCBNarrow})}`, async () => { | 
|       // Verify all product levels able to choose in dropdown (verify higher level product) | 
|       await dlgCustomerOrder.ddlProduct.verifyValueExist(DataMetalBaseProductName.BCCanBody); | 
|   | 
|       // Choose a leaf product | 
|       await dlgCustomerOrder.updateDialogValues({Product: DataMetalBaseProductName.BCCBNarrow}); | 
|     }); | 
|   | 
|     it(`Step 6 - ${StepDialog.updateDialogValues(DialogCustomerOrder.title, {StockingPoint: DataMetalStockingPointName.NorthAmerica})} ${StepDialog.verifyOKEnabled()}`, async () => { | 
|       await dlgCustomerOrder.updateDialogValues({StockingPoint: DataMetalStockingPointName.NorthAmerica}); | 
|       await dlgCustomerOrder.verifyOKEnabled(); | 
|     }); | 
|   | 
|     it(`Step 7 - ${StepDialog.clickTab('Advanced')} ${StepDialog.verifyDialogValues(DialogCustomerOrder.title, {ExcludeFromFulfillmentKPI: 'false', IsEligibleNetting: 'true', IsFirmed: 'true'})}`, async () => { | 
|       await dlgCustomerOrder.pnlAdvanced.clickTab(); | 
|       await dlgCustomerOrder.verifyDialogValues({ExcludeFromFulfillmentKPI: 'false', IsEligibleNetting: 'true', IsFirmed: 'true'}); | 
|     }); | 
|   | 
|     it(`Step 8 - ${StepDialog.clickTab('General')} ${StepDialog.updateDialogValues(DialogCustomerOrder.title, {Quantity: '-1'})} ${StepDialog.verifyOKDisabled()}`, async () => { | 
|       await dlgCustomerOrder.pnlGeneral.clickTab(); | 
|       await dlgCustomerOrder.updateDialogValues({Quantity: '-1'}); | 
|       await dlgCustomerOrder.verifyOKDisabled(); | 
|     }); | 
|   | 
|     it(`Step 9 - ${StepDialog.updateDialogValues(DialogCustomerOrder.title, {Quantity: '2345.1'})} ${StepDialog.clickOK()}`, async () => { | 
|       await dlgCustomerOrder.updateDialogValues({Quantity: '2345.1'}); | 
|       await dlgCustomerOrder.clickOK(); | 
|     }); | 
|   | 
|     it(`Step 10 - ${StepList.verifyRowExists(listCustomerOrders.title, {'Sales segment': DataMetalBaseSalesSegmentName.AllOrganics, Product: DataMetalBaseProductName.BCCBNarrow, | 
|                                                                         'Stocking point': DataMetalStockingPointName.NorthAmerica, 'Order date': janSOP, Quantity: '2,345'})}`, async () => { | 
|       await listCustomerOrders.verifyRowExists({'Sales segment': DataMetalBaseSalesSegmentName.AllOrganics, Product: DataMetalBaseProductName.BCCBNarrow, | 
|                                                 'Stocking point': DataMetalStockingPointName.NorthAmerica, 'Order date': janSOP, Quantity: '2,345'}); | 
|     }); | 
|   | 
|     it(`Step 11 - ${StepList.focusListClickActionButton(listCustomerOrders.title, 'Create')} | 
|                   ${StepDialog.updateDialogValues(DialogCustomerOrder.title, valuedlgCustomerOrderJan12)} ${StepDialog.clickOK()}`, async () => { | 
|       dlgCustomerOrder = await listCustomerOrders.clickActionButton(appMP.abpSales.btnCreate); | 
|       await dlgCustomerOrder.updateDialogValues(valuedlgCustomerOrderJan12); | 
|       await dlgCustomerOrder.clickOK(); | 
|     }); | 
|   | 
|     it(`Step 12 - ${StepList.verifyRowExists(listCustomerOrders.title, valueListCustomerOrderJan12)}`, async () => { | 
|       await listCustomerOrders.verifyRowExists(valueListCustomerOrderJan12); | 
|     }); | 
|   }); | 
|   | 
|   describe('ADSO-50242 - Edit customer order', () => { | 
|     it(`Step 1 - ${StepList.selectRowAndClickMenu(listCustomerOrders.title, valueListCustomerOrderJan12, ListCustomerOrdersContextMenuItem.Edit.Label)}`, async () => { | 
|       // Edit (via context menu) customer order created from previous test case (last step) | 
|       const row = await listCustomerOrders.getRow(valueListCustomerOrderJan12); | 
|       [dlgCustomerOrder] = await listCustomerOrders.selectContextMenu(ListCustomerOrdersContextMenuItem.Edit, row); | 
|     }); | 
|   | 
|     it(`Step 2 - ${StepDialog.verifyDialogValues(DialogCustomerOrder.title, valuedlgCustomerOrderJan12Extended)}`, async () => { | 
|       await dlgCustomerOrder.verifyDialogValues(valuedlgCustomerOrderJan12Extended); | 
|     }); | 
|   | 
|     it(`Step 3 - ${StepDialog.updateDialogValues(DialogCustomerOrder.title, valueDlgEditCustomerOrderFeb12)} ${StepDialog.clickOK()}`, async () => { | 
|       await dlgCustomerOrder.updateDialogValues(valueDlgEditCustomerOrderFeb12); | 
|       await dlgCustomerOrder.clickOK(); | 
|     }); | 
|   | 
|     it(`Step 4 - ${StepNavigationPanel.showSalesSegmentsList()} ${StepNavigationPanel.checkSalesSegments([dataMetalsSalesSegment.SpecialCan.Name])}`, async () => { | 
|       // Filter list by sales segment and product (to speed retrieval) | 
|       await appMP.formNavigation.toggleSalesSegmentList(true); | 
|       const row = await appMP.formNavigation.listSalesSegment.getRow([dataMetalsSalesSegmentProvider, dataMetalsSalesSegment.SpecialCan]); | 
|       await appMP.formNavigation.listSalesSegment.toggleRowCheckbox(row, true); | 
|       await appMP.formNavigation.toggleSalesSegmentList(false); | 
|     }); | 
|   | 
|     it(`Step 5 - ${StepNavigationPanel.showProductsList()} ${StepNavigationPanel.checkProducts([dataMetalsProducts.BCCBWide.Name])}`, async () => { | 
|       await appMP.formNavigation.toggleProductList(true); | 
|       const row = await appMP.formNavigation.listProduct.getRow([dataMetalsProductsProvider, dataMetalsProducts.BCCBWide]); | 
|       await appMP.formNavigation.listProduct.toggleRowCheckbox(row, true); | 
|       await appMP.formNavigation.toggleProductList(false); | 
|     }); | 
|   | 
|     it(`Step 6 - ${StepList.selectRow(listCustomerOrders.title, valueListEditCustomerOrderFeb12)} ${StepActionBarPage.clickButton('Edit')}`, async () => { | 
|       // Edit same customer order via action button | 
|       const row = await listCustomerOrders.selectRow(valueListEditCustomerOrderFeb12); | 
|       dlgCustomerOrder = await listCustomerOrders.clickActionButton(appMP.abpSales.btnEdit, undefined, row); | 
|     }); | 
|   | 
|     it(`Step 7 - ${StepDialog.verifyDialogValues(DialogCustomerOrder.title, valueDlgEditCustomerOrderFeb12)} ${StepDialog.clickCancel()}`, async () => { | 
|       await dlgCustomerOrder.verifyDialogValues(valueDlgEditCustomerOrderFeb12); | 
|       await dlgCustomerOrder.clickCancel(); | 
|     }); | 
|   }); | 
| }); |