Skip to content

Commit

Permalink
check trashbin after deletion in UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it committed Sep 13, 2017
1 parent f3421d6 commit 44543b9
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 322 deletions.
55 changes: 46 additions & 9 deletions tests/ui/features/bootstrap/FilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use Behat\Gherkin\Node\TableNode;
use Page\FilesPage;
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;
use Page\TrashbinPage;
use SensioLabs\Behat\PageObjectExtension\PageObject\PageObject;

require_once 'bootstrap.php';

Expand All @@ -34,6 +36,7 @@
class FilesContext extends RawMinkContext implements Context {

private $filesPage;
private $trashbinPage;

/**
* Table of all files and folders that should have been deleted stored so
Expand All @@ -49,7 +52,10 @@ class FilesContext extends RawMinkContext implements Context {
*
* @param FilesPage $filesPage
*/
public function __construct(FilesPage $filesPage) {
public function __construct(
FilesPage $filesPage, TrashbinPage $trashbinPage
) {
$this->trashbinPage = $trashbinPage;
$this->filesPage = $filesPage;
}

Expand Down Expand Up @@ -218,6 +224,19 @@ public function theDeletedElementsShouldNotBeListedAfterPageReload() {
$this->theDeletedElementsShouldNotBeListed();
}

/**
* @Then the deleted elements should be listed in the trashbin
* @return void
*/
public function theDeletedElementsShouldBeListedInTheTrashbin() {
$this->trashbinPage->open();
$this->trashbinPage->waitTillPageIsLoaded($this->getSession());

foreach ($this->deletedElementsTable as $file) {
$this->theFileFolderShouldBeListed($file['name'], $this->trashbinPage);
}
}

/**
* @When I batch delete these files
* @param TableNode $files table of file names
Expand Down Expand Up @@ -267,23 +286,33 @@ public function iOpenTheFolder($name) {
/**
* @Then the file/folder :name should be listed
* @param string $name
* @param PageObject|null $pageObject if null $this->filesPage will be used
* @return void
*/
public function theFileFolderShouldBeListed($name) {
public function theFileFolderShouldBeListed(
$name, $pageObject = null
) {
if (is_null($pageObject)) {
$pageObject = $this->filesPage;
}
PHPUnit_Framework_Assert::assertNotNull(
$this->filesPage->findFileRowByName($name, $this->getSession())
$pageObject->findFileRowByName($name, $this->getSession())
);
}

/**
* @Then the file/folder :name should not be listed
* @param string $name
* @param PageObject|null $pageObject if null $this->filesPage will be used
* @return void
*/
public function theFileFolderShouldNotBeListed($name) {
public function theFileFolderShouldNotBeListed($name, $pageObject = null) {
$message = null;
if (is_null($pageObject)) {
$pageObject = $this->filesPage;
}
try {
$this->filesPage->findFileRowByName($name, $this->getSession());
$pageObject->findFileRowByName($name, $this->getSession());
} catch (ElementNotFoundException $e) {
$message = $e->getMessage();
}
Expand All @@ -297,14 +326,15 @@ public function theFileFolderShouldNotBeListed($name) {
}

/**
* @Then /^the following (?:file|folder) should (not|)\s?be listed$/
* @Then /^the following (?:file|folder) should (not|)\s?be listed\s?(in the trashbin|)$/
* @param string $shouldOrNot
* @param string $trashbin
* @param TableNode $namePartsTable table of parts of the file name
* table headings: must be: |name-parts |
* @return void
*/
public function theFollowingFileFolderShouldBeListed(
$shouldOrNot, TableNode $namePartsTable
$shouldOrNot, $trashbin, TableNode $namePartsTable
) {
$should = ($shouldOrNot !== "not");
$fileNameParts = [];
Expand All @@ -313,10 +343,17 @@ public function theFollowingFileFolderShouldBeListed(
$fileNameParts[] = $namePartsRow['name-parts'];
}

if ($trashbin !== "") {
$this->trashbinPage->open();
$this->trashbinPage->waitTillPageIsLoaded($this->getSession());
$pageObject = $this->trashbinPage;
} else {
$pageObject = $this->filesPage;
}
if ($should) {
$this->theFileFolderShouldBeListed($fileNameParts);
$this->theFileFolderShouldBeListed($fileNameParts, $pageObject);
} else {
$this->theFileFolderShouldNotBeListed($fileNameParts);
$this->theFileFolderShouldNotBeListed($fileNameParts, $pageObject);
}
}

Expand Down
10 changes: 9 additions & 1 deletion tests/ui/features/files/delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Feature: delete
| strängé filename (duplicate #2).txt |
Then the deleted elements should not be listed
And the deleted elements should not be listed after a page reload
But the deleted elements should be listed in the trashbin

Scenario: Delete a file with problematic characters
When I rename the following file to
Expand Down Expand Up @@ -48,6 +49,12 @@ Feature: delete
| "double" quotes |
| question? |
| &and#hash |
But the following file should be listed in the trashbin
| name-parts |
| 'single' |
| "double" quotes |
| question? |
| &and#hash |

Scenario: Delete multiple files at once
When I batch delete these files
Expand All @@ -56,4 +63,5 @@ Feature: delete
| lorem.txt |
| simple-folder |
Then the deleted elements should not be listed
And the deleted elements should not be listed after a page reload
And the deleted elements should not be listed after a page reload
But the deleted elements should be listed in the trashbin
Loading

0 comments on commit 44543b9

Please sign in to comment.