Skip to content

Commit d2d0d40

Browse files
authored
OBPIH-6701 Add test for receiving through import template (#53)
* OBPIH-6701 add test for import in receiving * OBPIH-6701 add elements to receive step * add improvements after review
1 parent 4a2b056 commit d2d0d40

2 files changed

Lines changed: 238 additions & 0 deletions

File tree

src/pages/receiving/steps/ReceivingStep.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,31 @@ class ReceivingStep extends BasePageModel {
5858
return this.page.getByRole('button').getByText('Export template');
5959
}
6060

61+
get importTemplateButton() {
62+
return this.page
63+
.locator('[class="btn btn-outline-secondary btn-xs mr-3"]')
64+
.getByText('Import template');
65+
}
66+
6167
async downloadExportTemplate() {
6268
await this.fileHandler.onDownload();
6369
await this.exportTemplateButton.click();
6470
return await this.fileHandler.saveFile();
6571
}
72+
73+
async uploadFile(path: string) {
74+
await this.fileHandler.onFileChooser();
75+
await this.importTemplateButton.click();
76+
return await this.fileHandler.uploadFile(path);
77+
}
78+
79+
get validationOnEditFieldsThroughImport() {
80+
return this.page
81+
.locator('.s-alert-box-inner')
82+
.getByText(
83+
'You can only import the Receiving Now and the Comment fields. To make other changes, please use the edit line feature. You can then export and import the template again.'
84+
);
85+
}
6686
}
6787

