/** 
 | 
 * @file         ADSO-10108 
 | 
 * @description  Non unique unit cost should not be allowed to create 
 | 
 * @testcategory Web - Financials - Units 
 | 
 * @author       Gay Er Xuan (erxuan.gay@3ds.com) 
 | 
 * @copyright    Dassault Systemes 
 | 
 */ 
 | 
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 { ListUnitCost } from '../../../libmp/forms/form.unitcost'; 
 | 
import { startOfPlanningYear } from '../../../libmp/data/data.period'; 
 | 
  
 | 
describe('ADSO-10108 - Non unique unit cost should not be allowed to create', () => { 
 | 
  const appMP = AppMP.getInstance(); 
 | 
  let listUnitCost: ListUnitCost; 
 | 
  const janSOPMinus1 = `1-Jan-${startOfPlanningYear - 1}`; 
 | 
  const janSOP = `1-Jan-${startOfPlanningYear}`; 
 | 
  
 | 
  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(`Setup - Open view ${appMP.viewUnitCost.viewPath}. Verify DE Fermenter exist`, async () => { 
 | 
    // Open Unit Costs view 
 | 
    await appMP.viewUnitCost.switchTo(); 
 | 
    // Open navigation form 
 | 
    expect(await appMP.formNavigation.isVisible()).toBe(true, 'Navigation form should be visible'); 
 | 
    await appMP.formNavigation.btnEntity.click(); 
 | 
    const listEntity = appMP.formNavigation.listEntity; 
 | 
    await listEntity.waitUntilPresent(); 
 | 
    // Select DE Fermenter 
 | 
    const row = await listEntity.getEntityRowByName('DE Fermenter', ['Europe', 'Plants', 'Denmark Plant']); 
 | 
    await row.checkboxClick(); 
 | 
    // Verify 1 DE Fermenter Unit Cost exist in the list 
 | 
    listUnitCost = appMP.viewUnitCost.frmUnitCost.listUnitCost; 
 | 
    const unitCostRow: ListRow | undefined = await listUnitCost.getUnitCostRowByValues('DE Fermenter', 'General fixed costs', 'Fixed', janSOPMinus1); 
 | 
    expect(unitCostRow).toBeDefined('One DE Fermenter Unit Cost should exist in the list'); 
 | 
  }); 
 | 
  
 | 
  it('Step 1 - Verify non unique unit cost is not allowed to create', async () => { 
 | 
    // Open create unit cost dialog 
 | 
    const dlgUnitCost = await listUnitCost.openEditDialog(); 
 | 
    // Update dialog 
 | 
    await dlgUnitCost.updateUnitCostValue('General fixed costs', 'Fixed', 'DE Fermenter', new Date(janSOPMinus1)); 
 | 
    // Verify OK button is disabled and feedback text is shown 
 | 
    expect(await dlgUnitCost.clickOK(1000)).toBe(false, 'Non unique unit cost should not be allowed to create'); 
 | 
    expect(await dlgUnitCost.getOKButtonTooltip()).toBe('Identical cost definition exists. Unit cost must be unique by Account, Cost driver and Start date.', 'Feedback text should match'); 
 | 
    // Update dialog 
 | 
    await dlgUnitCost.updateUnitCostValue('General fixed costs', 'Fixed', 'DE Fermenter', new Date(janSOP)); 
 | 
    // Verify OK button is enabled 
 | 
    expect(await dlgUnitCost.btnOk.isClickable(1000)).toBe(true, 'Unique unit cost should be allowed to create'); 
 | 
    // Cancel the dialog 
 | 
    await dlgUnitCost.clickCancel(); 
 | 
  }); 
 | 
}); 
 |