diff --git a/assets/js/src/listing/groups.jsx b/assets/js/src/listing/groups.jsx index 226175f34a..ba7c9b7393 100644 --- a/assets/js/src/listing/groups.jsx +++ b/assets/js/src/listing/groups.jsx @@ -29,6 +29,7 @@ class ListingGroups extends React.Component { href="javascript:;" className={classes} onClick={() => this.handleSelect(group.name)} + data-automation-id={`filters_${group.label.replace(' ', '_').toLowerCase()}`} > {group.label} ({ parseInt(group.count, 10).toLocaleString() }) diff --git a/tests/DataFactories/Form.php b/tests/DataFactories/Form.php new file mode 100644 index 0000000000..71973eb0f8 --- /dev/null +++ b/tests/DataFactories/Form.php @@ -0,0 +1,35 @@ +data = [ + 'name' => 'New form', + 'body' => 'a:2:{i:0;a:5:{s:2:"id";s:5:"email";s:4:"name";s:5:"Email";s:4:"type";s:4:"text";s:6:"static";b:1;s:6:"params";a:2:{s:5:"label";s:5:"Email";s:8:"required";b:1;}}i:1;a:5:{s:2:"id";s:6:"submit";s:4:"name";s:6:"Submit";s:4:"type";s:6:"submit";s:6:"static";b:1;s:6:"params";a:1:{s:5:"label";s:10:"Subscribe!";}}}', + 'settings' => 'a:4:{s:10:"on_success";s:7:"message";s:15:"success_message";s:61:"Check your inbox or spam folder to confirm your subscription.";s:8:"segments";N;s:20:"segments_selected_by";s:5:"admin";}', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ]; + } + + public function withName($name) { + $this->data['name'] = $name; + return $this; + } + + public function withDeleted() { + $this->data['deleted_at'] = Carbon::now(); + return $this; + } + + public function create() { + \MailPoet\Models\Form::createOrUpdate($this->data); + } + +} diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 96c46d04bf..3be7f36771 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -55,4 +55,10 @@ class AcceptanceTester extends \Codeception\Actor { $I->waitForText($page, 5); } + public function clickItemRowActionByItemName($item_name, $link) { + $I = $this; + $I->moveMouseOver(['xpath' => '//*[text()="' . $item_name . '"]//ancestor::tr']); + $I->click($link, ['xpath' => '//*[text()="' . $item_name . '"]//ancestor::tr']); + } + } diff --git a/tests/acceptance/FormsCreationCest.php b/tests/acceptance/FormsCreationCest.php index dc15bf1957..191533c505 100644 --- a/tests/acceptance/FormsCreationCest.php +++ b/tests/acceptance/FormsCreationCest.php @@ -36,6 +36,4 @@ class FormsCreationCest { $I->waitForText('Please select a list.'); } - - } diff --git a/tests/acceptance/FormsDeletingCest.php b/tests/acceptance/FormsDeletingCest.php new file mode 100644 index 0000000000..cc1333dc33 --- /dev/null +++ b/tests/acceptance/FormsDeletingCest.php @@ -0,0 +1,70 @@ +withName($form_name)->create(); + + $I->wantTo('Move a form to trash'); + + $I->login(); + $I->amOnMailpoetPage('Forms'); + $I->waitForText($form_name); + + $I->clickItemRowActionByItemName($form_name, 'Move to trash'); + + $I->waitForElement('[data-automation-id="filters_trash"]'); + $I->click('[data-automation-id="filters_trash"]'); + + $I->waitForText($form_name); + } + + function restoreFormFromTrash(\AcceptanceTester $I) { + $form_name = 'Restore from trash form'; + $form = new Form(); + $form->withName($form_name)->withDeleted()->create(); + + $I->wantTo('Restore a form from trash'); + + $I->login(); + $I->amOnMailpoetPage('Forms'); + + $I->waitForElement('[data-automation-id="filters_trash"]'); + $I->click('[data-automation-id="filters_trash"]'); + $I->waitForText($form_name); + + $I->clickItemRowActionByItemName($form_name, 'Restore'); + $I->click('[data-automation-id="filters_all"]'); + $I->waitForText($form_name); + } + + function deleteFormPermanently(\AcceptanceTester $I) { + $form_name = 'Delete form permanently'; + $form = new Form(); + $form->withName($form_name)->withDeleted()->create(); + + $I->wantTo('Delete a form permanently trash'); + + $I->login(); + $I->amOnMailpoetPage('Forms'); + + $I->waitForElement('[data-automation-id="filters_trash"]'); + $I->click('[data-automation-id="filters_trash"]'); + $I->waitForText($form_name); + + $I->clickItemRowActionByItemName($form_name, 'Delete Permanently'); + + $I->waitForText('1 form was permanently deleted.'); + $I->waitForElementNotVisible($form_name); + } + + +}