| /** | 
|  * @file        ADSO-9879 ADSO-9882 ADSO-9881 | 
|  * @description Create, edit and delete (CRUD) external supply | 
|  * @author      Chan Clarence (ccn7@3ds.com) | 
|  * @copyright   Dassault Systèmes | 
|  */ | 
| import { qCustomMatcher } from '../../e2elib/lib/src/main/qmatchers.const'; | 
| import { AppMP, Demo, Scenario } from '../../libmp/appmp'; | 
| import { StepDialog } from '../../libappsop/dialogsop'; | 
| import { StepList } from '../../libappsop/listsop'; | 
| import { DialogExternalSupply, DialogExternalSupplyFields } from '../../libmp/dialogs/dialog.externalsupply'; | 
| import { DialogProduct, DialogProductFields } from '../../libmp/dialogs/dialog.product'; | 
| import { ListExternalSuppliesColumn, ListExternalSuppliesContextMenuItem } from '../../libmp/forms/form.externalsupplies'; | 
| import { ListEntity, ListProduct, StepNavigationPanel } from '../../libmp/forms/navigationpanel/form.navigationpanel'; | 
| import { ListProductContextMenuItem } from '../../libmp/forms/form.product'; | 
| import { DataFoodBaseEntityName, DataLowFatStrawberry12 } from '../../libmp/data/data.navigation'; | 
| import { startOfPlanningYear } from '../../libmp/data/data.period'; | 
|   | 
| describe('ADSO-9879 ADSO-9882 ADSO-9881 - Create, edit and delete (CRUD) external supply', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   const listNavEntity = appMP.formNavigation.listEntity; | 
|   const listNavProduct = appMP.formNavigation.listProduct; | 
|   const listProduct = appMP.viewProduct.frmProduct.listProduct; | 
|   const listExternalSupply = appMP.viewExternalSupplies.formExternalSupplies.listExternalSupplies; | 
|   let dlgProduct: DialogProduct; | 
|   let dlgExternalSupply: DialogExternalSupply; | 
|   const updateProductShelfLife: DialogProductFields = { ShelfLifeEnabled: 'true', ShelfLife: '60' }; | 
|   const defaultExtSupplyValues: DialogExternalSupplyFields = { StockingPoint: DataFoodBaseEntityName.DCAustria, Product: DataLowFatStrawberry12.name }; | 
|   const updateExtSupplyValues: DialogExternalSupplyFields = { Date: `3-Feb-${startOfPlanningYear}`, ManufacturedDate: `2-Feb-${startOfPlanningYear}`, Quantity: '123' }; | 
|   const updateExtSupplyValues2: DialogExternalSupplyFields = { Date: `13-Feb-${startOfPlanningYear}`, ManufacturedDate: `12-Feb-${startOfPlanningYear}`, Quantity: '999', Description: 'Edit created external supply' }; | 
|   const verifyCreatedExtSupplyValues: DialogExternalSupplyFields = { ...defaultExtSupplyValues, ...updateExtSupplyValues }; // Combine both object values | 
|   const listVerifyValues: ListExternalSuppliesColumn = { Date: `3-Feb-${startOfPlanningYear}`, 'Stocking point': DataFoodBaseEntityName.DCAustria, Product: DataLowFatStrawberry12.name, Quantity: '123.00' }; | 
|   const listVerifyValues2: ListExternalSuppliesColumn = { Date: `13-Feb-${startOfPlanningYear}`, 'Stocking point': DataFoodBaseEntityName.DCAustria, Product: DataLowFatStrawberry12.name, Quantity: '999.00', Description: 'Edit created external supply' }; | 
|   // Delete steps | 
|   let rowCount = 0; | 
|   | 
|   beforeAll(async () => { | 
|     jasmine.addMatchers(qCustomMatcher); | 
|     await appMP.login(); | 
|   }); | 
|   | 
|   afterAll(async () => { | 
|     await appMP.formNavigation.reset(); | 
|     await appMP.resetActiveView(appMP.viewExternalSupplies); | 
|     await appMP.cleanupAndLogout(); | 
|   }); | 
|   | 
|   afterEach(async () => { | 
|     await appMP.checkToastMessage(); | 
|   }); | 
|   | 
|   describe('ADSO-9879 - Create external supply', () => { | 
|     it(`Step 1 - ${AppMP.getDemoDataPath(Demo.Food, Scenario.Base)}`, async () => { | 
|       await appMP.createDemoDataset(Demo.Food, Scenario.Base, false); | 
|     }); | 
|   | 
|     it(`Step 2 - Open view ${appMP.viewProduct.viewPath}.`, async () => { | 
|       await appMP.viewProduct.switchTo(); | 
|     }); | 
|   | 
|     it(`Step 3 - ${StepList.selectRowAndClickMenu(ListProduct.title, {Name: DataLowFatStrawberry12.name}, ListProductContextMenuItem.Edit.Label)}`, async () => { | 
|       const row = await listProduct.getRow({Name: DataLowFatStrawberry12.name}, DataLowFatStrawberry12.parents); | 
|       [dlgProduct] = await listProduct.selectContextMenu(ListProductContextMenuItem.Edit, row); | 
|     }); | 
|   | 
|     it(`Step 4 - ${StepDialog.clickTab(DialogProduct.tabAdvancedTitle)} ${StepDialog.updateDialogValues(DialogProduct.title, updateProductShelfLife)} ${StepDialog.clickOK()}`, async () => { | 
|       await dlgProduct.pnlAdvanced.clickTab(); | 
|       await dlgProduct.updateDialogValues(updateProductShelfLife); | 
|       await dlgProduct.clickOK(); | 
|   | 
|       await appMP.resetActiveView(appMP.viewProduct); | 
|     }); | 
|   | 
|     it(`Step 5 - Open view ${appMP.viewExternalSupplies.viewPath}.`, async () => { | 
|       await appMP.viewExternalSupplies.switchTo(); | 
|     }); | 
|   | 
|     it(`Step 6 - ${StepNavigationPanel.showEntitiesList()} ${StepNavigationPanel.showProductsList()}`, async () => { | 
|       await appMP.formNavigation.toggleEntityList(true); | 
|       await appMP.formNavigation.toggleProductList(true); | 
|     }); | 
|   | 
|     it(`Step 7 - ${StepList.expandRowInList(ListEntity.title, DataFoodBaseEntityName.Europe)} ${StepList.expandRowInList(ListProduct.title, DataLowFatStrawberry12.parents)}`, async () => { | 
|       const europe = await listNavEntity.getEntityRowByName(DataFoodBaseEntityName.Europe); | 
|       await europe.expandRow(); | 
|   | 
|       await listNavProduct.expandRow({Name: DataLowFatStrawberry12.name}, DataLowFatStrawberry12.parents); | 
|     }); | 
|   | 
|     it(`Step 8 - ${StepNavigationPanel.checkStockingPoints([DataFoodBaseEntityName.DCAustria])} ${StepNavigationPanel.checkProducts([DataLowFatStrawberry12.name])}`, async () => { | 
|       const dcAustria = await listNavEntity.getEntityRowByName(DataFoodBaseEntityName.DCAustria, [DataFoodBaseEntityName.Europe]); | 
|       await listNavEntity.toggleRowCheckbox(dcAustria, true); | 
|   | 
|       const strawberry12pk = await listNavProduct.getRow({Name: DataLowFatStrawberry12.name}, DataLowFatStrawberry12.parents); | 
|       await listNavProduct.toggleRowCheckbox(strawberry12pk, true); | 
|     }); | 
|   | 
|     it(`Step 9 - ${StepList.rightClickSelectMenu(listExternalSupply.title, ListExternalSuppliesContextMenuItem.Create.Label)}`, async () => { | 
|       [dlgExternalSupply] = await listExternalSupply.selectContextMenu(ListExternalSuppliesContextMenuItem.Create); | 
|     }); | 
|   | 
|     it(`Step 10 - ${StepDialog.verifyDialogValues(DialogExternalSupply.title, defaultExtSupplyValues)}`, async () => { | 
|       await dlgExternalSupply.verifyDialogValues(defaultExtSupplyValues); | 
|     }); | 
|   | 
|     it(`Step 11 - ${StepDialog.updateDialogValues(DialogExternalSupply.title, updateExtSupplyValues)} ${StepDialog.clickOK()}`, async () => { | 
|       await dlgExternalSupply.updateDialogValues(updateExtSupplyValues); | 
|       await dlgExternalSupply.clickOK(); | 
|     }); | 
|   | 
|     it(`Step 12 - ${StepList.verifyRowExists(listExternalSupply.title, listVerifyValues)}`, async () => { | 
|       await listExternalSupply.verifyRowExists(listVerifyValues); | 
|     }); | 
|   | 
|     it(`Step 13 - ${StepList.focusListClickActionButton(listExternalSupply.title, 'Create')}`, async () => { | 
|       dlgExternalSupply = await listExternalSupply.clickActionButton(appMP.abpInventory.btnCreate); | 
|     }); | 
|   | 
|     it(`Step 14 - ${StepDialog.verifyDialogValues(DialogExternalSupply.title, defaultExtSupplyValues)} ${StepDialog.clickCancel()}`, async () => { | 
|       await dlgExternalSupply.verifyDialogValues(defaultExtSupplyValues); | 
|       await dlgExternalSupply.clickCancel(); | 
|     }); | 
|   }); | 
|   | 
|   describe('ADSO-9882 - Edit external supply', () => { | 
|     it(`Step 1 - ${StepList.selectRowAndClickMenu(listExternalSupply.title, listVerifyValues, ListExternalSuppliesContextMenuItem.Edit.Label)}`, async () => { | 
|       // Edit the created external supply in ADSO-9879 | 
|       const row = await listExternalSupply.getRow(listVerifyValues); | 
|       [dlgExternalSupply] = await listExternalSupply.selectContextMenu(ListExternalSuppliesContextMenuItem.Edit, row); | 
|     }); | 
|   | 
|     it(`Step 2 - ${StepDialog.verifyDialogValues(DialogExternalSupply.title, verifyCreatedExtSupplyValues)}`, async () => { | 
|       await dlgExternalSupply.verifyDialogValues(verifyCreatedExtSupplyValues); | 
|     }); | 
|   | 
|     it(`Step 3 - ${StepDialog.updateDialogValues(DialogExternalSupply.title, updateExtSupplyValues2)} ${StepDialog.clickOK()}`, async () => { | 
|       await dlgExternalSupply.updateDialogValues(updateExtSupplyValues2); | 
|       await dlgExternalSupply.clickOK(); | 
|     }); | 
|   | 
|     it(`Step 4 - ${StepList.verifyRowExists(listExternalSupply.title, listVerifyValues2)}`, async () => { | 
|       await listExternalSupply.verifyRowExists(listVerifyValues2); | 
|     }); | 
|   }); | 
|   | 
|   describe('ADSO-9881 - Delete external supply', () => { | 
|     it(`Step 1 - ${StepList.selectRowNumAndClickMenu(listExternalSupply.title, 1, ListExternalSuppliesContextMenuItem.Delete.Label)}`, async () => { | 
|       rowCount = await listExternalSupply.getRowCount(); | 
|   | 
|       const rowToDelete = await listExternalSupply.getRowByIndex(0); | 
|       await listExternalSupply.selectContextMenu(ListExternalSuppliesContextMenuItem.Delete, rowToDelete); | 
|     }); | 
|   | 
|     it(`Step 2 - ${StepList.verifyRowDeleted(listExternalSupply.title)}`, async () => { | 
|       await listExternalSupply.verifyTotalRow(rowCount - 1, 'Expect total row decrease by 1 as we remove the first row via list menu.'); | 
|     }); | 
|   | 
|     it(`Step 3 - ${StepList.selectRowNumAndClickActionButton(listExternalSupply.title, 1, 'Delete')}`, async () => { | 
|       await listExternalSupply.selectListRowsByIndex([0]); | 
|       await listExternalSupply.clickActionButton(appMP.abpInventory.btnDelete, undefined, await listExternalSupply.getRowByIndex(0)); | 
|     }); | 
|   | 
|     it(`Step 4 - ${StepList.verifyRowDeleted(listExternalSupply.title)}`, async () => { | 
|       await listExternalSupply.verifyTotalRow(rowCount - 2, 'Expect total row decrease by 1 as we remove the first row via action bar button.'); | 
|     }); | 
|   }); | 
| }); |