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
/**
 * @file        ADSO-9505, ADSO-9510
 * @description Edit edit weight of active goal
 * @author      Gay Er Xuan (erxuan.gay@3ds.com)
 * @copyright   Dassault Systèmes
 */
import { qCustomMatcher } from '../../e2elib/lib/src/main/qmatchers.const';
import { AppMP, Demo, Scenario } from '../../libmp/appmp';
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component';
import { DialogStrategy, ListActiveGoals, ListActiveGoalsContextMenuItem } from '../../libmp/dialogs/dialog.strategy';
import { DataFoodStrategyName } from '../../libmp/data/data.strategy';
import { ListStrategyContextMenuItem } from '../../libmp/forms/form.optimizerstrategies';
 
describe('ADSO-9505, ADSO-9510 - Edit weight of active goal', () => {
  const appMP = AppMP.getInstance();
  let initialWeight: string;
  let strategyDialog: DialogStrategy;
  let listActiveGoal: ListActiveGoals;
  let firstActiveGoalRow: ListRow;
  const listStrategy = appMP.viewOptimizerStrategies.frmOptimizerStrategies.listStrategy;
  let listActiveGoalColumnWeight: string;
 
  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(`Initialize - Open view ${appMP.viewOptimizerStrategies.viewPath}. Take note initial weight of first active goal`, async () => {
    await appMP.viewOptimizerStrategies.switchTo();
    // Edit strategy and get first active goal
    const defaultStrategyRow = await listStrategy.getRow({Name: DataFoodStrategyName.Default});
    [strategyDialog] = await listStrategy.selectContextMenu(ListStrategyContextMenuItem.Edit, defaultStrategyRow);
    listActiveGoal = strategyDialog.listActiveGoals;
    firstActiveGoalRow = await listActiveGoal.getRowByIndex(0);
    // Record weight
    listActiveGoalColumnWeight = listActiveGoal.extractColumnName({Weight: ''});
    initialWeight = await listActiveGoal.getCellValueFromRow(listActiveGoalColumnWeight, firstActiveGoalRow);
  });
 
  it('ADSO-9505 - Edit active goal with negative weight', async () => {
    const [dlgGoal] = await listActiveGoal.selectContextMenu(ListActiveGoalsContextMenuItem.Edit, firstActiveGoalRow);
    await dlgGoal.updateDialogValues({Weight: '-1'});
    await dlgGoal.verifyOKDisabled();
    await dlgGoal.clickCancel();
  });
 
  it('ADSO-9510 - Increase weight of an active goal', async () => {
    // Record weight before increase
    const previousWeight = await listActiveGoal.getCellValueFromRow(listActiveGoalColumnWeight, firstActiveGoalRow);
    // Increase the weight by 1 using Increase weight context menu
    await listActiveGoal.selectContextMenu(ListActiveGoalsContextMenuItem.IncreaseWeight, firstActiveGoalRow);
    // Record weight after increase
    const afterWeight = await listActiveGoal.getCellValueFromRow(listActiveGoalColumnWeight, firstActiveGoalRow);
    expect(Number(afterWeight)).toBe(Number(previousWeight) + 1, 'Goal weight should be increased by 1');
  });
 
  it('Finalize - Reset weight of the active goal', async () => {
    // Reset weight to initial value
    const [dlgGoal] = await listActiveGoal.selectContextMenu(ListActiveGoalsContextMenuItem.Edit, firstActiveGoalRow);
    await dlgGoal.updateDialogValues({Weight: initialWeight});
    await dlgGoal.clickOK();
 
    const finalWeight = await listActiveGoal.getCellValueFromRow(listActiveGoalColumnWeight, firstActiveGoalRow);
    expect(finalWeight).toBe(initialWeight, 'Goal weight should be reset back to initial value');
 
    // Dismiss the strategy dialog
    await strategyDialog.clickCancel();
  });
});