Skip to content

Commit ae25fd2

Browse files
authored
Merge pull request #13217 from nextcloud/add-acceptance-tests-for-moving-and-copying-files
Add acceptance tests for moving and copying files
2 parents d549954 + 374b02c commit ae25fd2

File tree

4 files changed

+337
-0
lines changed

4 files changed

+337
-0
lines changed

tests/acceptance/config/behat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ default:
1515
- DialogContext
1616
- FeatureContext
1717
- FileListContext
18+
- FilePickerContext
1819
- FilesAppContext
1920
- FilesAppSharingContext
2021
- LoginPageContext
@@ -43,6 +44,7 @@ default:
4344
- DialogContext
4445
- FeatureContext
4546
- FileListContext
47+
- FilePickerContext
4648
- FilesAppContext
4749
- FilesAppSharingContext
4850
- LoginPageContext

tests/acceptance/features/app-files.feature

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,101 @@ Feature: app-files
140140
Then I see that the current section is "Deleted files"
141141
Then I see that the file list contains a file named "welcome.txt"
142142

143+
Scenario: move a file to another folder
144+
Given I am logged in
145+
And I create a new folder named "Destination"
146+
When I start the move or copy operation for "welcome.txt"
147+
And I select "Destination" in the file picker
148+
And I move to the last selected folder in the file picker
149+
Then I see that the file list does not contain a file named "welcome.txt"
150+
And I enter in the folder named "Destination"
151+
And I see that the file list contains a file named "welcome.txt"
152+
153+
Scenario: move a selection to another folder
154+
Given I am logged in
155+
And I create a new folder named "Folder"
156+
And I create a new folder named "Not selected folder"
157+
And I create a new folder named "Destination"
158+
When I select "welcome.txt"
159+
And I select "Folder"
160+
And I start the move or copy operation for the selected files
161+
And I select "Destination" in the file picker
162+
And I move to the last selected folder in the file picker
163+
Then I see that the file list does not contain a file named "welcome.txt"
164+
And I see that the file list does not contain a file named "Folder"
165+
And I see that the file list contains a file named "Not selected folder"
166+
And I enter in the folder named "Destination"
167+
And I see that the file list contains a file named "welcome.txt"
168+
And I see that the file list contains a file named "Folder"
169+
And I see that the file list does not contain a file named "Not selected folder"
170+
171+
Scenario: copy a file to another folder
172+
Given I am logged in
173+
And I create a new folder named "Destination"
174+
When I start the move or copy operation for "welcome.txt"
175+
And I select "Destination" in the file picker
176+
And I copy to the last selected folder in the file picker
177+
Then I enter in the folder named "Destination"
178+
# The file will appear in the destination once the copy operation finishes
179+
And I see that the file list contains a file named "welcome.txt"
180+
# The Files app is open again to reload the file list in the root folder
181+
And I open the Files app
182+
And I see that the file list contains a file named "welcome.txt"
183+
184+
Scenario: copy a selection to another folder
185+
Given I am logged in
186+
And I create a new folder named "Folder"
187+
And I create a new folder named "Not selected folder"
188+
And I create a new folder named "Destination"
189+
When I select "welcome.txt"
190+
And I select "Folder"
191+
And I start the move or copy operation for the selected files
192+
And I select "Destination" in the file picker
193+
And I copy to the last selected folder in the file picker
194+
Then I enter in the folder named "Destination"
195+
# The files will appear in the destination once the copy operation finishes
196+
And I see that the file list contains a file named "welcome.txt"
197+
And I see that the file list contains a file named "Folder"
198+
And I see that the file list does not contain a file named "Not selected folder"
199+
# The Files app is open again to reload the file list in the root folder
200+
And I open the Files app
201+
And I see that the file list contains a file named "welcome.txt"
202+
And I see that the file list contains a file named "Folder"
203+
And I see that the file list contains a file named "Not selected folder"
204+
205+
Scenario: copy a file in its same folder
206+
Given I am logged in
207+
When I start the move or copy operation for "welcome.txt"
208+
# No folder was explicitly selected, so the last selected folder is the
209+
# current folder.
210+
And I copy to the last selected folder in the file picker
211+
Then I see that the file list contains a file named "welcome.txt"
212+
And I see that the file list contains a file named "welcome (copy).txt"
213+
214+
Scenario: copy a file twice in its same folder
215+
Given I am logged in
216+
And I start the move or copy operation for "welcome.txt"
217+
# No folder was explicitly selected, so the last selected folder is the
218+
# current folder.
219+
And I copy to the last selected folder in the file picker
220+
When I start the move or copy operation for "welcome.txt"
221+
And I copy to the last selected folder in the file picker
222+
Then I see that the file list contains a file named "welcome.txt"
223+
And I see that the file list contains a file named "welcome (copy).txt"
224+
And I see that the file list contains a file named "welcome (copy 2).txt"
225+
226+
Scenario: copy a copy of a file in its same folder
227+
Given I am logged in
228+
And I start the move or copy operation for "welcome.txt"
229+
# No folder was explicitly selected, so the last selected folder is the
230+
# current folder.
231+
And I copy to the last selected folder in the file picker
232+
When I start the move or copy operation for "welcome (copy).txt"
233+
And I copy to the last selected folder in the file picker
234+
Then I see that the file list contains a file named "welcome.txt"
235+
And I see that the file list contains a file named "welcome (copy).txt"
236+
And I see that the file list contains a file named "welcome (copy 2).txt"
237+
143238
Scenario: rename a file with the details view open
144239
Given I am logged in
145240
And I open the details view for "welcome.txt"

