|
| 1 | +import { expect, test } from '@/fixtures/fixtures'; |
| 2 | +import { StockMovementResponse, User } from '@/types'; |
| 3 | +import { formatDate, getDateByOffset } from '@/utils/DateUtils'; |
| 4 | + |
| 5 | +test.describe('Expected delivery date tests', () => { |
| 6 | + let STOCK_MOVEMENT: StockMovementResponse; |
| 7 | + let USER: User; |
| 8 | + const SHIPMENT_TYPE = 'Air'; |
| 9 | + |
| 10 | + test.beforeEach( |
| 11 | + async ({ |
| 12 | + supplierLocationService, |
| 13 | + mainUserService, |
| 14 | + stockMovementService, |
| 15 | + thirdProductService, |
| 16 | + fourthProductService, |
| 17 | + }) => { |
| 18 | + const supplierLocation = await supplierLocationService.getLocation(); |
| 19 | + USER = await mainUserService.getUser(); |
| 20 | + const PRODUCT_THREE = await thirdProductService.getProduct(); |
| 21 | + const PRODUCT_FOUR = await fourthProductService.getProduct(); |
| 22 | + |
| 23 | + STOCK_MOVEMENT = await stockMovementService.createInbound({ |
| 24 | + originId: supplierLocation.id, |
| 25 | + }); |
| 26 | + |
| 27 | + await stockMovementService.addItemsToInboundStockMovement( |
| 28 | + STOCK_MOVEMENT.id, |
| 29 | + [ |
| 30 | + { productId: PRODUCT_THREE.id, quantity: 50 }, |
| 31 | + { productId: PRODUCT_FOUR.id, quantity: 200 }, |
| 32 | + ] |
| 33 | + ); |
| 34 | + } |
| 35 | + ); |
| 36 | + |
| 37 | + test.afterEach(async ({ stockMovementShowPage, stockMovementService }) => { |
| 38 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 39 | + const isRollbackButtonVisible = |
| 40 | + await stockMovementShowPage.rollbackButton.isVisible(); |
| 41 | + if (isRollbackButtonVisible) { |
| 42 | + await stockMovementShowPage.rollbackButton.click(); |
| 43 | + } |
| 44 | + await stockMovementService.deleteStockMovement(STOCK_MOVEMENT.id); |
| 45 | + }); |
| 46 | + |
| 47 | + test('Leave exp delivery date empty and assert dialog when go backward', async ({ |
| 48 | + stockMovementShowPage, |
| 49 | + createInboundPage, |
| 50 | + }) => { |
| 51 | + await test.step('Go to stock movement show page', async () => { |
| 52 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 53 | + await stockMovementShowPage.isLoaded(); |
| 54 | + }); |
| 55 | + |
| 56 | + await test.step('Go backward when exp delivey date empty, accept dialog', async () => { |
| 57 | + await stockMovementShowPage.editButton.click(); |
| 58 | + await createInboundPage.sendStep.isLoaded(); |
| 59 | + await createInboundPage.previousButton.click(); |
| 60 | + await createInboundPage.sendStep.validationPopup.assertPopupVisible(); |
| 61 | + await createInboundPage.sendStep.validationPopup.confirmButton.click(); |
| 62 | + await createInboundPage.addItemsStep.isLoaded(); |
| 63 | + }); |
| 64 | + |
| 65 | + await test.step('Go to stock send page', async () => { |
| 66 | + await createInboundPage.nextButton.click(); |
| 67 | + await createInboundPage.sendStep.isLoaded(); |
| 68 | + }); |
| 69 | + |
| 70 | + await test.step('Go backward when exp delivey date empty, cancel dialog', async () => { |
| 71 | + await createInboundPage.previousButton.click(); |
| 72 | + await createInboundPage.sendStep.validationPopup.assertPopupVisible(); |
| 73 | + await createInboundPage.sendStep.validationPopup.cancelButton.click(); |
| 74 | + await createInboundPage.sendStep.isLoaded(); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + test('Leave exp delivery date empty and assert dialog when save and exit', async ({ |
| 79 | + stockMovementShowPage, |
| 80 | + createInboundPage, |
| 81 | + }) => { |
| 82 | + await test.step('Go to stock movement show page', async () => { |
| 83 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 84 | + await stockMovementShowPage.isLoaded(); |
| 85 | + }); |
| 86 | + |
| 87 | + await test.step('Save and exit when exp delivey date empty, cancel', async () => { |
| 88 | + await stockMovementShowPage.editButton.click(); |
| 89 | + await createInboundPage.sendStep.isLoaded(); |
| 90 | + await createInboundPage.sendStep.saveAndExitButton.click(); |
| 91 | + await createInboundPage.sendStep.validationPopup.assertPopupVisible(); |
| 92 | + await createInboundPage.sendStep.validationPopup.noButton.click(); |
| 93 | + await createInboundPage.sendStep.isLoaded(); |
| 94 | + }); |
| 95 | + |
| 96 | + await test.step('Save and exit when exp delivey date empty, accept dialog', async () => { |
| 97 | + await createInboundPage.sendStep.saveAndExitButton.click(); |
| 98 | + await createInboundPage.sendStep.validationPopup.assertPopupVisible(); |
| 99 | + await createInboundPage.sendStep.validationPopup.yesButton.click(); |
| 100 | + await stockMovementShowPage.isLoaded(); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + test('Set ship date and expected delivery date to past values', async ({ |
| 105 | + stockMovementShowPage, |
| 106 | + createInboundPage, |
| 107 | + inboundListPage, |
| 108 | + }) => { |
| 109 | + await test.step('Go to stock movement show page', async () => { |
| 110 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 111 | + await stockMovementShowPage.isLoaded(); |
| 112 | + }); |
| 113 | + |
| 114 | + await test.step('Set ship date and exp delivery date to past values', async () => { |
| 115 | + await stockMovementShowPage.editButton.click(); |
| 116 | + await createInboundPage.sendStep.isLoaded(); |
| 117 | + await createInboundPage.sendStep.expectedDeliveryDatePicker.fillWithFormat( |
| 118 | + getDateByOffset(new Date(), -1), |
| 119 | + 'MM/DD/YYYY' |
| 120 | + ); |
| 121 | + await createInboundPage.sendStep.shipDateDatePicker.fillWithFormat( |
| 122 | + getDateByOffset(new Date(), -2), |
| 123 | + 'MM/DD/YYYY HH:mm:ss Z' |
| 124 | + ); |
| 125 | + await createInboundPage.sendStep.shipmentTypeSelect.findAndSelectOption( |
| 126 | + SHIPMENT_TYPE |
| 127 | + ); |
| 128 | + }); |
| 129 | + |
| 130 | + await test.step('Send stock stock movement', async () => { |
| 131 | + await createInboundPage.sendStep.sendShipmentButton.click(); |
| 132 | + await stockMovementShowPage.isLoaded(); |
| 133 | + }); |
| 134 | + |
| 135 | + await test.step('Assert date shipped on stock movement view page', async () => { |
| 136 | + await expect( |
| 137 | + stockMovementShowPage.auditingTable.dateShippedRow |
| 138 | + ).toContainText( |
| 139 | + `${formatDate(getDateByOffset(new Date(), -2), 'DD/MMM/YYYY')} by ${USER.name}` |
| 140 | + ); |
| 141 | + }); |
| 142 | + |
| 143 | + await test.step('Go to list page and assert date created', async () => { |
| 144 | + const inboundShipmentIdentifier = |
| 145 | + await stockMovementShowPage.detailsListTable.identifierValue.textContent(); |
| 146 | + await inboundListPage.goToPage(); |
| 147 | + await inboundListPage.filters.searchField.textbox.fill( |
| 148 | + `${inboundShipmentIdentifier}`.toString().trim() |
| 149 | + ); |
| 150 | + await inboundListPage.search(); |
| 151 | + await expect(inboundListPage.table.row(0).dateCreated).toContainText( |
| 152 | + `${formatDate(new Date(), 'MMM DD, YYYY')}` |
| 153 | + ); |
| 154 | + }); |
| 155 | + |
| 156 | + await test.step('Assert expected delivery date on list page', async () => { |
| 157 | + await expect( |
| 158 | + inboundListPage.table.row(0).expectedReceiptDate |
| 159 | + ).toContainText( |
| 160 | + `${formatDate(getDateByOffset(new Date(), -1), 'MMM DD, YYYY')}` |
| 161 | + ); |
| 162 | + }); |
| 163 | + }); |
| 164 | + |
| 165 | + test('Edit expected devlivery date in shipped inbound', async ({ |
| 166 | + stockMovementShowPage, |
| 167 | + createInboundPage, |
| 168 | + inboundListPage, |
| 169 | + }) => { |
| 170 | + await test.step('Go to stock movement show page', async () => { |
| 171 | + await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); |
| 172 | + await stockMovementShowPage.isLoaded(); |
| 173 | + }); |
| 174 | + |
| 175 | + await test.step('Set exp delivery date and send shipment', async () => { |
| 176 | + await stockMovementShowPage.editButton.click(); |
| 177 | + await createInboundPage.sendStep.isLoaded(); |
| 178 | + await createInboundPage.sendStep.expectedDeliveryDatePicker.fillWithFormat( |
| 179 | + getDateByOffset(new Date(), 1), |
| 180 | + 'MM/DD/YYYY' |
| 181 | + ); |
| 182 | + await createInboundPage.sendStep.shipmentTypeSelect.findAndSelectOption( |
| 183 | + SHIPMENT_TYPE |
| 184 | + ); |
| 185 | + await createInboundPage.sendStep.sendShipmentButton.click(); |
| 186 | + await stockMovementShowPage.isLoaded(); |
| 187 | + }); |
| 188 | + |
| 189 | + await test.step('Update expected delivery date in shipped sm', async () => { |
| 190 | + await stockMovementShowPage.editButton.click(); |
| 191 | + await createInboundPage.sendStep.isLoaded(); |
| 192 | + await createInboundPage.sendStep.expectedDeliveryDatePicker.fillWithFormat( |
| 193 | + getDateByOffset(new Date(), 2), |
| 194 | + 'MM/DD/YYYY' |
| 195 | + ); |
| 196 | + await createInboundPage.sendStep.saveAndExitButton.click(); |
| 197 | + }); |
| 198 | + |
| 199 | + await test.step('Go to list page and use enter on search bar', async () => { |
| 200 | + const inboundShipmentIdentifier = |
| 201 | + await stockMovementShowPage.detailsListTable.identifierValue.textContent(); |
| 202 | + await inboundListPage.goToPage(); |
| 203 | + await inboundListPage.filters.searchField.textbox.fill( |
| 204 | + `${inboundShipmentIdentifier}`.toString().trim() |
| 205 | + ); |
| 206 | + await inboundListPage.filters.searchField.textbox.press('Enter'); |
| 207 | + }); |
| 208 | + |
| 209 | + await test.step('Assert updated exp delivery date', async () => { |
| 210 | + await expect( |
| 211 | + inboundListPage.table.row(0).expectedReceiptDate |
| 212 | + ).toContainText( |
| 213 | + `${formatDate(getDateByOffset(new Date(), 2), 'MMM DD, YYYY')}` |
| 214 | + ); |
| 215 | + }); |
| 216 | + }); |
| 217 | +}); |
0 commit comments