From b1bf4f396e770392b43750dda7de7924e11ae8f9 Mon Sep 17 00:00:00 2001 From: Veljko V Date: Wed, 8 Jul 2020 16:15:32 +0200 Subject: [PATCH] Add new testcase with all scenarios for segments MAILPOET-3047 --- tests/acceptance/CreateNewSegmentCest.php | 46 ----- tests/acceptance/DeleteTrashedSegmentCest.php | 74 -------- tests/acceptance/EditExistingSegmentCest.php | 41 ----- tests/acceptance/ManageSegmentsCest.php | 164 ++++++++++++++++++ .../acceptance/RestoreTrashedSegmentCest.php | 35 ---- tests/acceptance/TrashExistingSegmentCest.php | 37 ---- .../acceptance/ViewSegmentSubscribersCest.php | 57 ------ 7 files changed, 164 insertions(+), 290 deletions(-) delete mode 100644 tests/acceptance/CreateNewSegmentCest.php delete mode 100644 tests/acceptance/DeleteTrashedSegmentCest.php delete mode 100644 tests/acceptance/EditExistingSegmentCest.php create mode 100644 tests/acceptance/ManageSegmentsCest.php delete mode 100644 tests/acceptance/RestoreTrashedSegmentCest.php delete mode 100644 tests/acceptance/TrashExistingSegmentCest.php delete mode 100644 tests/acceptance/ViewSegmentSubscribersCest.php diff --git a/tests/acceptance/CreateNewSegmentCest.php b/tests/acceptance/CreateNewSegmentCest.php deleted file mode 100644 index 3db893cc30..0000000000 --- a/tests/acceptance/CreateNewSegmentCest.php +++ /dev/null @@ -1,46 +0,0 @@ -wantTo('Create a new WP user role segment'); - $segmentTitle = 'Create User Role Segment Test'; - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->click('[data-automation-id="new-segment"]'); - $i->fillField(['name' => 'name'], $segmentTitle); - $i->fillField(['name' => 'description'], 'Lorem ipsum dolor amed'); - $i->selectOption('form select[name=segmentType]', 'WordPress user roles'); - $i->selectOption('form select[name=wordpressRole]', 'Editor'); - $i->click('Save'); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - $i->waitForText($segmentTitle); - } - - public function createEmailSegment(\AcceptanceTester $i) { - $i->wantTo('Create a new email segment'); - $emailSubject = 'Segment Email Test'; - $newsletterFactory = new Newsletter(); - $newsletterFactory->withSubject($emailSubject)->create(); - $segmentTitle = 'Create Email Segment Test'; - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->click('[data-automation-id="new-segment"]'); - $i->fillField(['name' => 'name'], $segmentTitle); - $i->fillField(['name' => 'description'], 'Lorem ipsum dolor amed'); - $i->selectOption('form select[name=segmentType]', 'Email'); - $i->selectOption('form select[name=action]', 'opened'); - $i->click('#select2-newsletter_id-container'); - $i->selectOptionInSelect2($emailSubject); - $i->click('Save'); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - $i->waitForText($segmentTitle, 20); - } -} diff --git a/tests/acceptance/DeleteTrashedSegmentCest.php b/tests/acceptance/DeleteTrashedSegmentCest.php deleted file mode 100644 index 7b334dc813..0000000000 --- a/tests/acceptance/DeleteTrashedSegmentCest.php +++ /dev/null @@ -1,74 +0,0 @@ -wantTo('Delete a segment from trash'); - - $segmentTitle = 'Delete Segment From Trash Test'; - - $segmentFactory = new DynamicSegment(); - $segment = $segmentFactory - ->withName($segmentTitle) - ->withUserRoleFilter('Administrator') - ->withDeleted() - ->create(); - $segmentFactory - ->withName($segmentTitle . '2') - ->withUserRoleFilter('Administrator') - ->withDeleted() - ->create(); - $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; - - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - $i->waitForElement('[data-automation-id="filters_trash"]'); - $i->click('[data-automation-id="filters_trash"]'); - $i->waitForText($segmentTitle, 20, $listingAutomationSelector); - $i->clickItemRowActionByItemName($segmentTitle, 'Delete permanently'); - $i->waitForText('1 segment was permanently deleted.'); - $i->dontSeeElement($listingAutomationSelector); - $i->seeNoJSErrors(); - $i->waitForText($segmentTitle . '2', 20); - } - - public function emptyTrash(\AcceptanceTester $i) { - $i->wantTo('Empty a trash on Segment page'); - - $segmentTitle = 'Empty Trash'; - - $segmentFactory = new DynamicSegment(); - $segment = $segmentFactory - ->withName($segmentTitle) - ->withUserRoleFilter('Administrator') - ->withDeleted() - ->create(); - $segmentFactory = new DynamicSegment(); - $segmentFactory - ->withName($segmentTitle . '2') - ->withUserRoleFilter('Administrator') - ->create(); - $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; - - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - $i->waitForElement('[data-automation-id="filters_trash"]'); - $i->click('[data-automation-id="filters_trash"]'); - $i->waitForText($segmentTitle, 20, $listingAutomationSelector); - - $i->click('[data-automation-id="empty_trash"]'); - $i->waitForText('1 segment was permanently deleted.'); - $i->dontSeeElement($listingAutomationSelector); - $i->seeNoJSErrors(); - - $i->click('[data-automation-id="filters_all"]'); - $i->waitForText($segmentTitle . '2', 20); - } -} diff --git a/tests/acceptance/EditExistingSegmentCest.php b/tests/acceptance/EditExistingSegmentCest.php deleted file mode 100644 index 29f4831445..0000000000 --- a/tests/acceptance/EditExistingSegmentCest.php +++ /dev/null @@ -1,41 +0,0 @@ -wantTo('Edit an existing WP user role segment'); - - $segmentTitle = 'Edit User Role Segment Test'; - $segmentEditedTitle = 'Edit User Role Segment Test Edited'; - - $segmentFactory = new DynamicSegment(); - $segment = $segmentFactory - ->withName($segmentTitle) - ->withUserRoleFilter('Administrator') - ->create(); - - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; - $i->waitForText($segmentTitle, 10, $listingAutomationSelector); - $i->clickItemRowActionByItemName($segmentTitle, 'Edit'); - - $i->waitForElementNotVisible('.mailpoet_form_loading'); - $i->fillField(['name' => 'name'], $segmentEditedTitle); - $i->fillField(['name' => 'description'], 'Lorem ipsum dolor amed edited'); - $i->selectOption('form select[name=segmentType]', 'WordPress user roles'); - $i->selectOption('form select[name=wordpressRole]', 'Editor'); - $i->click('Save'); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - - $i->waitForText($segmentEditedTitle, 20, $listingAutomationSelector); - $i->seeNoJSErrors(); - } -} diff --git a/tests/acceptance/ManageSegmentsCest.php b/tests/acceptance/ManageSegmentsCest.php new file mode 100644 index 0000000000..d7b3b0c092 --- /dev/null +++ b/tests/acceptance/ManageSegmentsCest.php @@ -0,0 +1,164 @@ +withWooCommerceListImportPageDisplayed(true); + (new Settings())->withCookieRevenueTrackingDisabled(); + } + + public function viewUserRoleSegmentSubscribers(\AcceptanceTester $i) { + $i->wantTo('View WP user role segment subscribers'); + + $wpAdminEmail = 'test-admin@example.com'; + $wpEditorEmail = 'test-editor@example.com'; + $wpAuthorEmail = 'test-author@example.com'; + $segmentTitle = 'User Role Segment Test'; + + $this->createUser('Test Admin', 'admin', $wpAdminEmail); + $this->createUser('Test Editor', 'editor', $wpEditorEmail); + $this->createUser('Test Author', 'author', $wpAuthorEmail); + + $segmentFactory = new DynamicSegment(); + $segment = $segmentFactory + ->withName($segmentTitle) + ->withUserRoleFilter('Editor') + ->create(); + + $i->login(); + $i->amOnMailpoetPage('Lists'); + $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); + $i->click('[data-automation-id="dynamic-segments-tab"]'); + $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; + $i->waitForText($segmentTitle, 10, $listingAutomationSelector); + $i->clickItemRowActionByItemName($segmentTitle, 'View Subscribers'); + $i->seeInCurrentUrl('mailpoet-subscribers#'); + $i->seeInCurrentUrl('segment=' . $segment->id); + $i->waitForText($wpEditorEmail, 20); + $i->see($segmentTitle, ['css' => 'select[name=segment]']); + $i->dontSee($wpAdminEmail); + $i->dontSee($wpAuthorEmail); + $i->seeNoJSErrors(); + } + + public function createEditTrashRestoreAndDeleteExistingSegment(\AcceptanceTester $i) { + $i->wantTo('Create, edit, trash, restore and delete existing segment'); + $segmentTitle = 'User Segment'; + $segmentEditedTitle = 'User Segment EDITED'; + $segmentDesc = 'Lorem ipsum dolor sit amet'; + $segmentEditedDesc = 'Lorem ipsum dolor sit amet EDITED'; + + // Prepare (2) additional segments for the test + $segmentFactory = new DynamicSegment(); + $segment = $segmentFactory + ->withName($segmentTitle . ' TRASHED 1') + ->withUserRoleFilter('Administrator') + ->withDeleted() + ->create(); + $segmentFactory + ->withName($segmentTitle . ' TRASHED 2') + ->withUserRoleFilter('Administrator') + ->withDeleted() + ->create(); + + // Create a new segment + $i->login(); + $i->amOnMailpoetPage('Lists'); + $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); + $i->click('[data-automation-id="dynamic-segments-tab"]'); + $i->click('[data-automation-id="new-segment"]'); + $i->fillField(['name' => 'name'], $segmentTitle); + $i->fillField(['name' => 'description'], $segmentDesc); + $i->selectOption('form select[name=segmentType]', 'WordPress user roles'); + $i->selectOption('form select[name=wordpressRole]', 'Subscriber'); + $i->click('Save'); + $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); + $i->click('[data-automation-id="dynamic-segments-tab"]'); + $i->waitForText($segmentTitle); + + // Edit existing segment + $i->clickItemRowActionByItemName($segmentTitle, 'Edit'); + $i->waitForElementNotVisible('.mailpoet_form_loading'); + $i->fillField(['name' => 'name'], $segmentEditedTitle); + $i->fillField(['name' => 'description'], $segmentEditedDesc); + $i->selectOption('form select[name=segmentType]', 'WordPress user roles'); + $i->selectOption('form select[name=wordpressRole]', 'Editor'); + $i->click('Save'); + $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); + $i->click('[data-automation-id="dynamic-segments-tab"]'); + $i->waitForText($segmentEditedTitle); + $i->seeNoJSErrors(); + + // Trash existing segment + $i->clickItemRowActionByItemName($segmentEditedTitle, 'Move to trash'); + $i->waitForText('1 segment was moved to the trash.'); + $i->click('[data-automation-id="filters_trash"]'); + $i->waitForText($segmentEditedTitle); + $i->seeNoJSErrors(); + + // Restore trashed segment + $i->clickItemRowActionByItemName($segmentEditedTitle, 'Restore'); + $i->waitForText('1 segment has been restored from the Trash.'); + $i->seeInCurrentURL(urlencode('group[trash]')); + $i->click('[data-automation-id="filters_all"]'); + $i->waitForText($segmentEditedTitle); + $i->seeNoJSErrors(); + + // Trash and delete existing segment + $i->clickItemRowActionByItemName($segmentEditedTitle, 'Move to trash'); + $i->waitForText('1 segment was moved to the trash.'); + $i->click('[data-automation-id="filters_trash"]'); + $i->waitForText($segmentEditedTitle); + $i->clickItemRowActionByItemName($segmentEditedTitle, 'Delete permanently'); + $i->waitForText('1 segment was permanently deleted.'); + $i->seeNoJSErrors(); + $i->waitForText($segmentTitle . ' TRASHED 1'); + $i->waitForText($segmentTitle . ' TRASHED 2'); + + // Empty trash from other (2) segments + $i->click('[data-automation-id="empty_trash"]'); + $i->waitForText('2 segments were permanently deleted.'); + $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; + $i->dontSeeElement($listingAutomationSelector); + $i->seeInCurrentURL(urlencode('group[all]')); + $i->seeNoJSErrors(); + } + + public function createEmailSegment(\AcceptanceTester $i) { + $i->wantTo('Create a new email segment'); + $emailSubject = 'Segment Email Test'; + $newsletterFactory = new Newsletter(); + $newsletterFactory->withSubject($emailSubject)->create(); + $segmentTitle = 'Create Email Segment Test'; + $segmentDesc = 'Lorem ipsum dolor sit amet'; + $i->login(); + $i->amOnMailpoetPage('Lists'); + $i->click('[data-automation-id="new-segment"]'); + $i->fillField(['name' => 'name'], $segmentTitle); + $i->fillField(['name' => 'description'], $segmentDesc); + $i->selectOption('form select[name=segmentType]', 'Email'); + $i->selectOption('form select[name=action]', 'opened'); + $i->click('#select2-newsletter_id-container'); + $i->selectOptionInSelect2($emailSubject); + $i->click('Save'); + $i->amOnMailpoetPage('Lists'); + $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); + $i->click('[data-automation-id="dynamic-segments-tab"]'); + $i->waitForText($segmentTitle, 20); + } + + private function createUser($name, $role, $email) { + $userId = wp_create_user($name, "$name-password", $email); + $user = get_user_by('ID', $userId); + foreach ($user->roles as $defaultRole) { + $user->remove_role($defaultRole); + } + $user->add_role($role); + return $user; + } +} diff --git a/tests/acceptance/RestoreTrashedSegmentCest.php b/tests/acceptance/RestoreTrashedSegmentCest.php deleted file mode 100644 index e185e5749b..0000000000 --- a/tests/acceptance/RestoreTrashedSegmentCest.php +++ /dev/null @@ -1,35 +0,0 @@ -wantTo('Restore a segment from trash'); - - $segmentTitle = 'Restore Segment From Trash Test'; - - $segmentFactory = new DynamicSegment(); - $segment = $segmentFactory - ->withName($segmentTitle) - ->withUserRoleFilter('Administrator') - ->withDeleted() - ->create(); - $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; - - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - - $i->waitForElement('[data-automation-id="filters_trash"]', 10); - $i->click('[data-automation-id="filters_trash"]'); - $i->waitForText($segmentTitle, 10, $listingAutomationSelector); - $i->clickItemRowActionByItemName($segmentTitle, 'Restore'); - $i->waitForText('1 segment has been restored from the Trash.', 10); - $i->seeInCurrentURL(urlencode('group[all]')); - $i->waitForText($segmentTitle, 20, $listingAutomationSelector); - $i->seeNoJSErrors(); - } -} diff --git a/tests/acceptance/TrashExistingSegmentCest.php b/tests/acceptance/TrashExistingSegmentCest.php deleted file mode 100644 index a7d0d366df..0000000000 --- a/tests/acceptance/TrashExistingSegmentCest.php +++ /dev/null @@ -1,37 +0,0 @@ -withWooCommerceListImportPageDisplayed(true); - (new Settings())->withCookieRevenueTrackingDisabled(); - } - - public function moveSegmentToTrash(\AcceptanceTester $i) { - $i->wantTo('Move an existing segment to trash'); - - $segmentTitle = 'Move Segment To Trash Test'; - - $segmentFactory = new DynamicSegment(); - $segment = $segmentFactory - ->withName($segmentTitle) - ->withUserRoleFilter('Administrator') - ->create(); - - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; - $i->waitForText($segmentTitle, 10, $listingAutomationSelector); - $i->clickItemRowActionByItemName($segmentTitle, 'Move to trash'); - $i->waitForText('1 segment was moved to the trash.', 10); - $i->click('[data-automation-id="filters_trash"]'); - $i->waitForText($segmentTitle, 20, $listingAutomationSelector); - $i->seeNoJSErrors(); - } -} diff --git a/tests/acceptance/ViewSegmentSubscribersCest.php b/tests/acceptance/ViewSegmentSubscribersCest.php deleted file mode 100644 index e714a60622..0000000000 --- a/tests/acceptance/ViewSegmentSubscribersCest.php +++ /dev/null @@ -1,57 +0,0 @@ -withWooCommerceListImportPageDisplayed(true); - (new Settings())->withCookieRevenueTrackingDisabled(); - } - - public function viewUserRoleSegmentSubscribers(\AcceptanceTester $i) { - $i->wantTo('View WP user role segment subscribers'); - - $wpAdminEmail = 'test-admin@example.com'; - $wpEditorEmail = 'test-editor@example.com'; - $wpAuthorEmail = 'test-author@example.com'; - $segmentTitle = 'User Role Segment Test'; - - $this->createUser('Test Admin', 'admin', $wpAdminEmail); - $this->createUser('Test Editor', 'editor', $wpEditorEmail); - $this->createUser('Test Author', 'author', $wpAuthorEmail); - - $segmentFactory = new DynamicSegment(); - $segment = $segmentFactory - ->withName($segmentTitle) - ->withUserRoleFilter('Editor') - ->create(); - - $i->login(); - $i->amOnMailpoetPage('Lists'); - $i->waitForElement('[data-automation-id="dynamic-segments-tab"]'); - $i->click('[data-automation-id="dynamic-segments-tab"]'); - $listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]'; - $i->waitForText($segmentTitle, 10, $listingAutomationSelector); - $i->clickItemRowActionByItemName($segmentTitle, 'View Subscribers'); - $i->seeInCurrentUrl('mailpoet-subscribers#'); - $i->seeInCurrentUrl('segment=' . $segment->id); - $i->waitForText($wpEditorEmail, 20); - $i->see($segmentTitle, ['css' => 'select[name=segment]']); - $i->dontSee($wpAdminEmail); - $i->dontSee($wpAuthorEmail); - $i->seeNoJSErrors(); - } - - private function createUser($name, $role, $email) { - $userId = wp_create_user($name, "$name-password", $email); - $user = get_user_by('ID', $userId); - foreach ($user->roles as $defaultRole) { - $user->remove_role($defaultRole); - } - $user->add_role($role); - return $user; - } -}