tests/acceptance/features/bootstrap/FileListContext.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,48 @@ public static function createNewFolderMenuItemNameInput($fileListAncestor) {
130130
describedAs("Name input in create new folder menu item in file list");
131131
}
132132

133+
/**
134+
* @return Locator
135+
*/
136+
public static function fileListHeader($fileListAncestor) {
137+
return Locator::forThe()->css("thead")->
138+
descendantOf($fileListAncestor)->
139+
describedAs("Header in file list");
140+
}
141+
142+
/**
143+
* @return Locator
144+
*/
145+
public static function selectedFilesActionsMenuButton($fileListAncestor) {
146+
return Locator::forThe()->css(".actions-selected")->
147+
descendantOf(self::fileListHeader($fileListAncestor))->
148+
describedAs("Selected files actions menu button in file list");
149+
}
150+
151+
/**
152+
* @return Locator
153+
*/
154+
public static function selectedFilesActionsMenu() {
155+
return Locator::forThe()->css(".filesSelectMenu")->
156+
describedAs("Selected files actions menu in file list");
157+
}
158+
159+
/**
160+
* @return Locator
161+
*/
162+
private static function selectedFilesActionsMenuItemFor($itemText) {
163+
return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")->
164+
descendantOf(self::selectedFilesActionsMenu())->
165+
describedAs($itemText . " item in selected files actions menu in file list");
166+
}
167+
168+
/**
169+
* @return Locator
170+
*/
171+
public static function moveOrCopySelectedFilesMenuItem() {
172+
return self::selectedFilesActionsMenuItemFor("Move or copy");
173+
}
174+
133175
/**
134176
* @return Locator
135177
*/
@@ -148,6 +190,26 @@ public static function rowForFilePreceding($fileListAncestor, $fileName1, $fileN
148190
describedAs("Row for file $fileName1 preceding $fileName2 in file list");
149191
}
150192

193+
/**
194+
* @return Locator
195+
*/
196+
public static function selectionCheckboxForFile($fileListAncestor, $fileName) {
197+
// Note that the element that the user interacts with is the label, not
198+
// the checbox itself.
199+
return Locator::forThe()->css(".selection label")->
200+
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
201+
describedAs("Selection checkbox for file $fileName in file list");
202+
}
203+
204+
/**
205+
* @return Locator
206+
*/
207+
public static function selectionCheckboxInputForFile($fileListAncestor, $fileName) {
208+
return Locator::forThe()->css(".selection input[type=checkbox]")->
209+
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
210+
describedAs("Selection checkbox input for file $fileName in file list");
211+
}
212+
151213
/**
152214
* @return Locator
153215
*/
@@ -265,6 +327,13 @@ public static function renameMenuItem() {
265327
return self::fileActionsMenuItemFor("Rename");
266328
}
267329

