Add acceptance test for form preview

[MAILPOET-2743]
This commit is contained in:
Rostislav Wolny
2020-04-16 18:30:52 +02:00
committed by Veljko V
parent 4cb7ba2424
commit 6d07f5eb32
4 changed files with 58 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ function Preview({
}} }}
title={MailPoet.I18n.t('formPreviewDesktop')} title={MailPoet.I18n.t('formPreviewDesktop')}
href="#" href="#"
data-automation-id="preview_type_desktop"
> >
<DesktopIcon /> <DesktopIcon />
</a> </a>
@@ -37,6 +38,7 @@ function Preview({
}} }}
title={MailPoet.I18n.t('formPreviewMobile')} title={MailPoet.I18n.t('formPreviewMobile')}
href="#" href="#"
data-automation-id="preview_type_mobile"
> >
<MobileIcon /> <MobileIcon />
</a> </a>

View File

@@ -28,6 +28,7 @@ export default () => {
onClick={showPreview} onClick={showPreview}
isPressed={isPreview} isPressed={isPreview}
className="editor-post-preview" className="editor-post-preview"
data-automation-id="form_preview_button"
> >
{__('Preview')} {__('Preview')}
</Button> </Button>

View File

@@ -132,6 +132,7 @@ const FormPreview = () => {
<select <select
onChange={onChange(setFormType)} onChange={onChange(setFormType)}
value={formType} value={formType}
data-automation-id="form_type_selection"
> >
<option value="sidebar">{MailPoet.I18n.t('placeFormSidebar')}</option> <option value="sidebar">{MailPoet.I18n.t('placeFormSidebar')}</option>
<option value="below_post">{MailPoet.I18n.t('placeFormBellowPages')}</option> <option value="below_post">{MailPoet.I18n.t('placeFormBellowPages')}</option>
@@ -155,6 +156,7 @@ const FormPreview = () => {
src={iframeSrc} src={iframeSrc}
title={MailPoet.I18n.t('formPreview')} title={MailPoet.I18n.t('formPreview')}
onLoad={() => setIframeLoaded(true)} onLoad={() => setIframeLoaded(true)}
data-automation-id="form_preview_iframe"
/> />
</Preview> </Preview>
</> </>

View File

@@ -0,0 +1,53 @@
<?php
namespace MailPoet\Test\Acceptance;
use MailPoet\Test\DataFactories\Form;
use MailPoet\Test\DataFactories\Segment;
class FormEditorFormPreviewCest {
public function previewUnsavedChangesAndRememberPreviewSettings(\AcceptanceTester $i) {
$segmentFactory = new Segment();
$segmentName = 'Fancy List';
$segment = $segmentFactory->withName($segmentName)->create();
$formName = 'My fancy form';
$form = new Form();
$form->withName($formName)->withSegments([$segment])->create();
$i->wantTo('Add first name to the editor and preview form without saving it');
$i->login();
$i->amOnMailPoetPage('Forms');
$i->waitForText($formName);
$i->clickItemRowActionByItemName($formName, 'Edit');
$i->waitForElement('[data-automation-id="form_title_input"]');
$i->click('.block-list-appender button');// CLICK the big button that adds new blocks
$i->waitForElement('.block-editor-inserter__results .components-panel__body-toggle');
$i->click('.block-editor-inserter__results .components-panel__body:nth-child(2) .components-panel__body-toggle'); // toggle fields
$i->click('.editor-block-list-item-mailpoet-form-first-name-input'); // add first name block to the editor
// Open preview
$i->click('[data-automation-id="form_preview_button"]');
$i->waitForElement('[data-automation-id="form_preview_iframe"]');
// Check first name was rendered in iframe
$i->switchToIFrame('[data-automation-id="form_preview_iframe"]');
$i->waitForElement('[data-automation-id="form_first_name"]');
$i->switchToIFrame();
// Change preview type and form type and check again
$i->click('[data-automation-id="preview_type_mobile"]');
$i->selectOption('[data-automation-id="form_type_selection"]', 'Fixed bar');
$i->switchToIFrame('[data-automation-id="form_preview_iframe"]');
$i->waitForElement('[data-automation-id="form_first_name"]');
$i->switchToIFrame();
// Reload page and check preview settings
$i->reloadPage();
$i->acceptPopup();
$i->waitForElement('[data-automation-id="form_preview_button"]');
$i->click('[data-automation-id="form_preview_button"]');
$i->waitForElement('[data-automation-id="form_preview_iframe"]');
$i->seeOptionIsSelected('[data-automation-id="form_type_selection"]', 'Fixed bar');
$i->seeOptionIsSelected('[data-automation-id="form_type_selection"]', 'Fixed bar');
}
}