Create acceptance test for testing products widget
[MAILPOET-1842]
This commit is contained in:
@@ -568,6 +568,7 @@ ProductsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
|
|||||||
|
|
||||||
Module.ProductsWidgetView = base.WidgetView.extend({
|
Module.ProductsWidgetView = base.WidgetView.extend({
|
||||||
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
|
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
|
||||||
|
id: 'automation_editor_block_products',
|
||||||
getTemplate: function getTemplate() { return window.templates.productsInsertion; },
|
getTemplate: function getTemplate() { return window.templates.productsInsertion; },
|
||||||
behaviors: {
|
behaviors: {
|
||||||
DraggableBehavior: {
|
DraggableBehavior: {
|
||||||
|
@@ -22,7 +22,9 @@ class WooCommerceProduct {
|
|||||||
'name' => 'Product',
|
'name' => 'Product',
|
||||||
'type' => self::TYPE_SIMPLE,
|
'type' => self::TYPE_SIMPLE,
|
||||||
'sku' => 'WC_PR_'. uniqid(),
|
'sku' => 'WC_PR_'. uniqid(),
|
||||||
'price' => 10
|
'price' => 10,
|
||||||
|
'categoryId' => null,
|
||||||
|
'tagId' => null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +52,13 @@ class WooCommerceProduct {
|
|||||||
return $this->update('sku', $sku);
|
return $this->update('sku', $sku);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
function withRandomSku() {
|
||||||
|
return $this->update('sku', 'WC_PR_'. uniqid());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $price
|
* @param int $price
|
||||||
* @return $this
|
* @return $this
|
||||||
@@ -58,12 +67,49 @@ class WooCommerceProduct {
|
|||||||
return $this->update('price', $price);
|
return $this->update('price', $price);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
function withCategory($id) {
|
||||||
|
return $this->update('categoryId', $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
function withTag($id) {
|
||||||
|
return $this->update('tagId', $id);
|
||||||
|
}
|
||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
$create_output = $this->tester->cliToArray("wc product create --porcelain --allow-root --user=admin --name=\"{$this->data['name']}\" --sku=\"{$this->data['sku']}\" --type=\"{$this->data['type']}\" --regular_price={$this->data['price']}");
|
$create_command = "wc product create --porcelain --allow-root --user=admin";
|
||||||
|
$create_command .= " --name=\"{$this->data['name']}\"";
|
||||||
|
$create_command .= " --sku=\"{$this->data['sku']}\"";
|
||||||
|
$create_command .= " --type=\"{$this->data['type']}\"";
|
||||||
|
$create_command .= " --regular_price={$this->data['price']}";
|
||||||
|
if ($this->data['categoryId']) {
|
||||||
|
$create_command .= " --categories='[{ \"id\": {$this->data['categoryId']} }]'";
|
||||||
|
}
|
||||||
|
if ($this->data['tagId']) {
|
||||||
|
$create_command .= " --tags='[{ \"id\": {$this->data['tagId']} }]'";
|
||||||
|
}
|
||||||
|
$create_output = $this->tester->cliToArray($create_command);
|
||||||
$product_out = $this->tester->cliToArray("wc product get $create_output[0] --format=json --allow-root --user=admin");
|
$product_out = $this->tester->cliToArray("wc product get $create_output[0] --format=json --allow-root --user=admin");
|
||||||
return json_decode($product_out[0], true);
|
return json_decode($product_out[0], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createCategory($name) {
|
||||||
|
$create_output = $this->tester->cliToArray("wc product_cat create --porcelain --allow-root --user=admin --name=\"{$name}\"");
|
||||||
|
return $create_output[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTag($name) {
|
||||||
|
$create_output = $this->tester->cliToArray("wc product_tag create --porcelain --allow-root --user=admin --name=\"{$name}\"");
|
||||||
|
return $create_output[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
*/
|
*/
|
||||||
|
@@ -18,7 +18,7 @@ modules:
|
|||||||
url: 'http://test.local'
|
url: 'http://test.local'
|
||||||
browser: chrome
|
browser: chrome
|
||||||
port: 4444
|
port: 4444
|
||||||
window_size: '1024x768'
|
window_size: '1280x980'
|
||||||
restart: true
|
restart: true
|
||||||
wait: 0
|
wait: 0
|
||||||
adminUsername: admin
|
adminUsername: admin
|
||||||
|
120
tests/acceptance/EditorProductsCest.php
Normal file
120
tests/acceptance/EditorProductsCest.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Test\Acceptance;
|
||||||
|
|
||||||
|
use MailPoet\Settings\SettingsController;
|
||||||
|
use MailPoet\Test\DataFactories\Newsletter;
|
||||||
|
use MailPoet\Test\DataFactories\WooCommerceProduct;
|
||||||
|
use MailPoet\Util\Security;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../DataFactories/Newsletter.php';
|
||||||
|
require_once __DIR__ . '/../DataFactories/WooCommerceProduct.php';
|
||||||
|
|
||||||
|
class EditorProductsCest {
|
||||||
|
|
||||||
|
const POST_TITLE = 'Hello World';
|
||||||
|
|
||||||
|
const KEYWORD_ZERO_RESULTS = '0Non-existent product';
|
||||||
|
const KEYWORD_MULTIPLE_RESULTS = '1Multiple products ';
|
||||||
|
|
||||||
|
const PRODUCT_PREFIX_CATEGORY = '2Category product';
|
||||||
|
const CATEGORY_ZERO_RESULTS = '3Category with no product';
|
||||||
|
const CATEGORY_MULTIPLE_RESULTS = '4Category multiple products';
|
||||||
|
|
||||||
|
const PRODUCTS_COUNT = 2;
|
||||||
|
|
||||||
|
/** @var WooCommerceProduct */
|
||||||
|
private $product_factory;
|
||||||
|
|
||||||
|
function _before(\AcceptanceTester $I) {
|
||||||
|
$I->activateWooCommerce();
|
||||||
|
$this->product_factory = new WooCommerceProduct($I);
|
||||||
|
|
||||||
|
// Temporary requirement so products widget is displayed
|
||||||
|
$this->settings = new SettingsController();
|
||||||
|
$this->settings->set('display_wc_products_widget', 1);
|
||||||
|
|
||||||
|
// Create categories
|
||||||
|
$this->product_factory->createCategory(self::CATEGORY_ZERO_RESULTS);
|
||||||
|
$category_multiple_results_id = $this->product_factory->createCategory(self::CATEGORY_MULTIPLE_RESULTS);
|
||||||
|
|
||||||
|
// Create products for multiple results
|
||||||
|
for ($i = 0; $i < self::PRODUCTS_COUNT; $i++) {
|
||||||
|
$this->product_factory
|
||||||
|
->withRandomSku()
|
||||||
|
->withName(self::KEYWORD_MULTIPLE_RESULTS . ' ' . Security::generateRandomString())
|
||||||
|
->create();
|
||||||
|
$this->product_factory
|
||||||
|
->withRandomSku()
|
||||||
|
->withName(self::PRODUCT_PREFIX_CATEGORY . ' ' . Security::generateRandomString())
|
||||||
|
->withCategory($category_multiple_results_id)
|
||||||
|
->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterProducts(\AcceptanceTester $I) {
|
||||||
|
$I->wantTo('Filter products');
|
||||||
|
|
||||||
|
$newsletterTitle = 'Newsletter Title';
|
||||||
|
(new Newsletter())
|
||||||
|
->withSubject($newsletterTitle)
|
||||||
|
->loadBodyFrom('newsletterWithText.json')
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$I->login();
|
||||||
|
$I->amOnMailpoetPage('Emails');
|
||||||
|
$I->waitForText($newsletterTitle);
|
||||||
|
$I->clickItemRowActionByItemName($newsletterTitle, 'Edit');
|
||||||
|
|
||||||
|
// Create products block
|
||||||
|
$I->waitForText('Products');
|
||||||
|
$I->wait(1); // just to be sure
|
||||||
|
$I->dragAndDrop('#automation_editor_block_products', '#mce_0');
|
||||||
|
$I->waitForText('PRODUCT SELECTION');
|
||||||
|
|
||||||
|
// Preload tags and categories
|
||||||
|
$I->click('.select2-search__field');
|
||||||
|
$I->waitForElementNotVisible('.select2-results__option.loading-results');
|
||||||
|
|
||||||
|
// Zero results for category
|
||||||
|
$I->selectOptionInSelect2(self::CATEGORY_ZERO_RESULTS);
|
||||||
|
$I->waitForText('No products available');
|
||||||
|
$this->clearCategories($I);
|
||||||
|
|
||||||
|
// Multiple result for category
|
||||||
|
$I->selectOptionInSelect2(self::CATEGORY_MULTIPLE_RESULTS);
|
||||||
|
$I->waitForElementNotVisible('.mailpoet_post_scroll_container > div:nth-child(' . (self::PRODUCTS_COUNT + 1) . ')');
|
||||||
|
$I->waitForText(self::PRODUCT_PREFIX_CATEGORY, 10, '.mailpoet_post_scroll_container');
|
||||||
|
$I->seeNumberOfElements('.mailpoet_post_scroll_container > div', self::PRODUCTS_COUNT);
|
||||||
|
$this->clearCategories($I);
|
||||||
|
|
||||||
|
// Click select2 to hide results
|
||||||
|
$I->click('.select2-search__field');
|
||||||
|
|
||||||
|
// Zero results for keyword
|
||||||
|
$I->fillField('.mailpoet_products_search_term', self::KEYWORD_ZERO_RESULTS);
|
||||||
|
$I->waitForText('No products available');
|
||||||
|
|
||||||
|
// Multiple result for keyword
|
||||||
|
$I->fillField('.mailpoet_products_search_term', self::KEYWORD_MULTIPLE_RESULTS);
|
||||||
|
$I->waitForElementNotVisible('.mailpoet_post_scroll_container > div:nth-child(' . (self::PRODUCTS_COUNT + 1) . ')');
|
||||||
|
$I->waitForText(self::KEYWORD_MULTIPLE_RESULTS, 10, '.mailpoet_post_scroll_container');
|
||||||
|
$I->seeNumberOfElements('.mailpoet_post_scroll_container > div', self::PRODUCTS_COUNT);
|
||||||
|
|
||||||
|
// Product is clickable
|
||||||
|
$I->click('#mailpoet_select_post_0');
|
||||||
|
$I->seeCheckboxIsChecked('#mailpoet_select_post_0');
|
||||||
|
|
||||||
|
// Searching for existing post should return zero results
|
||||||
|
$I->fillField('.mailpoet_products_search_term', self::POST_TITLE);
|
||||||
|
$I->waitForText('No products available');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function clearCategories(\AcceptanceTester $I) {
|
||||||
|
$I->click('.select2-selection__clear');
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after(\AcceptanceTester $I) {
|
||||||
|
$I->deactivateWooCommerce();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user