|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace acceptance; |
| 6 | + |
| 7 | +use AcceptanceTester; |
| 8 | +use Facebook\WebDriver\WebDriverKeys; |
| 9 | +use Throwable; |
| 10 | + |
| 11 | +use function json_encode; |
| 12 | +use function sprintf; |
| 13 | +use function time; |
| 14 | + |
| 15 | +// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 16 | +class TravelCest extends BaseAcceptanceCest |
| 17 | +{ |
| 18 | + protected AcceptanceTester $I; |
| 19 | + |
| 20 | + // Test data |
| 21 | + protected string $vehicleType = 'Osobní'; |
| 22 | + protected string $licensePlate; |
| 23 | + protected string $harmonizedConsumption = '5.8'; |
| 24 | + protected string $division = '621.66.014 - Frantův oddíl'; |
| 25 | + protected string $unitRepresentative = 'Karel Vedoucí'; |
| 26 | + |
| 27 | + public function _before(AcceptanceTester $I): void |
| 28 | + { |
| 29 | + parent::_before($I); |
| 30 | + |
| 31 | + $this->I = $I; |
| 32 | + $I->login(AcceptanceTester::UNIT_LEADER_ROLE); |
| 33 | + $this->licensePlate = 'RZ-' . time(); |
| 34 | + } |
| 35 | + |
| 36 | + /** @depends createVehicle */ |
| 37 | + public function createTravelOrder(AcceptanceTester $I): void |
| 38 | + { |
| 39 | + $name = 'Porada s vedoucími'; |
| 40 | + $unitRepresentative = 'Pavel Zástupce'; |
| 41 | + $licensePlate = 'RZA-' . time(); |
| 42 | + $I->wantTo('Create travel order'); |
| 43 | + $this->navigateToVehicle($I); |
| 44 | + $this->newVehicle($I, $licensePlate); |
| 45 | + $this->navigationToContract($I); |
| 46 | + $this->newContract($I, $unitRepresentative); |
| 47 | + $this->navigateToTravelOrder($I); |
| 48 | + $this->newTravelOrder($I, $name, $licensePlate); |
| 49 | + $this->navigateToTravelOrder($I); |
| 50 | + $this->deleteTravelOrder($I, $name); |
| 51 | + $this->navigateToVehicle($I); |
| 52 | + $this->deleteVehicle($I, $licensePlate); |
| 53 | + $this->navigationToContract($I); |
| 54 | + $this->deleteContract($I, $unitRepresentative); |
| 55 | + } |
| 56 | + |
| 57 | + protected function navigateToTravelOrder(AcceptanceTester $I): void |
| 58 | + { |
| 59 | + $I->amOnPage('/'); |
| 60 | + $I->click('Cesťáky'); |
| 61 | + $I->seeInCurrentUrl('/cestaky'); |
| 62 | + } |
| 63 | + |
| 64 | + protected function newTravelOrder(AcceptanceTester $I, string $name, string $licensePlate): void |
| 65 | + { |
| 66 | + $I->click('Založit cestovní příkaz'); |
| 67 | + $I->waitForText('Založit cestovní příkaz'); |
| 68 | + |
| 69 | + $I->waitForElementVisible('#frm-form-form-purpose', 10); |
| 70 | + |
| 71 | + $I->fillField('#frm-form-form-purpose', $name); |
| 72 | + $I->fillField('#frm-form-form-place', 'Praha'); |
| 73 | + $I->fillField('#frm-form-form-fellowPassengers', 'Pepa Novák, Alena Malá'); |
| 74 | + $I->fillField('#frm-form-form-note', 'Vzít materiál ze skladu'); |
| 75 | + |
| 76 | + $I->selectOption('#frm-form-form-type', ['car']); |
| 77 | + $I->click(['xpath' => '//*[@id="frm-form-form-contract_id"]/option[@value!=""][1]']); |
| 78 | + |
| 79 | + $I->waitForElementNotVisible('#passengerName', 5); |
| 80 | + $I->waitForElementNotVisible('#passengerContact', 5); |
| 81 | + $I->waitForElementNotVisible('#passengerAddress', 5); |
| 82 | + |
| 83 | + // (Alternativa bez smlouvy – odkomentuj a vyplň) |
| 84 | + /* |
| 85 | + $I->selectOption('#frm-form-form-contract_id', ''); |
| 86 | + $I->executeJS('document.getElementById("frm-form-form-contract_id").dispatchEvent(new Event("change",{bubbles:true}));'); |
| 87 | + $I->waitForElementVisible('#passengerName', 5); |
| 88 | + $I->fillField('#frm-form-form-passenger-name', 'Jan Novák'); |
| 89 | + $I->fillField('#frm-form-form-passenger-contact', '777123456'); |
| 90 | + $I->fillField('#frm-form-form-passenger-address', 'Ulice 1, Praha'); |
| 91 | + */ |
| 92 | + |
| 93 | + // 5) Vozidlo – po výběru "car" jsou pole povinná |
| 94 | + $I->waitForElementVisible('#frm-form-form-vehicle_id', 5); |
| 95 | + $I->selectOption('#frm-form-form-vehicle_id', ['text' => 'Osobní (' . $licensePlate . ')']); |
| 96 | + $I->fillField('#frm-form-form-fuel_price', '38.50'); |
| 97 | + $I->fillField('#frm-form-form-amortization', '1.20'); |
| 98 | + |
| 99 | + // 6) Odeslání |
| 100 | + $I->scrollTo('[name=send]', 0, -120); |
| 101 | + $I->click('[name=send]'); |
| 102 | + |
| 103 | + // 7) Ověření (uprav dle app – flash zpráva / redirect / nadpis) |
| 104 | + $I->waitForText('Cestovní příkaz byl založen', 10); |
| 105 | + $I->seeInCurrentUrl('/cestaky'); |
| 106 | + } |
| 107 | + |
| 108 | + protected function deleteTravelOrder(AcceptanceTester $I, string $name): void |
| 109 | + { |
| 110 | + $I->click($name); |
| 111 | + $I->waitForText('Cestovní příkaz'); |
| 112 | + $I->click('Smazat'); |
| 113 | + try { |
| 114 | + $I->acceptPopup(); |
| 115 | + } catch (Throwable) { |
| 116 | + } |
| 117 | + |
| 118 | + $I->waitForText('Cestovní příkaz byl smazán.'); |
| 119 | + } |
| 120 | + |
| 121 | + /** @depends createContract */ |
| 122 | + public function createVehicle(AcceptanceTester $I): void |
| 123 | + { |
| 124 | + $I->wantTo('Create vehicle'); |
| 125 | + $this->navigateToVehicle($I); |
| 126 | + $this->newVehicle($I, $this->licensePlate); |
| 127 | + $this->navigateToVehicle($I); |
| 128 | + $this->checkVehicle($I, $this->licensePlate); |
| 129 | + $this->navigateToVehicle($I); |
| 130 | + $this->deleteVehicle($I, $this->licensePlate); |
| 131 | + } |
| 132 | + |
| 133 | + protected function navigateToVehicle(AcceptanceTester $I): void |
| 134 | + { |
| 135 | + $I->amOnPage('/'); |
| 136 | + $I->click('Cesťáky'); |
| 137 | + $I->seeInCurrentUrl('/cestaky'); |
| 138 | + $I->click('Vozidla'); |
| 139 | + $I->seeInCurrentUrl('/cestaky/vozidla'); |
| 140 | + } |
| 141 | + |
| 142 | + protected function newVehicle(AcceptanceTester $I, string $licensePlate): void |
| 143 | + { |
| 144 | + $I->click('Založit nové vozidlo'); |
| 145 | + $I->see('Nové vozidlo'); |
| 146 | + |
| 147 | + $I->fillField(['id' => 'frm-formCreateVehicle-type'], $this->vehicleType); |
| 148 | + $I->fillField(['id' => 'frm-formCreateVehicle-registration'], $licensePlate); |
| 149 | + $I->fillField(['id' => 'frm-formCreateVehicle-consumption'], $this->harmonizedConsumption); |
| 150 | + $I->selectOption(['id' => 'frm-formCreateVehicle-subunitId'], $this->division); |
| 151 | + $I->click('Založit'); |
| 152 | + $I->click('Založit nové vozidlo'); |
| 153 | + $I->see('Nové vozidlo'); |
| 154 | + |
| 155 | + $I->fillField(['id' => 'frm-formCreateVehicle-type'], $this->vehicleType); |
| 156 | + $I->fillField(['id' => 'frm-formCreateVehicle-registration'], $licensePlate); |
| 157 | + $I->fillField(['id' => 'frm-formCreateVehicle-consumption'], $this->harmonizedConsumption); |
| 158 | + $I->selectOption(['id' => 'frm-formCreateVehicle-subunitId'], $this->division); |
| 159 | + $I->click('Založit'); |
| 160 | + } |
| 161 | + |
| 162 | + protected function checkVehicle(AcceptanceTester $I, string $licensePlate): void |
| 163 | + { |
| 164 | + $I->see('Vozidla'); |
| 165 | + $I->see($licensePlate); |
| 166 | + $I->see($this->vehicleType); |
| 167 | + $I->see($this->division); |
| 168 | + $I->click('#frm-grid-grid-filter-filter-search'); |
| 169 | + $I->fillField('#frm-grid-grid-filter-filter-search', 'AUV'); |
| 170 | + $I->pressKey('#frm-grid-grid-filter-filter-search', [WebDriverKeys::ENTER]); |
| 171 | + $I->wait(3); |
| 172 | + $I->dontSee($licensePlate, '#snippet-grid-grid-table'); |
| 173 | + $I->see('Nenalezeny žádné záznamy.', '#snippet-grid-grid-table'); |
| 174 | + $I->click('#frm-grid-grid-filter-filter-search'); |
| 175 | + $I->fillField('#frm-grid-grid-filter-filter-search', $licensePlate); |
| 176 | + $I->pressKey('#frm-grid-grid-filter-filter-search', [WebDriverKeys::ENTER]); |
| 177 | + $I->waitForText($licensePlate, 10, '#snippet-grid-grid-table'); |
| 178 | + $I->wait(3); |
| 179 | + $I->click($licensePlate, '#snippet-grid-grid-table'); |
| 180 | + $I->waitForText('Údaje o vozidle'); |
| 181 | + } |
| 182 | + |
| 183 | + protected function deleteVehicle(AcceptanceTester $I, string $licensePlate): void |
| 184 | + { |
| 185 | + $I->click($licensePlate, '#snippet-grid-grid-table'); |
| 186 | + $I->waitForText('Údaje o vozidle'); |
| 187 | + $I->click('Smazat vozidlo'); |
| 188 | + try { |
| 189 | + $I->acceptPopup(); |
| 190 | + } catch (Throwable) { |
| 191 | + } |
| 192 | + |
| 193 | + $I->waitForText('Vozidlo bylo odebráno.'); |
| 194 | + } |
| 195 | + |
| 196 | + public function createContract(AcceptanceTester $I): void |
| 197 | + { |
| 198 | + $I->wantTo('Create contract'); |
| 199 | + $this->navigationToContract($I); |
| 200 | + $this->newContract($I, $this->unitRepresentative); |
| 201 | + $this->navigationToContract($I); |
| 202 | + $this->detailContract($I, $this->unitRepresentative); |
| 203 | + $this->navigationToContract($I); |
| 204 | + $this->deleteContract($I, $this->unitRepresentative); |
| 205 | + } |
| 206 | + |
| 207 | + protected function navigationToContract(AcceptanceTester $I): void |
| 208 | + { |
| 209 | + $I->amOnPage('/'); |
| 210 | + $I->click('Cesťáky'); |
| 211 | + $I->seeInCurrentUrl('/cestaky'); |
| 212 | + $I->click('Smlouvy'); |
| 213 | + $I->seeInCurrentUrl('/cestaky/smlouvy'); |
| 214 | + $I->waitForText('Smlouvy'); |
| 215 | + } |
| 216 | + |
| 217 | + protected function newContract(AcceptanceTester $I, string $unitRepresentative): void |
| 218 | + { |
| 219 | + $I->click('Založit smlouvu'); |
| 220 | + $I->waitForText('Nová smlouva o proplácení cestovních náhrad'); |
| 221 | + $I->waitForElementVisible('#frm-formCreateContract', 10); |
| 222 | + $I->fillField('#frm-formCreateContract-passengerName', 'Jan Novák'); |
| 223 | + $I->fillField('#frm-formCreateContract-passengerAddress', 'Ulice 1, 100 00 Praha'); |
| 224 | + $I->fillField('#frm-formCreateContract-passengerContact', '777123456'); |
| 225 | + $I->fillField('#frm-formCreateContract-unitRepresentative', $unitRepresentative); |
| 226 | + $I->fillField('#frm-formCreateContract-start', '18.10.2025'); |
| 227 | + $I->click('#frm-formCreateContract-passengerBirthday'); |
| 228 | + $I->fillField('#frm-formCreateContract-passengerBirthday', '01.01.1990'); |
| 229 | + $I->pressKey('#frm-formCreateContract-passengerBirthday', [WebDriverKeys::TAB]); |
| 230 | + $I->click('#frm-formCreateContract [name=send]'); |
| 231 | + $I->waitForText('Smlouva byla založena.'); |
| 232 | + $I->see($unitRepresentative); |
| 233 | + } |
| 234 | + |
| 235 | + protected function detailContract(AcceptanceTester $I, string $unitRepresentative): void |
| 236 | + { |
| 237 | + $I->click(sprintf('[data-test="%s"]', $unitRepresentative)); |
| 238 | + $I->waitForElementVisible('body', 10); |
| 239 | + $I->see('Smlouva o proplácení cestovních náhrad'); |
| 240 | + |
| 241 | + // --- Vytisknout -> PDF ve stejném tabu --- |
| 242 | + $I->waitForElementVisible('[data-test="contract-print"]', 10); |
| 243 | + $urlBefore = $I->grabFromCurrentUrl(); |
| 244 | + $I->click('[data-test="contract-print"]'); |
| 245 | + |
| 246 | + $I->waitForJS('return window.location.href !== ' . json_encode($urlBefore) . ';', 10); |
| 247 | + $I->seeInCurrentUrl('/print'); |
| 248 | + |
| 249 | + $I->moveBack(); |
| 250 | + |
| 251 | + $I->waitForText('Údaje smlouvy', 10); |
| 252 | + } |
| 253 | + |
| 254 | + protected function deleteContract(AcceptanceTester $I, string $unitRepresentative): void |
| 255 | + { |
| 256 | + $I->click(sprintf('[data-test="%s"]', $unitRepresentative)); |
| 257 | + $I->waitForElementVisible('body', 10); |
| 258 | + $I->see('Smlouva o proplácení cestovních náhrad'); |
| 259 | + $I->waitForElementVisible('[data-test="contract-delete"]', 10); |
| 260 | + // --- Smazat --- |
| 261 | + $I->click('[data-test="contract-delete"]'); |
| 262 | + try { |
| 263 | + $I->acceptPopup(); |
| 264 | + } catch (Throwable) { |
| 265 | + } |
| 266 | + |
| 267 | + $I->waitForText('Smlouva byla smazána', 10); |
| 268 | + $I->seeInCurrentUrl('/smlouvy'); |
| 269 | + } |
| 270 | +} |
0 commit comments