| /** | 
|  * @file        ADSO-9541 | 
|  * @description Create new currency rate | 
|  * @author      Tai Zan Sen (zansen.tai@3ds.com) | 
|  * @copyright   Dassault Systèmes | 
|  */ | 
| import { AppMP, Demo, Scenario } from '../../libmp/appmp'; | 
| import { qCustomMatcher } from '../../e2elib/lib/src/main/qmatchers.const'; | 
| import { DialogCurrencyRate, okButtonDisabledTooltip } from '../../libmp/dialogs/dialog.currencyrate'; | 
| import { ListCurrencyRateContextMenuItem } from '../../libmp/forms/form.currencyrate'; | 
| import { ChartCurrencyRates } from '../../libmp/forms/form.currencyratechart'; | 
| import { DataFoodBaseCurrency } from '../../libmp/data/data.currency'; | 
| import { UtilSOP } from '../../libappsop/utilsop'; | 
|   | 
| describe('ADSO-9541 - Create new currency rate via context menu in currency list and action bar Create button', () => { | 
|   const appMP = AppMP.getInstance(); | 
|   | 
|   // Test data for currency rate start date | 
|   const today = new Date(Date.now()); | 
|   const april14th = `14-Apr-${today.getFullYear()}`; | 
|   const euro = DataFoodBaseCurrency.Euro; | 
|   const rmb = DataFoodBaseCurrency.RMB; | 
|   let dlgCurrencyRate: DialogCurrencyRate; | 
|   | 
|   beforeAll(async () => { | 
|     jasmine.addMatchers(qCustomMatcher); | 
|     await appMP.login(); | 
|   }); | 
|   | 
|   afterAll(async () => { | 
|     await appMP.viewCurrency.reset(); | 
|     await appMP.cleanupAndLogout(); | 
|   }); | 
|   | 
|   afterEach(async () => { | 
|     await appMP.checkToastMessage(); | 
|   }); | 
|   | 
|   it(`Step 1 - ${AppMP.getDemoDataPath(Demo.Food, Scenario.Base)}`, async () => { | 
|     await appMP.createDemoDataset(Demo.Food, Scenario.Base, false); | 
|   }); | 
|   | 
|   it(`Step 2 - Open view ${appMP.viewCurrency.viewPath}.`, async () => { | 
|     await appMP.viewCurrency.switchTo(); | 
|   }); | 
|   | 
|   it('Step 3 - Select RMB currency, right click context menu to Create', async () => { | 
|     await appMP.viewCurrency.formCurrency.listCurrency.selectRow({Name: rmb}); | 
|     [dlgCurrencyRate] = await appMP.viewCurrency.formCurrencyRate.listCurrencyRate.selectContextMenu(ListCurrencyRateContextMenuItem.Create); | 
|   }); | 
|   | 
|   it('Step 4 - In Currency rate dialog, verify by default currency = RMB, Start = today date, Rate = 0 and OK button disabled as Rate must be greater than 0', async () => { | 
|     const expectedLabelRate = dlgCurrencyRate.getLabelRateFormat(euro, rmb); | 
|     await dlgCurrencyRate.verifyDialogValues({Currency: rmb, Start: UtilSOP.getDateString(today), Rate: '0', RateLabel: expectedLabelRate}); | 
|     await dlgCurrencyRate.verifyOKDisabled(okButtonDisabledTooltip.partialRateMustGreaterZero('0')); | 
|   }); | 
|   | 
|   it('Step 5 - Enter Rate = 0.567. Verify rate label shows "Euro to 1 RMB", and OK button is enabled', async () => { | 
|     await dlgCurrencyRate.updateDialogValues({ Rate: '0.567' }); | 
|   | 
|     const expectedLabelRate = dlgCurrencyRate.getLabelRateFormat(euro, rmb); | 
|     await dlgCurrencyRate.verifyDialogValues({RateLabel: expectedLabelRate}); | 
|     await dlgCurrencyRate.verifyOKEnabled(); | 
|   }); | 
|   | 
|   it('Step 6 - Update Start = 14-Apr-SOP and click OK to save. Verify currency rate is created in list. Verify currency rate shown in chart.', async () => { | 
|     await dlgCurrencyRate.updateDialogValues({Start: april14th }); | 
|     await dlgCurrencyRate.clickOK(); | 
|     await appMP.viewCurrency.formCurrencyRate.listCurrencyRate.verifyRowExists({Start: april14th, Rate: '0.5670'}); | 
|   | 
|     // Verify rate shown correctly in chart | 
|     await appMP.viewCurrency.formCurrencyRateChart.chartCurrencyRate.verifyHasDataPoint(ChartCurrencyRates.LegendGroupName, rmb, april14th, '0.567'); | 
|   }); | 
|   | 
|   it(`Step 7 - Click Create action bar button and enter values in dialog as: currency = RMB, start = 14-April-SOP, rate = 0.568. | 
|       Verify OK disabled as currency rate must be unique by Currency and Start.`, async () => { | 
|     dlgCurrencyRate = await appMP.viewCurrency.formCurrencyRate.listCurrencyRate.clickActionButton(appMP.abpData.btnCreate); | 
|     await dlgCurrencyRate.updateDialogValues({ Currency: rmb, Start: april14th, Rate: '0.568' }); | 
|     await dlgCurrencyRate.verifyOKDisabled(okButtonDisabledTooltip.partialRateMustUnique()); | 
|   }); | 
|   | 
|   it('Step 8 - Click Cancel to dismiss dialog', async () => { | 
|     await dlgCurrencyRate.clickCancel(); | 
|   }); | 
| }); |