From d459baf9baf99a07955d2b8bc85b4f52cec214b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Wed, 2 Oct 2019 15:45:26 +0200 Subject: [PATCH] Move automatic email acceptance tests from Premium plugin [MAILPOET-2382] --- .../CreateWooCommerceNewsletterCest.php | 80 +++++++++++++++++++ .../DeleteAutomaticWooCommerceEmailCest.php | 77 ++++++++++++++++++ .../DuplicateAutomaticEmailCest.php | 24 ++++++ .../EditAutomaticWooCommerceEmailCest.php | 53 ++++++++++++ .../SendCategoryPurchaseEmailCest.php | 49 ++++++++++++ .../acceptance/SendFirstPurchaseEmailCest.php | 64 +++++++++++++++ .../SendProductPurchaseEmailCest.php | 64 +++++++++++++++ 7 files changed, 411 insertions(+) create mode 100644 tests/acceptance/CreateWooCommerceNewsletterCest.php create mode 100644 tests/acceptance/DeleteAutomaticWooCommerceEmailCest.php create mode 100644 tests/acceptance/DuplicateAutomaticEmailCest.php create mode 100644 tests/acceptance/EditAutomaticWooCommerceEmailCest.php create mode 100644 tests/acceptance/SendCategoryPurchaseEmailCest.php create mode 100644 tests/acceptance/SendFirstPurchaseEmailCest.php create mode 100644 tests/acceptance/SendProductPurchaseEmailCest.php diff --git a/tests/acceptance/CreateWooCommerceNewsletterCest.php b/tests/acceptance/CreateWooCommerceNewsletterCest.php new file mode 100644 index 0000000000..c634a8e4de --- /dev/null +++ b/tests/acceptance/CreateWooCommerceNewsletterCest.php @@ -0,0 +1,80 @@ +wantTo('Create and configure a first purchase automatic email'); + + $newsletter_title = 'First Purchase Email Creation'; + $I->activateWooCommerce(); + + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="new_email"]'); + $I->dontSeeElement('[data-automation-id="woocommerce_premium_feature_notice"]'); + $I->click('[data-automation-id="create_woocommerce"]'); + $I->click('[data-automation-id="create_woocommerce_first_purchase"]'); + + $I->waitForText('Select WooCommerce events conditions'); + $I->click('Next'); + + $template = '[data-automation-id="select_template_0"]'; + $I->waitForElement($template); + $I->click($template); + + $title_element = '[data-automation-id="newsletter_title"]'; + $I->waitForElement($title_element); + $I->fillField($title_element, $newsletter_title); + $I->click('Next'); + + $I->waitForElement('[data-automation-id="newsletter_send_form"]'); + $newsletter_listing_element = '[data-automation-id="listing_item_' . basename($I->getCurrentUrl()) . '"]'; + $I->waitForElementClickable('[value="Activate"]'); + $I->click('Activate'); + + $I->waitForElement($newsletter_listing_element); + $I->see($newsletter_title, $newsletter_listing_element); + $I->see('Email sent when a customer makes their first purchase.', $newsletter_listing_element); + } + + function createAbandonedCartEmail(\AcceptanceTester $I) { + $I->wantTo('Create and configure an abandoned cart automatic email'); + + $newsletter_title = 'Abandoned Cart Email Creation'; + $I->activateWooCommerce(); + + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="new_email"]'); + $I->click('[data-automation-id="create_woocommerce"]'); + $I->scrollToTop(); + $I->click('[data-automation-id="create_woocommerce_abandoned_shopping_cart"]'); + + $I->waitForText('Abandoned Shopping Cart'); + $I->click('Next'); + + $template = '[data-automation-id="select_template_0"]'; + $I->waitForElement($template); + $I->click($template); + + $title_element = '[data-automation-id="newsletter_title"]'; + $I->waitForElement($title_element); + $I->fillField($title_element, $newsletter_title); + $I->click('Next'); + + $I->waitForElement('[data-automation-id="newsletter_send_form"]'); + $newsletter_listing_element = '[data-automation-id="listing_item_' . basename($I->getCurrentUrl()) . '"]'; + $I->waitForElementClickable('[value="Activate"]'); + $I->click('Activate'); + + $I->waitForElement($newsletter_listing_element); + $I->see($newsletter_title, $newsletter_listing_element); + $I->see('Email sent when a customer abandons his cart', $newsletter_listing_element); + } + +} diff --git a/tests/acceptance/DeleteAutomaticWooCommerceEmailCest.php b/tests/acceptance/DeleteAutomaticWooCommerceEmailCest.php new file mode 100644 index 0000000000..944f37536a --- /dev/null +++ b/tests/acceptance/DeleteAutomaticWooCommerceEmailCest.php @@ -0,0 +1,77 @@ +activateWooCommerce(); + } + + function trashAutomaticWooCommerceEmail(\AcceptanceTester $I) { + $newsletter_name = 'Trash Automatic WooCommerce Email Test'; + + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($newsletter_name) + ->withAutomaticTypeWooCommerceFirstPurchase() + ->create(); + + $I->wantTo('Trash automatic WooCommerce email'); + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="tab-WooCommerce"]'); + $I->waitForText($newsletter_name); + $I->clickItemRowActionByItemName($newsletter_name, 'Move to trash'); + $I->waitForElement('[data-automation-id="filters_trash"]'); + $I->click('[data-automation-id="filters_trash"]'); + $I->waitForText($newsletter_name); + } + + function restoreTrashedAutomaticWooCommerceEmail(\AcceptanceTester $I) { + $newsletter_name = 'Restore Trashed Automatic WooCommerce Email Test'; + + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($newsletter_name) + ->withAutomaticTypeWooCommerceFirstPurchase() + ->withDeleted() + ->create(); + + $I->wantTo('Restore trashed automatic WooCommerce email'); + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="tab-WooCommerce"]'); + $I->waitForElement('[data-automation-id="filters_trash"]'); + $I->click('[data-automation-id="filters_trash"]'); + $I->waitForText($newsletter_name); + $I->clickItemRowActionByItemName($newsletter_name, 'Restore'); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="tab-WooCommerce"]'); + $I->waitForText($newsletter_name); + } + + function deleteTrashedAutomaticWooCommerceEmail(\AcceptanceTester $I) { + $newsletter_name = 'Delete Trashed Automatic WooCommerce Email Test'; + + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($newsletter_name) + ->withAutomaticTypeWooCommerceFirstPurchase() + ->withDeleted() + ->create(); + + $I->wantTo('Delete trashed automatic WooCommerce email'); + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="tab-WooCommerce"]'); + $I->waitForElement('[data-automation-id="filters_trash"]'); + $I->click('[data-automation-id="filters_trash"]'); + $I->waitForText($newsletter_name); + $I->clickItemRowActionByItemName($newsletter_name, 'Delete Permanently'); + $I->waitForText('permanently deleted.'); + $I->waitForElementNotVisible($newsletter_name); + } +} diff --git a/tests/acceptance/DuplicateAutomaticEmailCest.php b/tests/acceptance/DuplicateAutomaticEmailCest.php new file mode 100644 index 0000000000..4cb9842944 --- /dev/null +++ b/tests/acceptance/DuplicateAutomaticEmailCest.php @@ -0,0 +1,24 @@ +wantTo('Duplicate an automatic email'); + $I->activateWooCommerce(); + $email_subject = 'Duplicate Automatic Email Test'; + $newsletter_factory = new Newsletter(); + $newsletter_factory->withSubject($email_subject)->withAutomaticTypeWooCommerceFirstPurchase()->create(); + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="tab-WooCommerce"]'); + $I->waitForText($email_subject); + $I->clickItemRowActionByItemName($email_subject, 'Duplicate'); + $I->waitForText('Email "Copy of ' . $email_subject . '" has been duplicated.', 20); + $I->waitForListingItemsToLoad(); + $I->clickItemRowActionByItemName('Copy of ' . $email_subject, 'Edit'); + $I->waitForElement('[data-automation-id="newsletter_title"]', 20); + } +} diff --git a/tests/acceptance/EditAutomaticWooCommerceEmailCest.php b/tests/acceptance/EditAutomaticWooCommerceEmailCest.php new file mode 100644 index 0000000000..6ecbe2995f --- /dev/null +++ b/tests/acceptance/EditAutomaticWooCommerceEmailCest.php @@ -0,0 +1,53 @@ +wantTo('Not see WooCommerce tab'); + $I->deactivateWooCommerce(); + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->dontSee('[data-automation-id="tab-WooCommerce"]'); + } + + function editAutomaticWooCommerceEmail(\AcceptanceTester $I) { + $newsletter_name = 'Edit Automatic WooCommerce Email Test'; + $newsletter_edited_name = 'Edit Automatic WooCommerce Email Test Edited'; + + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($newsletter_name) + ->withAutomaticTypeWooCommerceFirstPurchase() + ->create(); + + // open editation + $I->wantTo('Edit automatic WooCommerce email'); + $I->activateWooCommerce(); + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="tab-WooCommerce"]'); + $I->waitForText($newsletter_name); + $I->clickItemRowActionByItemName($newsletter_name, 'Edit'); + + // edit subject + $title_element = '[data-automation-id="newsletter_title"]'; + $I->waitForElement($title_element); + $I->seeInCurrentUrl('mailpoet-newsletter-editor'); + $I->fillField($title_element, $newsletter_edited_name); + + // edit sending + $I->click('Next'); + $I->waitForElementVisible('#field_sender_name'); + $I->fillField('#field_sender_name', 'Test sender'); + $I->click('Save as draft and close'); + + // check update success + $I->waitForText('Email was updated successfully!'); + $I->amOnMailpoetPage('Emails'); + $I->click('[data-automation-id="tab-WooCommerce"]'); + $I->waitForText($newsletter_edited_name); + } +} diff --git a/tests/acceptance/SendCategoryPurchaseEmailCest.php b/tests/acceptance/SendCategoryPurchaseEmailCest.php new file mode 100644 index 0000000000..87fb9035f7 --- /dev/null +++ b/tests/acceptance/SendCategoryPurchaseEmailCest.php @@ -0,0 +1,49 @@ +activateWooCommerce(); + $settings_factory = new Settings(); + $settings_factory->withWooCommerceListImportPageDisplayed(true); + $settings_factory->withWooCommerceCheckoutOptinEnabled(); + } + + function sendCategoryPurchaseEmail(\AcceptanceTester $I) { + $I->wantTo('Buy a product in category and receive a "Purchased In This Category" email'); + + $product_name = 'Category Purchase Test Product'; + + $product_factory = new WooCommerceProduct($I); + + $category_id = $product_factory->createCategory('Category 1'); + $product = $product_factory + ->withName($product_name) + ->withCategoryIds([$category_id]) + ->create(); + + $email_subject = 'Product In Category Purchase Test'; + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($email_subject) + ->withAutomaticTypeWooCommerceProductInCategoryPurchased([$product]) + ->withActiveStatus() + ->create(); + + $user_email = Security::generateRandomString() . '-user@email.example'; + $I->orderProduct($product, $user_email); + + $I->amOnMailboxAppPage(); + $I->waitForText($email_subject, 20); + $I->click(Locator::contains('span.subject', $email_subject)); + $I->waitForText($user_email, 20); + } +} diff --git a/tests/acceptance/SendFirstPurchaseEmailCest.php b/tests/acceptance/SendFirstPurchaseEmailCest.php new file mode 100644 index 0000000000..70c71a5443 --- /dev/null +++ b/tests/acceptance/SendFirstPurchaseEmailCest.php @@ -0,0 +1,64 @@ +activateWooCommerce(); + $this->settings_factory = new Settings(); + $this->settings_factory->withWooCommerceListImportPageDisplayed(true); + $this->settings_factory->withWooCommerceCheckoutOptinEnabled(); + } + + function sendFirstPurchaseEmail(\AcceptanceTester $I) { + $I->wantTo('Send a "First purchase email"'); + + $product_name = 'First Purchase Product'; + $product_factory = new WooCommerceProduct($I); + $product = $product_factory->withName($product_name)->create(); + + $email_subject = 'First Purchase Test'; + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($email_subject) + ->withAutomaticTypeWooCommerceFirstPurchase() + ->withActiveStatus() + ->create(); + + $user_email = 'user@email.test'; + $I->orderProduct($product, $user_email); + + $I->amOnMailboxAppPage(); + $I->waitForText($email_subject, 20); + $I->click(Locator::contains('span.subject', $email_subject)); + $I->waitForText($user_email, 20); + } + + function doNotSendFirstPurchaseEmailIfUserHasNotOptedIn(\AcceptanceTester $I) { + $I->wantTo('Buy a product, do not opt-in and don\'t receive a "First purchase email"'); + + $product_name = 'First Purchase Product'; + $product_factory = new WooCommerceProduct($I); + $product = $product_factory->withName($product_name)->create(); + + $email_subject = 'First Purchase Test 2'; + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($email_subject) + ->withAutomaticTypeWooCommerceFirstPurchase() + ->withActiveStatus() + ->create(); + + $user_email = 'user3@email.test'; + $I->orderProduct($product, $user_email, true, false); + + $I->amOnMailboxAppPage(); + $I->dontSee($email_subject); + $I->dontSee($user_email); + } +} diff --git a/tests/acceptance/SendProductPurchaseEmailCest.php b/tests/acceptance/SendProductPurchaseEmailCest.php new file mode 100644 index 0000000000..4d4fda9419 --- /dev/null +++ b/tests/acceptance/SendProductPurchaseEmailCest.php @@ -0,0 +1,64 @@ +activateWooCommerce(); + $this->settings_factory = new Settings(); + $this->settings_factory->withWooCommerceListImportPageDisplayed(true); + $this->settings_factory->withWooCommerceCheckoutOptinEnabled(); + } + + function sendProductPurchaseEmail(\AcceptanceTester $I) { + $I->wantTo('Buy a product and receive a "Product Purchase" email'); + + $product_name = 'Product Purchase Test Product'; + $product_factory = new WooCommerceProduct($I); + $product = $product_factory->withName($product_name)->create(); + + $email_subject = 'Product Purchase Test'; + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($email_subject) + ->withAutomaticTypeWooCommerceProductPurchased([$product]) + ->withActiveStatus() + ->create(); + + $user_email = 'user2@email.test'; + $I->orderProduct($product, $user_email); + + $I->amOnMailboxAppPage(); + $I->waitForText($email_subject, 20); + $I->click(Locator::contains('span.subject', $email_subject)); + $I->waitForText($user_email, 20); + } + + function doNotSendProductPurchaseEmailIfUserHasNotOptedIn(\AcceptanceTester $I) { + $I->wantTo('Buy a product, do not opt-in and don\'t receive a "Product Purchase" email'); + + $product_name = 'Product Purchase Test Product'; + $product_factory = new WooCommerceProduct($I); + $product = $product_factory->withName($product_name)->create(); + + $email_subject = 'Product Purchase Test 2'; + $newsletter_factory = new Newsletter(); + $newsletter_factory + ->withSubject($email_subject) + ->withAutomaticTypeWooCommerceProductPurchased([$product]) + ->withActiveStatus() + ->create(); + + $user_email = 'user4@email.test'; + $I->orderProduct($product, $user_email, true, false); + + $I->amOnMailboxAppPage(); + $I->dontSee($email_subject); + $I->dontSee($user_email); + } +}