| // Checks that the "copy code" button is not triggering JS error and its display | |
| // isn't broken. | |
| include: "utils.goml" | |
| go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" | |
| permissions: ["clipboard-read"] | |
| define-function: ( | |
| "check-copy-button", | |
| [], | |
| block { | |
| // First we ensure that there are no "copy code" currently existing. | |
| assert-count: (".example-wrap .copy-button", 0) | |
| move-cursor-to: ".example-wrap" | |
| assert-count: (".example-wrap .copy-button", 1) | |
| // We now ensure it's only displayed when the example is hovered. | |
| assert-css: (".example-wrap .copy-button", { "visibility": "visible" }) | |
| move-cursor-to: "rustdoc-toolbar #search-button" | |
| assert-css: (".example-wrap .copy-button", { "visibility": "hidden" }) | |
| // Checking that the copy button has the same size as the "copy path" button. | |
| compare-elements-size: ( | |
| "#copy-path", | |
| ".example-wrap:nth-of-type(1) .copy-button", | |
| ["height", "width"], | |
| ) | |
| }, | |
| ) | |
| call-function: ("check-copy-button", {}) | |
| // Checking that the run button and the copy button have the same height and same width. | |
| compare-elements-size: ( | |
| ".example-wrap:nth-of-type(1) .test-arrow", | |
| ".example-wrap:nth-of-type(1) .copy-button", | |
| ["height", "width"], | |
| ) | |
| // ... and the same y position. | |
| compare-elements-position: ( | |
| ".example-wrap:nth-of-type(1) .test-arrow", | |
| ".example-wrap:nth-of-type(1) .copy-button", | |
| ["y"], | |
| ) | |
| store-size: (".example-wrap:nth-of-type(1) .copy-button", { | |
| "height": copy_height, | |
| "width": copy_width, | |
| }) | |
| assert: |copy_height| > 0 && |copy_width| > 0 | |
| // We now check that copying code when line numbers are displayed don't include these line numbers. | |
| // First we ensure that the clipboard is empty. | |
| assert-clipboard: "" | |
| // We make the line numbers appear. | |
| call-function: ("open-settings-menu", {}) | |
| click: "#line-numbers" | |
| wait-for-local-storage: {"rustdoc-line-numbers": "true" } | |
| // We close the settings menu. | |
| call-function: ("close-settings-menu", {}) | |
| // We ensure that there are actually line numbers generated in the DOM. | |
| assert-text: (".example-wrap pre.rust code span[data-nosnippet]", "1") | |
| // We make the copy button appear. | |
| move-cursor-to: ".example-wrap pre.rust code" | |
| wait-for-css: (".example-wrap .button-holder", {"visibility": "visible"}) | |
| // We click on the copy button. | |
| click: ".example-wrap .button-holder .copy-button" | |
| assert-clipboard: 'println!("nothing fancy"); | |
| println!("but with two lines!");' | |
| // Back to UI checks, checking same things for the copy button when there is no run button. | |
| go-to: "file://" + |DOC_PATH| + "/lib2/sub_mod/struct.Foo.html" | |
| call-function: ("check-copy-button", {}) | |
| // Ensure there is no run button. | |
| assert-count: (".example-wrap .test-arrow", 0) | |
| // Check it's the same size without a run button. | |
| assert-size: (".example-wrap:nth-of-type(1) .copy-button", { | |
| "height": |copy_height|, | |
| "width": |copy_width|, | |
| }) |