|
| 1 | +import { ShipmentType } from '@/constants/ShipmentType'; |
| 2 | +import { expect, test } from '@/fixtures/fixtures'; |
| 3 | +import { StockMovementResponse } from '@/types'; |
| 4 | + |
| 5 | +test.describe('Assert recipient field when receive', () => { |
| 6 | + let STOCK_MOVEMENT: StockMovementResponse; |
| 7 | + |
| 8 | + test.beforeEach( |
| 9 | + async ({ |
| 10 | + supplierLocationService, |
| 11 | + stockMovementService, |
| 12 | + fourthProductService, |
| 13 | + fifthProductService, |
| 14 | + mainUserService, |
| 15 | + }) => { |
| 16 | + const supplierLocation = await supplierLocationService.getLocation(); |
| 17 | + const PRODUCT_FOUR = await fourthProductService.getProduct(); |
| 18 | + const PRODUCT_FIVE = await fifthProductService.getProduct(); |
| 19 | + const USER = await mainUserService.getUser(); |
| 20 | + |
| 21 | + STOCK_MOVEMENT = await stockMovementService.createInbound({ |
| 22 | + originId: supplierLocation.id, |
| 23 | + }); |
| 24 | + |
| 25 | + await stockMovementService.addItemsToInboundStockMovement( |
| 26 | + STOCK_MOVEMENT.id, |
| 27 | + [ |
| 28 | + { |
| 29 | + productId: PRODUCT_FOUR.id, |
| 30 | + quantity: 10, |
| 31 | + recipientId: USER.id, |
| 32 | + }, |
| 33 | + { |
| 34 | + productId: PRODUCT_FIVE.id, |
| 35 | + quantity: 10, |
| 36 | + }, |
| 37 | + ] |
| 38 | + ); |
| 39 | + |
| 40 | + await stockMovementService.sendInboundStockMovement(STOCK_MOVEMENT.id, { |
| 41 | + shipmentType: ShipmentType.AIR, |
| 42 | + }); |
| 43 | + } |
| 44 | + ); |
| 45 | + |
| 46 | + test.afterEach(async ({ stockMovementShowPage, stockMovementService }) => { |
| 47 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 48 | + const isRollbackLastReceiptButtonVisible = |
| 49 | + await stockMovementShowPage.rollbackLastReceiptButton.isVisible(); |
| 50 | + const isRollbackButtonVisible = |
| 51 | + await stockMovementShowPage.rollbackButton.isVisible(); |
| 52 | + |
| 53 | + // due to failed test, shipment might not be received which will not show the button |
| 54 | + if (isRollbackLastReceiptButtonVisible) { |
| 55 | + await stockMovementShowPage.rollbackLastReceiptButton.click(); |
| 56 | + } |
| 57 | + |
| 58 | + if (isRollbackButtonVisible) { |
| 59 | + await stockMovementShowPage.rollbackButton.click(); |
| 60 | + } |
| 61 | + |
| 62 | + await stockMovementService.deleteStockMovement(STOCK_MOVEMENT.id); |
| 63 | + }); |
| 64 | + |
| 65 | + test('Assert recipient field filled and disabled', async ({ |
| 66 | + stockMovementShowPage, |
| 67 | + receivingPage, |
| 68 | + mainUserService, |
| 69 | + }) => { |
| 70 | + await test.step('Go to stock movement show page', async () => { |
| 71 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 72 | + await stockMovementShowPage.isLoaded(); |
| 73 | + }); |
| 74 | + |
| 75 | + await test.step('Go to shipment receiving page', async () => { |
| 76 | + await stockMovementShowPage.receiveButton.click(); |
| 77 | + await receivingPage.receivingStep.isLoaded(); |
| 78 | + }); |
| 79 | + |
| 80 | + await test.step('Assert recipient field disabled and filled', async () => { |
| 81 | + const USER = await mainUserService.getUser(); |
| 82 | + await expect( |
| 83 | + receivingPage.receivingStep.table.getCellValue(1, 'Recipient') |
| 84 | + ).toBeEmpty(); |
| 85 | + await receivingPage.receivingStep.table |
| 86 | + .row(1) |
| 87 | + .recipientField.isDisabled(); |
| 88 | + await expect( |
| 89 | + receivingPage.receivingStep.table.getCellValue(2, 'Recipient') |
| 90 | + ).toHaveText(USER.name); |
| 91 | + await receivingPage.receivingStep.table.row(2).recipientField.click(); |
| 92 | + await receivingPage.receivingStep.table |
| 93 | + .row(2) |
| 94 | + .recipientField.getByTestId('custom-select-dropdown-menu') |
| 95 | + .isHidden(); |
| 96 | + }); |
| 97 | + |
| 98 | + await test.step('Fill partial qty for items', async () => { |
| 99 | + await receivingPage.receivingStep.table |
| 100 | + .row(1) |
| 101 | + .receivingNowField.textbox.fill('5'); |
| 102 | + await receivingPage.receivingStep.table |
| 103 | + .row(2) |
| 104 | + .receivingNowField.textbox.fill('5'); |
| 105 | + await receivingPage.nextButton.click(); |
| 106 | + await receivingPage.checkStep.isLoaded(); |
| 107 | + }); |
| 108 | + |
| 109 | + await test.step('Fill partial qty for items', async () => { |
| 110 | + const USER = await mainUserService.getUser(); |
| 111 | + await receivingPage.checkStep.isLoaded(); |
| 112 | + await expect( |
| 113 | + receivingPage.checkStep.table.getCellValue(1, 'Recipient') |
| 114 | + ).toBeEmpty(); |
| 115 | + await expect( |
| 116 | + receivingPage.checkStep.table.getCellValue(2, 'Recipient') |
| 117 | + ).toHaveText(USER.name); |
| 118 | + }); |
| 119 | + |
| 120 | + await test.step('Go backward and assert recipient field', async () => { |
| 121 | + const USER = await mainUserService.getUser(); |
| 122 | + await receivingPage.checkStep.backToEditButton.click(); |
| 123 | + await receivingPage.receivingStep.isLoaded(); |
| 124 | + await expect( |
| 125 | + receivingPage.receivingStep.table.getCellValue(1, 'Recipient') |
| 126 | + ).toBeEmpty(); |
| 127 | + await receivingPage.receivingStep.table |
| 128 | + .row(1) |
| 129 | + .recipientField.isDisabled(); |
| 130 | + await expect( |
| 131 | + receivingPage.receivingStep.table.getCellValue(2, 'Recipient') |
| 132 | + ).toHaveText(USER.name); |
| 133 | + await receivingPage.receivingStep.table.row(2).recipientField.click(); |
| 134 | + await receivingPage.receivingStep.table |
| 135 | + .row(2) |
| 136 | + .recipientField.getByTestId('custom-select-dropdown-menu') |
| 137 | + .isHidden(); |
| 138 | + }); |
| 139 | + |
| 140 | + await test.step('Finish 1st receipt', async () => { |
| 141 | + await receivingPage.nextButton.click(); |
| 142 | + await receivingPage.checkStep.isLoaded(); |
| 143 | + await receivingPage.checkStep.receiveShipmentButton.click(); |
| 144 | + await stockMovementShowPage.isLoaded(); |
| 145 | + }); |
| 146 | + |
| 147 | + await test.step('Start 2nd receipt and assert recipient field', async () => { |
| 148 | + const USER = await mainUserService.getUser(); |
| 149 | + await stockMovementShowPage.receiveButton.click(); |
| 150 | + await receivingPage.receivingStep.isLoaded(); |
| 151 | + await expect( |
| 152 | + receivingPage.receivingStep.table.getCellValue(1, 'Recipient') |
| 153 | + ).toBeEmpty(); |
| 154 | + await receivingPage.receivingStep.table |
| 155 | + .row(1) |
| 156 | + .recipientField.isDisabled(); |
| 157 | + await expect( |
| 158 | + receivingPage.receivingStep.table.getCellValue(2, 'Recipient') |
| 159 | + ).toHaveText(USER.name); |
| 160 | + await receivingPage.receivingStep.table.row(2).recipientField.click(); |
| 161 | + await receivingPage.receivingStep.table |
| 162 | + .row(2) |
| 163 | + .recipientField.getByTestId('custom-select-dropdown-menu') |
| 164 | + .isHidden(); |
| 165 | + }); |
| 166 | + }); |
| 167 | +}); |
0 commit comments