| /** | 
|  * @file        ADSO-9497 | 
|  * @description Copy strategy in Optimizer strategies view | 
|  * @author      Mehrab Kamrani (mehrab.hassan@3ds.com) | 
|  * @copyright   Dassault Systèmes | 
|  */ | 
| import { qCustomMatcher } from '../../e2elib/lib/src/main/qmatchers.const'; | 
| import { AppMP, Demo, Scenario } from '../../libmp/appmp'; | 
| import { DataFoodStrategyName } from '../../libmp/data/data.strategy'; | 
| import { ListStrategyContextMenuItem } from '../../libmp/forms/form.optimizerstrategies'; | 
|   | 
| describe('ADSO-9497 - Copy a strategy via context menu in strategy list and action bar Copy button', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   const listStrategy = appMP.viewOptimizerStrategies.frmOptimizerStrategies.listStrategy; | 
|   | 
|   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(`Step 1 - Open view ${appMP.viewOptimizerStrategies.viewPath} and via context menu on Strategies list copy a strategy`, async () => { | 
|     await appMP.viewOptimizerStrategies.switchTo(); | 
|   | 
|     const originalStrategyName = DataFoodStrategyName.Default; | 
|   | 
|     // Edit the default strategy and remember the active goals | 
|     const originalStrategyRow = await listStrategy.getRow({Name: originalStrategyName}); | 
|     let [strategyDialog] = await listStrategy.selectContextMenu(ListStrategyContextMenuItem.Edit, originalStrategyRow); | 
|     const originalStrategyActiveGoals = await strategyDialog.listActiveGoals.getActiveGoals(); | 
|     await strategyDialog.clickCancel(); | 
|   | 
|     // Copy strategy via context menu | 
|     await listStrategy.selectContextMenu(ListStrategyContextMenuItem.Copy, originalStrategyRow); | 
|   | 
|     // Validate that a copy of the original strategy is made and has a different name | 
|     const copiedStrategyName = listStrategy.getCopiedStrategyName(originalStrategyName); | 
|     await listStrategy.verifyRowExists({Name: copiedStrategyName}); | 
|   | 
|     // Remember active goals for copied strategy | 
|     const copiedStrategyRow = await listStrategy.getRow({Name: copiedStrategyName}); | 
|     [strategyDialog] = await listStrategy.selectContextMenu(ListStrategyContextMenuItem.Edit, copiedStrategyRow); | 
|     const copiedStrategyActiveGoals = await strategyDialog.listActiveGoals.getActiveGoals(); | 
|     await strategyDialog.clickCancel(); | 
|   | 
|     // Verify both original and copied scenarios has same Active Goal | 
|     const isBothIdentical = JSON.stringify(originalStrategyActiveGoals) === JSON.stringify(copiedStrategyActiveGoals); | 
|     expect(isBothIdentical).toBe(true, 'Both original and copied scenario should have same active goals'); | 
|   }); | 
|   | 
|   it('Step 2 - Select 2 optimizer strategies. Verify Copy context menu and action bar button disabled as batch copy not supported.', async () => { | 
|     // select multiple rows | 
|     const rows = [await listStrategy.getRowByIndex(0), await listStrategy.getRowByIndex(1)]; | 
|   | 
|     // verify Copy context menu is disabled | 
|     await listStrategy.verifyContextMenuDisabled(ListStrategyContextMenuItem.Copy, rows, 'Expecting Copy menu to be disabled as not supporting batch copy optimizer strategies.'); | 
|   | 
|     // Verify Copy button in scenario action bar page is disabled | 
|     expect(await appMP.abpScenario.btnCopy.isDisabled()).toBe(true, 'Expecting Copy button to be disabled as not supporting batch copy optimizer strategies.'); | 
|   }); | 
|   | 
|   it('Step 3 - Repeat test using action bar Copy button', async () => { | 
|     // Get "Default - Changeovers" strategy | 
|     const originalStrategyName = DataFoodStrategyName.DefaultChangeovers; | 
|     const originalStrategyRow = await listStrategy.selectRow({Name: originalStrategyName}); | 
|   | 
|     // Remember active goals of original strategy | 
|     let [strategyDialog] = await listStrategy.selectContextMenu(ListStrategyContextMenuItem.Edit, originalStrategyRow); | 
|     const originalStrategyActiveGoals = await strategyDialog.listActiveGoals.getActiveGoals(); | 
|     await strategyDialog.clickCancel(); | 
|   | 
|     // Copy strategy via copy button in action bar page | 
|     await listStrategy.clickActionButton(appMP.abpScenario.btnCopy); | 
|   | 
|     // Validate that a copy of the original strategy is made and has a different name | 
|     const copiedStrategyName = listStrategy.getCopiedStrategyName(originalStrategyName); | 
|     await listStrategy.verifyRowExists({Name: copiedStrategyName}); | 
|   | 
|     // Remember active goals for copied strategy | 
|     const copiedStrategyRow = await listStrategy.getRow({Name: copiedStrategyName}); | 
|     [strategyDialog] = await listStrategy.selectContextMenu(ListStrategyContextMenuItem.Edit, copiedStrategyRow); | 
|     const copiedStrategyActiveGoals = await strategyDialog.listActiveGoals.getActiveGoals(); | 
|     await strategyDialog.clickCancel(); | 
|   | 
|     // Verify both original and copied scenarios has same Active Goal | 
|     const isBothIdentical = JSON.stringify(originalStrategyActiveGoals) === JSON.stringify(copiedStrategyActiveGoals); | 
|     expect(isBothIdentical).toBe(true, 'Both original and copied scenario should have same active goals'); | 
|   }); | 
| }); |