haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
 * @file        ADSO-9879 ADSO-9882 ADSO-9881
 * @description Create, edit and delete (CRUD) external supply
 * @author      Chan Clarence (ccn7@3ds.com)
 * @copyright   Dassault Systèmes
 */
import { qCustomMatcher } from '../../e2elib/lib/src/main/qmatchers.const';
import { AppMP, Demo, Scenario } from '../../libmp/appmp';
import { StepDialog } from '../../libappsop/dialogsop';
import { StepList } from '../../libappsop/listsop';
import { DialogExternalSupply, DialogExternalSupplyFields } from '../../libmp/dialogs/dialog.externalsupply';
import { DialogProduct, DialogProductFields } from '../../libmp/dialogs/dialog.product';
import { ListExternalSuppliesColumn, ListExternalSuppliesContextMenuItem } from '../../libmp/forms/form.externalsupplies';
import { ListEntity, ListProduct, StepNavigationPanel } from '../../libmp/forms/navigationpanel/form.navigationpanel';
import { ListProductContextMenuItem } from '../../libmp/forms/form.product';
import { DataFoodBaseEntityName, DataLowFatStrawberry12 } from '../../libmp/data/data.navigation';
import { startOfPlanningYear } from '../../libmp/data/data.period';
 
describe('ADSO-9879 ADSO-9882 ADSO-9881 - Create, edit and delete (CRUD) external supply', () => {
  const appMP = AppMP.getInstance();
  const listNavEntity = appMP.formNavigation.listEntity;
  const listNavProduct = appMP.formNavigation.listProduct;
  const listProduct = appMP.viewProduct.frmProduct.listProduct;
  const listExternalSupply = appMP.viewExternalSupplies.formExternalSupplies.listExternalSupplies;
  let dlgProduct: DialogProduct;
  let dlgExternalSupply: DialogExternalSupply;
  const updateProductShelfLife: DialogProductFields = { ShelfLifeEnabled: 'true', ShelfLife: '60' };
  const defaultExtSupplyValues: DialogExternalSupplyFields = { StockingPoint: DataFoodBaseEntityName.DCAustria, Product: DataLowFatStrawberry12.name };
  const updateExtSupplyValues: DialogExternalSupplyFields = { Date: `3-Feb-${startOfPlanningYear}`, ManufacturedDate: `2-Feb-${startOfPlanningYear}`, Quantity: '123' };
  const updateExtSupplyValues2: DialogExternalSupplyFields = { Date: `13-Feb-${startOfPlanningYear}`, ManufacturedDate: `12-Feb-${startOfPlanningYear}`, Quantity: '999', Description: 'Edit created external supply' };
  const verifyCreatedExtSupplyValues: DialogExternalSupplyFields = { ...defaultExtSupplyValues, ...updateExtSupplyValues }; // Combine both object values
  const listVerifyValues: ListExternalSuppliesColumn = { Date: `3-Feb-${startOfPlanningYear}`, 'Stocking point': DataFoodBaseEntityName.DCAustria, Product: DataLowFatStrawberry12.name, Quantity: '123.00' };
  const listVerifyValues2: ListExternalSuppliesColumn = { Date: `13-Feb-${startOfPlanningYear}`, 'Stocking point': DataFoodBaseEntityName.DCAustria, Product: DataLowFatStrawberry12.name, Quantity: '999.00', Description: 'Edit created external supply' };
  // Delete steps
  let rowCount = 0;
 
  beforeAll(async () => {
    jasmine.addMatchers(qCustomMatcher);
    await appMP.login();
  });
 
  afterAll(async () => {
    await appMP.formNavigation.reset();
    await appMP.resetActiveView(appMP.viewExternalSupplies);
    await appMP.cleanupAndLogout();
  });
 
  afterEach(async () => {
    await appMP.checkToastMessage();
  });
 
  describe('ADSO-9879 - Create external supply', () => {
    it(`Step 1 - ${AppMP.getDemoDataPath(Demo.Food, Scenario.Base)}`, async () => {
      await appMP.createDemoDataset(Demo.Food, Scenario.Base, false);
    });
 
    it(`Step 2 - Open view ${appMP.viewProduct.viewPath}.`, async () => {
      await appMP.viewProduct.switchTo();
    });
 
    it(`Step 3 - ${StepList.selectRowAndClickMenu(ListProduct.title, {Name: DataLowFatStrawberry12.name}, ListProductContextMenuItem.Edit.Label)}`, async () => {
      const row = await listProduct.getRow({Name: DataLowFatStrawberry12.name}, DataLowFatStrawberry12.parents);
      [dlgProduct] = await listProduct.selectContextMenu(ListProductContextMenuItem.Edit, row);
    });
 
    it(`Step 4 - ${StepDialog.clickTab(DialogProduct.tabAdvancedTitle)} ${StepDialog.updateDialogValues(DialogProduct.title, updateProductShelfLife)} ${StepDialog.clickOK()}`, async () => {
      await dlgProduct.pnlAdvanced.clickTab();
      await dlgProduct.updateDialogValues(updateProductShelfLife);
      await dlgProduct.clickOK();
 
      await appMP.resetActiveView(appMP.viewProduct);
    });
 
    it(`Step 5 - Open view ${appMP.viewExternalSupplies.viewPath}.`, async () => {
      await appMP.viewExternalSupplies.switchTo();
    });
 
    it(`Step 6 - ${StepNavigationPanel.showEntitiesList()} ${StepNavigationPanel.showProductsList()}`, async () => {
      await appMP.formNavigation.toggleEntityList(true);
      await appMP.formNavigation.toggleProductList(true);
    });
 
    it(`Step 7 - ${StepList.expandRowInList(ListEntity.title, DataFoodBaseEntityName.Europe)} ${StepList.expandRowInList(ListProduct.title, DataLowFatStrawberry12.parents)}`, async () => {
      const europe = await listNavEntity.getEntityRowByName(DataFoodBaseEntityName.Europe);
      await europe.expandRow();
 
      await listNavProduct.expandRow({Name: DataLowFatStrawberry12.name}, DataLowFatStrawberry12.parents);
    });
 
    it(`Step 8 - ${StepNavigationPanel.checkStockingPoints([DataFoodBaseEntityName.DCAustria])} ${StepNavigationPanel.checkProducts([DataLowFatStrawberry12.name])}`, async () => {
      const dcAustria = await listNavEntity.getEntityRowByName(DataFoodBaseEntityName.DCAustria, [DataFoodBaseEntityName.Europe]);
      await listNavEntity.toggleRowCheckbox(dcAustria, true);
 
      const strawberry12pk = await listNavProduct.getRow({Name: DataLowFatStrawberry12.name}, DataLowFatStrawberry12.parents);
      await listNavProduct.toggleRowCheckbox(strawberry12pk, true);
    });
 
    it(`Step 9 - ${StepList.rightClickSelectMenu(listExternalSupply.title, ListExternalSuppliesContextMenuItem.Create.Label)}`, async () => {
      [dlgExternalSupply] = await listExternalSupply.selectContextMenu(ListExternalSuppliesContextMenuItem.Create);
    });
 
    it(`Step 10 - ${StepDialog.verifyDialogValues(DialogExternalSupply.title, defaultExtSupplyValues)}`, async () => {
      await dlgExternalSupply.verifyDialogValues(defaultExtSupplyValues);
    });
 
    it(`Step 11 - ${StepDialog.updateDialogValues(DialogExternalSupply.title, updateExtSupplyValues)} ${StepDialog.clickOK()}`, async () => {
      await dlgExternalSupply.updateDialogValues(updateExtSupplyValues);
      await dlgExternalSupply.clickOK();
    });
 
    it(`Step 12 - ${StepList.verifyRowExists(listExternalSupply.title, listVerifyValues)}`, async () => {
      await listExternalSupply.verifyRowExists(listVerifyValues);
    });
 
    it(`Step 13 - ${StepList.focusListClickActionButton(listExternalSupply.title, 'Create')}`, async () => {
      dlgExternalSupply = await listExternalSupply.clickActionButton(appMP.abpInventory.btnCreate);
    });
 
    it(`Step 14 - ${StepDialog.verifyDialogValues(DialogExternalSupply.title, defaultExtSupplyValues)} ${StepDialog.clickCancel()}`, async () => {
      await dlgExternalSupply.verifyDialogValues(defaultExtSupplyValues);
      await dlgExternalSupply.clickCancel();
    });
  });
 
  describe('ADSO-9882 - Edit external supply', () => {
    it(`Step 1 - ${StepList.selectRowAndClickMenu(listExternalSupply.title, listVerifyValues, ListExternalSuppliesContextMenuItem.Edit.Label)}`, async () => {
      // Edit the created external supply in ADSO-9879
      const row = await listExternalSupply.getRow(listVerifyValues);
      [dlgExternalSupply] = await listExternalSupply.selectContextMenu(ListExternalSuppliesContextMenuItem.Edit, row);
    });
 
    it(`Step 2 - ${StepDialog.verifyDialogValues(DialogExternalSupply.title, verifyCreatedExtSupplyValues)}`, async () => {
      await dlgExternalSupply.verifyDialogValues(verifyCreatedExtSupplyValues);
    });
 
    it(`Step 3 - ${StepDialog.updateDialogValues(DialogExternalSupply.title, updateExtSupplyValues2)} ${StepDialog.clickOK()}`, async () => {
      await dlgExternalSupply.updateDialogValues(updateExtSupplyValues2);
      await dlgExternalSupply.clickOK();
    });
 
    it(`Step 4 - ${StepList.verifyRowExists(listExternalSupply.title, listVerifyValues2)}`, async () => {
      await listExternalSupply.verifyRowExists(listVerifyValues2);
    });
  });
 
  describe('ADSO-9881 - Delete external supply', () => {
    it(`Step 1 - ${StepList.selectRowNumAndClickMenu(listExternalSupply.title, 1, ListExternalSuppliesContextMenuItem.Delete.Label)}`, async () => {
      rowCount = await listExternalSupply.getRowCount();
 
      const rowToDelete = await listExternalSupply.getRowByIndex(0);
      await listExternalSupply.selectContextMenu(ListExternalSuppliesContextMenuItem.Delete, rowToDelete);
    });
 
    it(`Step 2 - ${StepList.verifyRowDeleted(listExternalSupply.title)}`, async () => {
      await listExternalSupply.verifyTotalRow(rowCount - 1, 'Expect total row decrease by 1 as we remove the first row via list menu.');
    });
 
    it(`Step 3 - ${StepList.selectRowNumAndClickActionButton(listExternalSupply.title, 1, 'Delete')}`, async () => {
      await listExternalSupply.selectListRowsByIndex([0]);
      await listExternalSupply.clickActionButton(appMP.abpInventory.btnDelete, undefined, await listExternalSupply.getRowByIndex(0));
    });
 
    it(`Step 4 - ${StepList.verifyRowDeleted(listExternalSupply.title)}`, async () => {
      await listExternalSupply.verifyTotalRow(rowCount - 2, 'Expect total row decrease by 1 as we remove the first row via action bar button.');
    });
  });
});