6888
export default ReceivingStep;
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import path from 'node:path';
2+
3+
import AppConfig from '@/config/AppConfig';
4+
import { ShipmentType } from '@/constants/ShipmentType';
5+
import { expect, test } from '@/fixtures/fixtures';
6+
import { StockMovementResponse } from '@/types';
7+
import { getDateByOffset } from '@/utils/DateUtils';
8+
import UniqueIdentifier from '@/utils/UniqueIdentifier';
9+
import { WorkbookUtils } from '@/utils/WorkbookUtils';
10+
11+
test.describe('Import receiving template', () => {
12+
let STOCK_MOVEMENT: StockMovementResponse;
13+
const uniqueIdentifier = new UniqueIdentifier();
14+
const workbooks: WorkbookUtils[] = [];
15+
const lot = uniqueIdentifier.generateUniqueString('lot');
16+
const RECEIVING_NOW_COLUMN_IDX = 11;
17+
const COMMENT_COLUMN_IDX = 12;
18+
const LOT_COLUMN_IDX = 4;
19+
20+
test.beforeEach(
21+
async ({
22+
supplierLocationService,
23+
stockMovementService,
24+
mainProductService,
25+
}) => {
26+
const supplierLocation = await supplierLocationService.getLocation();
27+
const PRODUCT_ONE = await mainProductService.getProduct();
28+
29+
STOCK_MOVEMENT = await stockMovementService.createInbound({
30+
originId: supplierLocation.id,
31+
});
32+
33+
await stockMovementService.addItemsToInboundStockMovement(
34+
STOCK_MOVEMENT.id,
35+
[
36+
{
37+
productId: PRODUCT_ONE.id,
38+
quantity: 20,
39+
lotNumber: lot,
40+
expirationDate: getDateByOffset(new Date(), 3),
41+
},
42+
]
43+
);
44+
45+
await stockMovementService.sendInboundStockMovement(STOCK_MOVEMENT.id, {
46+
shipmentType: ShipmentType.AIR,
47+
});
48+
}
49+
);
50+
51+
test.afterEach(async ({ stockMovementShowPage, stockMovementService }) => {
52+
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
53+
const isButtonVisible =
54+
await stockMovementShowPage.rollbackLastReceiptButton.isVisible();
55+
56+
// due to failed test, shipment might not be received which will not show the button
57+
if (isButtonVisible) {
58+
await stockMovementShowPage.rollbackLastReceiptButton.click();
59+
}
60+
61+
await stockMovementShowPage.rollbackButton.click();
62+
63+
await stockMovementService.deleteStockMovement(STOCK_MOVEMENT.id);
64+
65+
for (const workbook of workbooks) {
66+
workbook.delete();
67+
}
68+
});
69+
70+
test('Receive shipment using import receiving template', async ({
71+
stockMovementShowPage,
72+
receivingPage,
73+
}) => {
74+
let filePath: string;
75+
let downloadedExportTemplateFile: WorkbookUtils;
76+
77+
await test.step('Go to stock movement show page', async () => {
78+
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
79+
await stockMovementShowPage.isLoaded();
80+
});
81+
82+
await test.step('Go to receiving page', async () => {
83+
await stockMovementShowPage.receiveButton.click();
84+
await receivingPage.receivingStep.isLoaded();
85+
});
86+
87+
await test.step('Download export template', async () => {
88+
const { fullFilePath } =
89+
await receivingPage.receivingStep.downloadExportTemplate();
90+
filePath = fullFilePath;
91+
});
92+
93+
let parsedDocumentData: unknown[][];
94+
95+
await test.step('Read downloaded file', async () => {
96+
downloadedExportTemplateFile = WorkbookUtils.read(filePath);
97+
workbooks.push(downloadedExportTemplateFile);
98+
});
99+
100+
await test.step('Parse csv document to json', async () => {
101+
parsedDocumentData = downloadedExportTemplateFile.sheetToJSON();
102+
});
103+
104+
const data: unknown[][] = [];
105+
106+
await test.step('Parse downloaded template document', async () => {
107+
data.push(downloadedExportTemplateFile.getHeaders());
108+
});
109+
110+
await test.step('Input receiving now qty into template', async () => {
111+
const documentRow = parsedDocumentData[1];
112+
const row = [...documentRow];
113+
(row[RECEIVING_NOW_COLUMN_IDX] = '20'), (row[COMMENT_COLUMN_IDX] = 'e2e-comment');
114+
data.push(row);
115+
});
116+
117+
const fileName = 'modified.csv';
118+
const fullFilePath = path.join(AppConfig.LOCAL_FILES_DIR_PATH, fileName);
119+
120+
await test.step('Save file', async () => {
121+
const savedFile = WorkbookUtils.saveFile(data, fullFilePath);
122+
workbooks.push(savedFile);
123+
});
124+
125+
await test.step('Upload edited file', async () => {
126+
await receivingPage.receivingStep.uploadFile(fullFilePath);
127+
});
128+
129+
await test.step('Assert inupt values after import file', async () => {
130+
await receivingPage.receivingStep.isLoaded();
131+
await expect(
132+
receivingPage.receivingStep.table.row(1).receivingNowField.textbox
133+
).toHaveValue('20');
134+
await expect(
135+
receivingPage.receivingStep.table.row(1).commentField.textbox
136+
).toHaveValue('e2e-comment');
137+
});
138+
139+
await test.step('Go to Check page', async () => {
140+
await receivingPage.receivingStep.isLoaded();
141+
await receivingPage.nextButton.click();
142+
});
143+
144+
await test.step('Receive shipment', async () => {
145+
await receivingPage.checkStep.isLoaded();
146+
await receivingPage.checkStep.receiveShipmentButton.click();
147+
await stockMovementShowPage.isLoaded();
148+
await expect(stockMovementShowPage.statusTag).toHaveText('Received');
149+
});
150+
});
151+
152+
test('Display validation when try to edit other fields through import', async ({
153+
stockMovementShowPage,
154+
receivingPage,
155+
}) => {
156+
let filePath: string;
157+
let downloadedExportTemplateFile: WorkbookUtils;
158+
159+
await test.step('Go to stock movement show page', async () => {
160+
await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id);
161+
await stockMovementShowPage.isLoaded();
162+
});
163+
164+
await test.step('Go to receiving page', async () => {
165+
await stockMovementShowPage.receiveButton.click();
166+
await receivingPage.receivingStep.isLoaded();
167+
});
168+
169+
await test.step('Download export template', async () => {
170+
const { fullFilePath } =
171+
await receivingPage.receivingStep.downloadExportTemplate();
172+
filePath = fullFilePath;
173+
});
174+
175+
let parsedDocumentData: unknown[][];
176+
177+
await test.step('Read downloaded file', async () => {
178+
downloadedExportTemplateFile = WorkbookUtils.read(filePath);
179+
workbooks.push(downloadedExportTemplateFile);
180+
});
181+
182+
await test.step('Parse csv document to json', async () => {
183+
parsedDocumentData = downloadedExportTemplateFile.sheetToJSON();
184+
});
185+
186+
const data: unknown[][] = [];
187+
188+
await test.step('Parse downloaded template document', async () => {
189+
data.push(downloadedExportTemplateFile.getHeaders());
190+
});
191+
192+
await test.step('Input receiving now qty into template', async () => {
193+
const documentRow = parsedDocumentData[1];
194+
const row = [...documentRow];
195+
(row[LOT_COLUMN_IDX] = 'editlot'), (row[RECEIVING_NOW_COLUMN_IDX] = '20'), (row[COMMENT_COLUMN_IDX] = 'comment');
196+
data.push(row);
197+
});
198+
199+
const fileName = 'modified.csv';
200+
const fullFilePath = path.join(AppConfig.LOCAL_FILES_DIR_PATH, fileName);
201+
202+
await test.step('Save file', async () => {
203+
const savedFile = WorkbookUtils.saveFile(data, fullFilePath);
204+
workbooks.push(savedFile);
205+
});
206+
207+
await test.step('Upload edited file', async () => {
208+
await receivingPage.receivingStep.uploadFile(fullFilePath);
209+
});
210+
211+
await test.step('Assert inupt values after import file', async () => {
212+
await expect(
213+
receivingPage.receivingStep.validationOnEditFieldsThroughImport
214+
).toBeVisible();
215+
await receivingPage.receivingStep.isLoaded();
216+
});
217+
});
218+
});

0 commit comments

Comments
 (0)