| // Checks that the setting "Directly go to item in search if there is only one result " is working |
| // as expected. |
| |
| include: "utils.goml" |
| |
| define-function: ( |
| "check-setting", |
| [storage_value, setting_attribute_value], |
| block { |
| assert-local-storage: {"rustdoc-go-to-only-result": |storage_value|} |
| call-function: ("open-settings-menu", {}) |
| assert-property: ("#go-to-only-result", {"checked": |setting_attribute_value|}) |
| } |
| ) |
| |
| go-to: "file://" + |DOC_PATH| + "/lib2/index.html" |
| |
| call-function: ("check-setting", { |
| "storage_value": null, |
| "setting_attribute_value": "false", |
| }) |
| |
| // By default, the search doesn't automatically go to the page if there is only one result. |
| go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams" |
| // It will timeout if the setting isn't working. |
| wait-for: "#search" |
| assert-document-property: ({"URL": "/lib2/index.html"}, CONTAINS) |
| |
| // Now we change its value. |
| call-function: ("open-settings-menu", {}) |
| click: "#go-to-only-result" |
| assert-local-storage: {"rustdoc-go-to-only-result": "true"} |
| |
| go-to: "file://" + |DOC_PATH| + "/lib2/index.html" |
| // We enter it into the search. |
| click: "#search-button" |
| wait-for: "#alternative-display .search-input" |
| write-into: (".search-input", "HasALongTraitWithParams") |
| wait-for-document-property: {"title": "HasALongTraitWithParams in lib2 - Rust"} |
| assert-window-property: ({"location"."pathname": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH) |
| |
| // Regression test for <https://github.com/rust-lang/rust/issues/112676>. |
| // If "go-to-only-result" is enabled and you go back to history, it should not lead you back to the |
| // page result again automatically. |
| history-go-back: |
| wait-for-document-property: {"title": "lib2 - Rust"} |
| assert-window-property: ({"location"."pathname": "/lib2/index.html"}, ENDS_WITH) |
| |
| // We try again to see if it goes to the only result |
| go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams" |
| wait-for-document-property: {"title": "HasALongTraitWithParams in lib2 - Rust"} |
| assert-document-property: ({"URL": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH) |
| |
| // We check the settings |
| call-function: ("check-setting", { |
| "storage_value": "true", |
| "setting_attribute_value": "true", |
| }) |
| |
| // And now we re-disable the setting. |
| click: "#go-to-only-result" |
| assert-local-storage: {"rustdoc-go-to-only-result": "false"} |
| |
| go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams" |
| // It will timeout if the setting isn't working. |
| wait-for: "#search" |
| assert-document-property: ({"URL": "/lib2/index.html"}, CONTAINS) |
| |
| // And we check everything is back the way it was before. |
| call-function: ("check-setting", { |
| "storage_value": "false", |
| "setting_attribute_value": "false", |
| }) |
| |
| define-function: ( |
| "search-multiple-results", |
| [location], |
| block { |
| // We wait for the search to be done. |
| wait-for: ".search-form" |
| // We ensure the page didn't change. |
| assert-window-property: {"location"."pathname": |location|} |
| // We ensure that there is more than 0 results. |
| wait-for-text: ("#search-tabs > button:nth-child(1) .count", "(2)", CONTAINS) |
| wait-for-text: ("#search-tabs > button:nth-child(2) .count", "(1)", CONTAINS) |
| wait-for-text: ("#search-tabs > button:nth-child(3) .count", "(0)", CONTAINS) |
| }, |
| ) |
| |
| // This is a regression test to ensure that it works when the setting is switched in-between. It |
| // could be reproduced by: |
| // 1. Doing a search (with "in parameters" or "in return types" having exactly one result) |
| // 2. Enabling the setting to true. |
| // 3. Reloading the page. |
| |
| // First we go to a different page. |
| go-to: "file://" + |DOC_PATH| + "/lib2/index.html" |
| |
| // The setting should be disabled. |
| assert-local-storage-false: {"rustdoc-go-to-only-result": "true"} |
| store-window-property: {"location"."pathname": location} |
| click: "#search-button" |
| wait-for: "#alternative-display .search-input" |
| write-into: (".search-input", "Whitespace") |
| call-function: ("search-multiple-results", {"location": |location|}) |
| |
| // We now toggle the setting and reload the page. |
| call-function: ("open-settings-menu", {}) |
| click: "#go-to-only-result" |
| assert-local-storage: {"rustdoc-go-to-only-result": "true"} |
| |
| reload: |
| call-function: ("search-multiple-results", {"location": |location|}) |