From df9fea24a58eba9476aaeccc350441634eaf5eae Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 14 Jun 2022 10:59:01 +0200 Subject: [PATCH 1/2] Fix expand/collapse on source viewer sidebar folders --- src/librustdoc/html/static/js/source-script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 58c036e0b3c..14d8a942977 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -32,10 +32,10 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { fullPath += elem["name"] + "/"; name.onclick = () => { - if (hasClass(this, "expand")) { - removeClass(this, "expand"); + if (hasClass(name, "expand")) { + removeClass(name, "expand"); } else { - addClass(this, "expand"); + addClass(name, "expand"); } }; name.innerText = elem["name"]; From a70c14aecca90e29417ab3c9b9dcbf0631efae79 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 14 Jun 2022 11:21:28 +0200 Subject: [PATCH 2/2] Add GUI test for sidebar items expand/collapse --- src/test/rustdoc-gui/source-code-page.goml | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml index 509739c9f29..188b2605f0f 100644 --- a/src/test/rustdoc-gui/source-code-page.goml +++ b/src/test/rustdoc-gui/source-code-page.goml @@ -1,4 +1,4 @@ -// Checks that the interactions with the source code pages are workined as expected. +// Checks that the interactions with the source code pages are working as expected. goto: file://|DOC_PATH|/src/test_docs/lib.rs.html // Check that we can click on the line number. click: ".line-numbers > span:nth-child(4)" // This is the span for line 4. @@ -27,3 +27,26 @@ assert-position: ("//*[@id='1']", {"x": 104, "y": 103}) // We click on the left of the "1" span but still in the "line-number" `
`.
 click: (103, 103)
 assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
+
+// Checking the source code sidebar.
+
+// First we "open" it.
+click: "#sidebar-toggle"
+assert: ".sidebar.expanded"
+
+// We check that the first entry of the sidebar is collapsed (which, for whatever reason,
+// is number 2 and not 1...).
+assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name"})
+assert-text: ("#source-sidebar .name:nth-child(2)", "implementors")
+// We also check its children are hidden too.
+assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "none"})
+// We now click on it.
+click: "#source-sidebar .name:nth-child(2)"
+assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name expand"})
+// Checking that its children are displayed as well.
+assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "block"})
+
+// And now we collapse it again.
+click: "#source-sidebar .name:nth-child(2)"
+assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name"})
+assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "none"})