Skip to content

Commit

Permalink
MDL-33671 core: Remove custom behat selectors
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Nicols <[email protected]>
  • Loading branch information
Peter Dias and andrewnicols committed Mar 4, 2020
1 parent a216d86 commit 06dc3a6
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 67 deletions.
3 changes: 2 additions & 1 deletion files/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public function render_form_filemanager($fm) {
array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'),
array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'),
array('confirmrenamefile', 'repository'), array('newfolder', 'repository'), array('edit', 'moodle'),
['nofilesselected', 'repository'], ['confirmdeleteselectedfile', 'repository']
['nofilesselected', 'repository'], ['confirmdeleteselectedfile', 'repository'],
['selectall', 'moodle'], ['deselectall', 'moodle'], ['selectallornone', 'form'],
)
);
if ($this->page->requires->should_create_one_time_item_now('core_file_managertemplate')) {
Expand Down
15 changes: 9 additions & 6 deletions lib/behat/behat_field_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,23 @@ protected static function get_field_node_type(NodeElement $fieldnode, Session $s
}

// If the type is explictly set on the element pointed to by the label - use it.
if ($type = $fieldnode->getParent()->getAttribute('data-fieldtype')) {
if ($type == 'tags') {
$fieldtype = $fieldnode->getAttribute('data-fieldtype');
if ($fieldtype) {
if ($fieldtype == 'tags') {
return 'autocomplete';
}
return $type;
return $fieldtype;
}

if (!empty($fieldnode->find('xpath', '/ancestor::*[@data-passwordunmaskid]'))) {
return 'passwordunmask';
}

// We look for a parent node with 'felement' class.
if ($class = $fieldnode->getParent()->getAttribute('class')) {
// Fetch the parentnode only once.
$parentnode = $fieldnode->getParent();

// We look for a parent node with 'felement' class.
if ($class = $parentnode->getAttribute('class')) {
if (strstr($class, 'felement') != false) {
// Remove 'felement f' from class value.
return substr($class, 10);
Expand All @@ -246,7 +249,7 @@ protected static function get_field_node_type(NodeElement $fieldnode, Session $s
}
}

return self::get_field_node_type($fieldnode->getParent(), $session);
return self::get_field_node_type($parentnode, $session);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/form/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ M.form_filemanager.init = function(Y, options) {
return this.filemanager.ancestor('.fitem.disabled') != null;
},
getSelectedFiles: function() {
var markedFiles = this.filemanager.all('.mark-for-selection:checked');
var markedFiles = this.filemanager.all('[data-togglegroup=file-selections]:checked');
var filenames = [];
markedFiles.each(function(item) {
var fileinfo = this.options.list.find(function(element) {
Expand Down Expand Up @@ -437,6 +437,7 @@ M.form_filemanager.init = function(Y, options) {
var params = {
selected: Y.JSON.stringify(filenames)
};
dialogOptions.header = M.util.get_string('confirm', 'moodle');
dialogOptions.message = M.util.get_string('confirmdeleteselectedfile', 'repository', filenames.length);
dialogOptions.callbackargs = [params];
dialogOptions.callback = function(params) {
Expand Down Expand Up @@ -846,6 +847,7 @@ M.form_filemanager.init = function(Y, options) {
node.one('.fp-dlg-butcancel').on('click', handle_cancel, this);
}
this.confirm_dlg.dlgopt = dialog_options;
this.confirm_dlg.set('headerContent', dialog_options.header);
this.confirm_dlg_node.one('.fp-dlg-text').setContent(dialog_options.message);
this.confirm_dlg.show();
},
Expand Down
41 changes: 31 additions & 10 deletions repository/filepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,26 @@ YUI.add('moodle-core_filepicker', function(Y) {
*/
var formatCheckbox = function(o) {
var el = Y.Node.create('<div/>');
var checkbox = Y.Node.create('<input/>');
checkbox.setAttribute('type', 'checkbox')
.setAttribute('class', 'mark-for-selection')

var checkbox = Y.Node.create('<input/>')
.setAttribute('type', 'checkbox')
.setAttribute('data-fieldtype', 'checkbox')
.setAttribute('data-fullname', o.data.fullname)
.setAttribute('data-action', 'toggle')
.setAttribute('data-toggle', 'slave')
.setAttribute('data-togglegroup', 'file-selections')
.setAttribute('data-toggle-selectall', 'Select all')
.setAttribute('data-toggle-deselectall', 'Deselectall');
.setAttribute('data-toggle-selectall', M.util.get_string('selectall', 'moodle'))
.setAttribute('data-toggle-deselectall', M.util.get_string('deselectall', 'moodle'));

var checkboxLabel = Y.Node.create('<label>')
.setHTML("Select file '" + o.data.fullname + "'")
.addClass('sr-only')
.setAttrs({
for: checkbox.generateID(),
});

el.appendChild(checkbox);
el.appendChild(checkboxLabel);
return el.getContent();
};
/** sorting function for table view */
Expand Down Expand Up @@ -363,20 +372,32 @@ YUI.add('moodle-core_filepicker', function(Y) {
];

// Generate a checkbox based on toggleall's specification
var checkbox = Y.Node.create('<input/>');
var div = Y.Node.create('<div/>');
checkbox.setAttribute('type', 'checkbox')
.setAttribute('class', 'mark-for-selection')
var checkbox = Y.Node.create('<input/>')
.setAttribute('type', 'checkbox')
// .setAttribute('title', M.util.get_string('selectallornone', 'form'))
.setAttribute('data-action', 'toggle')
.setAttribute('data-toggle', 'master')
.setAttribute('data-togglegroup', 'file-selections');

var checkboxLabel = Y.Node.create('<label>')
.setHTML(M.util.get_string('selectallornone', 'form'))
.addClass('sr-only')
.setAttrs({
for: checkbox.generateID(),
});

div.appendChild(checkboxLabel);
div.appendChild(checkbox);


// Enable the selectable checkboxes
if (options.disablecheckboxes != undefined && !options.disablecheckboxes) {
cols.unshift({
key: "", label: div.getContent(),
allowHTML: true, formatter: formatCheckbox,
key: "",
label: div.getContent(),
allowHTML: true,
formatter: formatCheckbox,
sortable: false
});
}
Expand Down
32 changes: 0 additions & 32 deletions repository/tests/behat/behat_filepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,38 +176,6 @@ public function i_delete_file_from_filemanager($name, $filemanagerelement) {
$okbutton->click();
}

/**
* Marks for deletion the specified file or folder from the specified filemanager field.
*
* @Given /^I mark for deletion "(?P<file_or_folder_name_string>(?:[^"]|\\")*)" from filemanager$/
* @throws ExpectationException Thrown by behat_base::find
* @param string $name
*/
public function i_mark_for_deletion_from_filemanager($name) {
$name = behat_context_helper::escape($name);
$okbutton = $this->find('css', "input.mark-for-selection[data-fullname=$name]");
$okbutton->click();
}

/**
* Executes delete function and confirms delete
*
* @Given /^I confirm deletion$/
* @throws ExpectationException Thrown by behat_base::find
*/
public function i_confirm_deletion() {
$name = get_string('deleteselected');

// Execute the action.
$okbutton = $this->find('css', "a[title='$name']");
$okbutton->click();

// Yes, we are sure.
// Using xpath + click instead of pressButton as 'Ok' it is a common string.
$okbutton = $this->find('css', 'div.fp-dlg button.fp-dlg-butconfirm');
$okbutton->click();
}

/**
* Makes sure user can see the exact number of elements (files in folders) in the filemanager.
*
Expand Down
70 changes: 53 additions & 17 deletions repository/tests/behat/delete_files.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,72 @@ Feature: Delete files and folders from the file manager
Given I log in as "admin"
And I follow "Manage private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I create "Delete me" folder in "Files" filemanager
And I create "Delete me later" folder in "Files" filemanager
And I press "Save changes"
And I follow "Manage private files"
And I click on "[title='Display folder with file details']" "css_element"
And I mark for deletion "empty.txt" from filemanager
And I confirm deletion
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
When I click on "Delete selected" "link"
Then I should see "Are you sure you want to delete the selected 1 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "empty.txt"
And I press "Save changes"
But I should see "Delete me later"
When I press "Save changes"
And I follow "Manage private files"
Then I should not see "empty.txt"
And I mark for deletion "Delete me" from filemanager
And I confirm deletion
Then I should not see "Delete me"
And I press "Save changes"
And I should not see "Delete me"
But I should see "Delete me later"
And I set the field "Select file 'Delete me later'" to "1"
And I click on "Delete selected" "link"
And I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me later"
When I press "Save changes"
Then I should not see "Delete me later"

@javascript
Scenario: Delete a file and a folder using bulk functionality (multiple)
Given I log in as "admin"
And I follow "Manage private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I create "Delete me" folder in "Files" filemanager
And I create "Do not delete me" folder in "Files" filemanager
And I press "Save changes"
And I follow "Manage private files"
And I click on "[title='Display folder with file details']" "css_element"
And I mark for deletion "empty.txt" from filemanager
And I mark for deletion "Delete me" from filemanager
And I confirm deletion
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
And I set the field "Select file 'Delete me'" to "1"
When I click on "Delete selected" "link"
Then I should see "Are you sure you want to delete the selected 2 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me"
Then I should not see "empty.txt"
And I should not see "empty.txt"
But I should see "Do not delete me"
When I press "Save changes"
Then I should not see "Delete me" in the "Private files" "block"
And I should not see "empty.txt" in the "Private files" "block"
But I should see "Do not delete me" in the "Private files" "block"

@javascript
Scenario: Delete files using the select all checkbox
Given I log in as "admin"
And I follow "Manage private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I create "Delete me" folder in "Files" filemanager
And I create "Delete me too" folder in "Files" filemanager
And I press "Save changes"
And I should not see "Delete me"
Then I should not see "empty.txt"
And I follow "Manage private files"
And I click on "Display folder with file details" "link"
When I set the field "Select all/none" to "1"
Then the following fields match these values:
| Select file 'empty.txt' | 1 |
| Select file 'Delete me' | 1 |
| Select file 'Delete me too' | 1 |
When I click on "Delete selected" "link"
Then I should see "Are you sure you want to delete the selected 3 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me"
And I should not see "empty.txt"
And I should not see "Delete me too"
When I press "Save changes"
Then I should not see "Delete me" in the "Private files" "block"
And I should not see "empty.txt" in the "Private files" "block"
But I should not see "Delete me too" in the "Private files" "block"

0 comments on commit 06dc3a6

Please sign in to comment.