/** 
 | 
 * @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(); 
 | 
  }); 
 | 
}); 
 |