330+
/**
331+
* @return Locator
332+
*/
333+
public static function moveOrCopyMenuItem() {
334+
return self::fileActionsMenuItemFor("Move or copy");
335+
}
336+
268337
/**
269338
* @return Locator
270339
*/
@@ -296,6 +365,24 @@ public function iEnterInTheFolderNamed($folderName) {
296365
$this->actor->find(self::mainLinkForFile($this->fileListAncestor, $folderName), 10)->click();
297366
}
298367

368+
/**
369+
* @Given I select :fileName
370+
*/
371+
public function iSelect($fileName) {
372+
$this->iSeeThatIsNotSelected($fileName);
373+
374+
$this->actor->find(self::selectionCheckboxForFile($this->fileListAncestor, $fileName), 10)->click();
375+
}
376+
377+
/**
378+
* @Given I start the move or copy operation for the selected files
379+
*/
380+
public function iStartTheMoveOrCopyOperationForTheSelectedFiles() {
381+
$this->actor->find(self::selectedFilesActionsMenuButton($this->fileListAncestor), 10)->click();
382+
383+
$this->actor->find(self::moveOrCopySelectedFilesMenuItem(), 2)->click();
384+
}
385+
299386
/**
300387
* @Given I open the details view for :fileName
301388
*/
@@ -325,6 +412,15 @@ public function iRenameTo($fileName1, $fileName2) {
325412
$this->actor->find(self::renameInputForFile($this->fileListAncestor, $fileName1), 10)->setValue($fileName2 . "\r");
326413
}
327414

415+
/**
416+
* @Given I start the move or copy operation for :fileName
417+
*/
418+
public function iStartTheMoveOrCopyOperationFor($fileName) {
419+
$this->actor->find(self::fileActionsMenuButtonForFile($this->fileListAncestor, $fileName), 10)->click();
420+
421+
$this->actor->find(self::moveOrCopyMenuItem(), 2)->click();
422+
}
423+
328424
/**
329425
* @Given I mark :fileName as favorite
330426
*/
@@ -410,13 +506,32 @@ public function iSeeThatTheFileListContainsAFileNamed($fileName) {
410506
PHPUnit_Framework_Assert::assertNotNull($this->actor->find(self::rowForFile($this->fileListAncestor, $fileName), 10));
411507
}
412508

509+
/**
510+
* @Then I see that the file list does not contain a file named :fileName
511+
*/
512+
public function iSeeThatTheFileListDoesNotContainAFileNamed($fileName) {
513+
if (!WaitFor::elementToBeEventuallyNotShown(
514+
$this->actor,
515+
self::rowForFile($this->fileListAncestor, $fileName),
516+
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
517+
PHPUnit_Framework_Assert::fail("The file list still contains a file named $fileName after $timeout seconds");
518+
}
519+
}
520+
413521
/**
414522
* @Then I see that :fileName1 precedes :fileName2 in the file list
415523
*/
416524
public function iSeeThatPrecedesInTheFileList($fileName1, $fileName2) {
417525
PHPUnit_Framework_Assert::assertNotNull($this->actor->find(self::rowForFilePreceding($this->fileListAncestor, $fileName1, $fileName2), 10));
418526
}
419527

528+
/**
529+
* @Then I see that :fileName is not selected
530+
*/
531+
public function iSeeThatIsNotSelected($fileName) {
532+
PHPUnit_Framework_Assert::assertFalse($this->actor->find(self::selectionCheckboxInputForFile($this->fileListAncestor, $fileName), 10)->isChecked());
533+
}
534+
420535
/**
421536
* @Then I see that :fileName is marked as favorite
422537
*/

0 commit comments

Comments
 (0)