diff --git a/assets/js/src/form/fields/select.jsx b/assets/js/src/form/fields/select.jsx index f2014ae3df..bef808654c 100644 --- a/assets/js/src/form/fields/select.jsx +++ b/assets/js/src/form/fields/select.jsx @@ -63,6 +63,7 @@ const FormFieldSelect = React.createClass({ id={`field_${this.props.field.name}`} value={this.props.item[this.props.field.name] || ''} onChange={this.props.onValueChange} + data-automation-id={this.props.automationId} {...this.props.field.validation} > {placeholder} diff --git a/assets/js/src/newsletters/types/notification/scheduling.jsx b/assets/js/src/newsletters/types/notification/scheduling.jsx index 4bd6916b6d..a2df15fcb6 100644 --- a/assets/js/src/newsletters/types/notification/scheduling.jsx +++ b/assets/js/src/newsletters/types/notification/scheduling.jsx @@ -134,6 +134,7 @@ const NotificationScheduling = React.createClass({ field={intervalField} item={this.getCurrentValue()} onValueChange={this.handleIntervalChange} + automationId="newsletter_interval_type" /> {nthWeekDaySelection} diff --git a/tests/DataFactories/Newsletter.php b/tests/DataFactories/Newsletter.php new file mode 100644 index 0000000000..cf067fb6d3 --- /dev/null +++ b/tests/DataFactories/Newsletter.php @@ -0,0 +1,104 @@ +data = [ + 'subject' => 'Some subject', + 'preheader' => 'Some preheader', + 'type' => 'standard', + 'status' => 'draft', + ]; + $this->options = []; + $this->loadBodyFrom('newsletterWithALC.json'); + } + + /** + * @return Newsletter + */ + public function loadBodyFrom($filename) { + $this->data['body'] = json_decode(file_get_contents(__DIR__ . '/../_data/' . $filename), true); + return $this; + } + + /** + * @return Newsletter + */ + public function withSubject($subject) { + $this->data['subject'] = $subject; + return $this; + } + + /** + * @return Newsletter + */ + public function withStatus($status) { + $this->data['status'] = $status; + return $this; + } + + /** + * @return Newsletter + */ + public function withType($type) { + $this->data['type'] = $type; + return $this; + } + + /** + * @return Newsletter + */ + public function withPostNoticationOptions(array $options = [ + 8 => 'daily', # intervalType + 9 => '0', # timeOfDay + 10 => '1', # intervalType + 11 => '0', # monthDay + 12 => '1', # nthWeekDay + 13 => '0 0 * * *', # schedule + ]) { + return $this->withOptions($options); + } + + /** + * @return Newsletter + */ + public function withOptions(array $options) + { + $this->options = array_merge($this->options, $options); + return $this; + } + + /** + * @return Newsletter + */ + public function withDeleted() { + $this->data['deleted_at'] = Carbon::now(); + return $this; + } + + /** + * @return \MailPoet\Models\Newsletter + */ + public function create() { + $newsletter = \MailPoet\Models\Newsletter::createOrUpdate($this->data); + foreach ($this->options as $option_id => $option_value) { + \MailPoet\Models\NewsletterOption::createOrUpdate( + [ + 'newsletter_id' => $newsletter->id, + 'option_field_id' => $option_id, + 'value' => $option_value, + ] + ); + } + return $newsletter; + } +} \ No newline at end of file diff --git a/tests/_data/newsletterWithALC.json b/tests/_data/newsletterWithALC.json new file mode 100644 index 0000000000..064aed8306 --- /dev/null +++ b/tests/_data/newsletterWithALC.json @@ -0,0 +1,377 @@ +{ + "content": { + "type": "container", + "orientation": "vertical", + "styles": { + "block": { + "backgroundColor": "transparent" + } + }, + "blocks": [ + { + "type": "automatedLatestContentLayout", + "withLayout": true, + "amount": "3", + "contentType": "post", + "terms": [], + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h3", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "featuredImagePosition": "alternate", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "button", + "readMoreText": "Read more", + "readMoreButton": { + "type": "button", + "text": "Read the post", + "url": "[postLink]", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "160px", + "lineHeight": "30px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "16px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "type": "divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + } + ] + }, + "globalStyles": { + "text": { + "fontColor": "#000000", + "fontFamily": "Arial", + "fontSize": "16px" + }, + "h1": { + "fontColor": "#111111", + "fontFamily": "Trebuchet MS", + "fontSize": "30px" + }, + "h2": { + "fontColor": "#222222", + "fontFamily": "Trebuchet MS", + "fontSize": "24px" + }, + "h3": { + "fontColor": "#333333", + "fontFamily": "Trebuchet MS", + "fontSize": "22px" + }, + "link": { + "fontColor": "#21759B", + "textDecoration": "underline" + }, + "wrapper": { + "backgroundColor": "#ffffff" + }, + "body": { + "backgroundColor": "#eeeeee" + } + }, + "blockDefaults": { + "automatedLatestContent": { + "amount": "5", + "withLayout": false, + "contentType": "post", + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h1", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "featuredImagePosition": "belowTitle", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "button", + "readMoreText": "Read more", + "readMoreButton": { + "text": "Read more", + "url": "[postLink]", + "context": "automatedLatestContent.readMoreButton", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "context": "automatedLatestContent.divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + }, + "automatedLatestContentLayout": { + "amount": "5", + "withLayout": true, + "contentType": "post", + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h1", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "featuredImagePosition": "alternate", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "button", + "readMoreText": "Read more", + "readMoreButton": { + "text": "Read more", + "url": "[postLink]", + "context": "automatedLatestContentLayout.readMoreButton", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "context": "automatedLatestContentLayout.divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + }, + "button": { + "text": "Read the post", + "url": "[postLink]", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + }, + "type": "button" + }, + "container": { + "styles": { + "block": { + "backgroundColor": "transparent" + } + } + }, + "divider": { + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + }, + "type": "divider" + }, + "footer": { + "text": "

Unsubscribe | Manage subscription
Add your postal address here!

", + "styles": { + "block": { + "backgroundColor": "transparent" + }, + "text": { + "fontColor": "#222222", + "fontFamily": "Arial", + "fontSize": "12px", + "textAlign": "center" + }, + "link": { + "fontColor": "#6cb7d4", + "textDecoration": "none" + } + } + }, + "posts": { + "amount": "10", + "withLayout": true, + "contentType": "post", + "postStatus": "publish", + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h1", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "featuredImagePosition": "alternate", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "link", + "readMoreText": "Read more", + "readMoreButton": { + "text": "Read more", + "url": "[postLink]", + "context": "posts.readMoreButton", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "context": "posts.divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + }, + "social": { + "iconSet": "default", + "icons": [ + { + "type": "socialIcon", + "iconType": "facebook", + "link": "http://www.facebook.com", + "image": "http://localhost/wp-content/plugins/mailpoet/assets/img/newsletter_editor/social-icons/01-social/Facebook.png?mailpoet_version=3.7.8", + "height": "32px", + "width": "32px", + "text": "Facebook" + }, + { + "type": "socialIcon", + "iconType": "twitter", + "link": "http://www.twitter.com", + "image": "http://localhost/wp-content/plugins/mailpoet/assets/img/newsletter_editor/social-icons/01-social/Twitter.png?mailpoet_version=3.7.8", + "height": "32px", + "width": "32px", + "text": "Twitter" + } + ] + }, + "spacer": { + "styles": { + "block": { + "backgroundColor": "transparent", + "height": "40px" + } + } + }, + "header": { + "text": "Display problems? Open this email in your web browser.", + "styles": { + "block": { + "backgroundColor": "transparent" + }, + "text": { + "fontColor": "#222222", + "fontFamily": "Arial", + "fontSize": "12px", + "textAlign": "center" + }, + "link": { + "fontColor": "#6cb7d4", + "textDecoration": "underline" + } + } + } + } +} \ No newline at end of file diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 3be7f36771..7734b8c15c 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -61,4 +61,16 @@ class AcceptanceTester extends \Codeception\Actor { $I->click($link, ['xpath' => '//*[text()="' . $item_name . '"]//ancestor::tr']); } + /** + * Select a value from select2 input field. + * + * @param string $value + * @param string $element + */ + public function selectOptionInSelect2($value, $element = 'input.select2-search__field') { + $I = $this; + $I->fillField($element, $value); + $I->pressKey($element, \WebDriverKeys::ENTER); + } + } diff --git a/tests/acceptance/EditExistingPostNotificationEmailCest.php b/tests/acceptance/EditExistingPostNotificationEmailCest.php new file mode 100644 index 0000000000..3ff5af0a9f --- /dev/null +++ b/tests/acceptance/EditExistingPostNotificationEmailCest.php @@ -0,0 +1,50 @@ +wantTo('Edit existing post notification email'); + + $newsletter_title = 'Edit Test Post Notification'; + $newsletter_edited_title = 'Edit Test Post Notification Edited'; + + // step 1 - Prepare post notification data + $form = new Newsletter(); + $newsletter = $form->withSubject($newsletter_title) + ->withType('notification') + ->withPostNoticationOptions() + ->create(); + + // step 2 - Open list of post notifications + $I->login(); + $I->amOnMailpoetPage('Emails'); + $I->click('Post Notifications', '[data-automation-id="newsletters_listing_tabs"]'); + + // step 3 - Open editation of post notifcation newsletter + $listing_automation_selector = '[data-automation-id="listing_item_' . $newsletter->id . '"]'; + $I->waitForText('Edit Test Post Notification', 10, $listing_automation_selector); + $I->clickItemRowActionByItemName($newsletter_title, 'Edit'); + + // step 4 - Edit subject + $title_element = '[data-automation-id="newsletter_title"]'; + $I->waitForElement($title_element); + $I->seeInCurrentUrl('mailpoet-newsletter-editor'); + $I->fillField($title_element, $newsletter_edited_title); + + // step 5 - Change schedule, list and activate + $I->click('Next'); + $I->waitForElement('input.select2-search__field'); + $I->seeInCurrentUrl('#/send'); + $I->selectOption('[data-automation-id="newsletter_interval_type"]', 'Weekly on...'); + $I->selectOptionInSelect2( 'WordPress Users'); + $newsletter_listing_element = '[data-automation-id="listing_item_' . basename($I->getCurrentUrl()) . '"]'; + $I->click('Activate'); + $I->waitForElement($newsletter_listing_element); + $I->see($newsletter_edited_title, $newsletter_listing_element); + } +}