Skip to content

Commit

Permalink
Merge branch 'MDL-78728' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 authored and ilyatregubov committed Sep 15, 2023
2 parents 62a91c8 + d005176 commit 632e603
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/form/amd/build/collapsesections.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/form/amd/build/collapsesections.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/form/amd/src/collapsesections.js
Expand Up @@ -26,6 +26,7 @@ import $ from 'jquery';
import Pending from 'core/pending';

const SELECTORS = {
FORM: '.mform',
FORMHEADER: '.fheader',
FORMCONTAINER: 'fieldset > .fcontainer',
};
Expand All @@ -45,8 +46,9 @@ export const init = collapsesections => {
// All jQuery in this code can be replaced when MDL-71979 is integrated (move to Bootstrap 5).
const pendingPromise = new Pending('core_form/collapsesections');
const collapsemenu = document.querySelector(collapsesections);
const formParent = collapsemenu.closest('form');
const formContainers = formParent?.querySelectorAll(SELECTORS.FORMCONTAINER) || [];

const formParent = collapsemenu.closest(SELECTORS.FORM);
const formContainers = formParent.querySelectorAll(SELECTORS.FORMCONTAINER);

collapsemenu.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
Expand Down Expand Up @@ -84,7 +86,7 @@ export const init = collapsesections => {
});

// Ensure collapse menu button adds aria-controls attribute referring to each collapsible element.
const collapseElements = $(SELECTORS.FORMHEADER);
const collapseElements = formParent.querySelectorAll(SELECTORS.FORMHEADER);
const collapseElementIds = [...collapseElements].map((element, index) => {
element.id = element.id || `collapseElement-${index}`;
return element.id;
Expand Down
38 changes: 17 additions & 21 deletions lib/tests/behat/readonlyform.feature
Expand Up @@ -6,27 +6,23 @@ Feature: Read-only forms should work

@javascript
Scenario: Shortforms expand collapsing should work for read-only forms - one-section form
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| label | L1 | <a href="../lib/tests/fixtures/readonlyform.php?sections=1">Fixture link</a> | C1 | label1 |
Given I am on the "C1" "Course" page logged in as "admin"
And I click on "Fixture link" "link" in the "region-main" "region"
When I expand all fieldsets
Then the field "Name" matches value "Important information"
Given I log in as "admin"
And I visit "/lib/tests/fixtures/readonlyform.php?sections=1"
When I press "First section"
Then "Name" "field" should be visible
And the field "Name" matches value "Important information"
And I press "First section"
And "Name" "field" should not be visible

@javascript
Scenario: Shortforms expand collapsing should work for read-only forms - two-section form
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| label | L1 | <a href="../lib/tests/fixtures/readonlyform.php?sections=2">Fixture link</a> | C1 | label1 |
Given I am on the "C1" "Course" page logged in as "admin"
And I click on "Fixture link" "link" in the "region-main" "region"
When I expand all fieldsets
Then the field "Name" matches value "Important information"
Then the field "Other" matches value "Other information"
Given I log in as "admin"
And I visit "/lib/tests/fixtures/readonlyform.php?sections=2"
When I press "Expand all"
Then "Name" "field" should be visible
And the field "Name" matches value "Important information"
And "Other" "field" should be visible
And the field "Other" matches value "Other information"
And I press "Collapse all"
And "Name" "field" should not be visible
And "Other" "field" should not be visible

0 comments on commit 632e603

Please sign in to comment.