From 4e3fef5b04e41bf5c9b0aa09f0410eec763dd7ec Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Fri, 14 Feb 2020 18:02:19 +0530 Subject: [PATCH] Test case for customer create --- .../Admin/Customer/CustomerCest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/functional/Admin/Customer/CustomerCest.php b/tests/functional/Admin/Customer/CustomerCest.php index 83af81175..4a806624f 100644 --- a/tests/functional/Admin/Customer/CustomerCest.php +++ b/tests/functional/Admin/Customer/CustomerCest.php @@ -23,4 +23,49 @@ class CustomerCest $I->see($customer->id, '//script[@type="text/x-template"]'); $I->see($customer->last_name, '//script[@type="text/x-template"]'); } + + public function testCreate(FunctionalTester $I): void + { + $I->loginAsAdmin(); + $I->amOnAdminRoute('admin.customer.index'); + + $I->click(__('admin::app.customers.customers.add-title'), '//*[contains(@class, "page-action")]'); + $I->seeCurrentRouteIs('admin.customer.create'); + + $I->click(__('admin::app.customers.customers.save-btn-title'), '//*[contains(@class, "page-action")]'); + $I->seeFormHasErrors(); + + $testData = $this->fillForm($I); + $I->click(__('admin::app.customers.customers.save-btn-title'), '//*[contains(@class, "page-action")]'); + + $I->dontSeeFormErrors(); + $I->seeCurrentRouteIs('admin.customer.index'); + $I->seeRecord(Customer::class, $testData); + } + + /** + * @param FunctionalTester $I + * + * @return array with the test-data + */ + private function fillForm(FunctionalTester $I): array + { + $testData = [ + 'first_name' => $I->fake()->firstName, + 'last_name' => $I->fake()->lastName, + 'gender' => $I->fake()->randomElement([ + 'Male', + 'Female', + 'Other', + ]), + 'email' => $I->fake()->email, + ]; + + $I->fillField('first_name', $testData['first_name']); + $I->fillField('last_name', $testData['last_name']); + $I->selectOption('gender', $testData['gender']); + $I->fillField('email', $testData['email']); + + return $testData; + } }