yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
 * @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');
  });
});