|
| 1 | +// This test checks the position of the `i` for the notable traits. |
| 2 | +include: "utils.goml" |
| 3 | +go-to: "file://" + |DOC_PATH| + "/test_docs/struct.NotableStructWithLongName.html" |
| 4 | +show-text: true |
| 5 | + |
| 6 | +define-function: ( |
| 7 | + "check-notable-tooltip-position", |
| 8 | + [x, i_x], |
| 9 | + block { |
| 10 | + // Checking they have the same y position. |
| 11 | + compare-elements-position-near: ( |
| 12 | + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", |
| 13 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 14 | + {"y": 1}, |
| 15 | + ) |
| 16 | + // Checking they don't have the same x position. |
| 17 | + compare-elements-position-false: ( |
| 18 | + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", |
| 19 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 20 | + ["x"], |
| 21 | + ) |
| 22 | + // The `i` should be *after* the type. |
| 23 | + assert-position: ( |
| 24 | + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", |
| 25 | + {"x": |x|}, |
| 26 | + ) |
| 27 | + assert-position: ( |
| 28 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 29 | + {"x": |i_x|}, |
| 30 | + ) |
| 31 | + }, |
| 32 | +) |
| 33 | + |
| 34 | +define-function: ( |
| 35 | + "check-notable-tooltip-position-complete", |
| 36 | + [x, i_x, popover_x], |
| 37 | + block { |
| 38 | + call-function: ("check-notable-tooltip-position", {"x": |x|, "i_x": |i_x|}) |
| 39 | + assert-count: ("//*[@class='tooltip popover']", 0) |
| 40 | + click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 41 | + assert-count: ("//*[@class='tooltip popover']", 1) |
| 42 | + wait-for-position: ( |
| 43 | + "//*[@class='tooltip popover']", |
| 44 | + {"x": |popover_x|} |
| 45 | + ) |
| 46 | + compare-elements-position-near: ( |
| 47 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 48 | + "//*[@class='tooltip popover']", |
| 49 | + {"y": 30} |
| 50 | + ) |
| 51 | + compare-elements-position-false: ( |
| 52 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 53 | + "//*[@class='tooltip popover']", |
| 54 | + ["x"] |
| 55 | + ) |
| 56 | + click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 57 | + move-cursor-to: "//h1" |
| 58 | + assert-count: ("//*[@class='tooltip popover']", 0) |
| 59 | + }, |
| 60 | +) |
| 61 | + |
| 62 | +// We start with a wide screen. |
| 63 | +set-window-size: (1100, 600) |
| 64 | +call-function: ("check-notable-tooltip-position-complete", { |
| 65 | + "x": 682, |
| 66 | + "i_x": 960, |
| 67 | + "popover_x": 468, |
| 68 | +}) |
| 69 | + |
| 70 | +// Now only the `i` should be on the next line. |
| 71 | +set-window-size: (1055, 600) |
| 72 | +compare-elements-position-false: ( |
| 73 | + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", |
| 74 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 75 | + ["y", "x"], |
| 76 | +) |
| 77 | + |
| 78 | +// Now both the `i` and the struct name should be on the next line. |
| 79 | +set-window-size: (980, 600) |
| 80 | +call-function: ("check-notable-tooltip-position", { |
| 81 | + "x": 250, |
| 82 | + "i_x": 528, |
| 83 | +}) |
| 84 | + |
| 85 | +go-to: "file://" + |DOC_PATH| + "/test_docs/struct.NotableStructWithLongName.html" |
| 86 | +// This is needed to ensure that the text color is computed. |
| 87 | +show-text: true |
| 88 | + |
| 89 | +// Now check the colors. |
| 90 | +define-function: ( |
| 91 | + "check-colors", |
| 92 | + [theme, header_color, content_color, type_color, trait_color, link_color], |
| 93 | + block { |
| 94 | + call-function: ("switch-theme", {"theme": |theme|}) |
| 95 | + |
| 96 | + assert-css: ( |
| 97 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 98 | + {"color": |content_color|}, |
| 99 | + ALL, |
| 100 | + ) |
| 101 | + |
| 102 | + move-cursor-to: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 103 | + wait-for-count: (".tooltip.popover", 1) |
| 104 | + |
| 105 | + assert-css: ( |
| 106 | + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", |
| 107 | + {"color": |link_color|}, |
| 108 | + ALL, |
| 109 | + ) |
| 110 | + |
| 111 | + assert-css: ( |
| 112 | + ".tooltip.popover h3", |
| 113 | + {"color": |header_color|}, |
| 114 | + ALL, |
| 115 | + ) |
| 116 | + assert-css: ( |
| 117 | + ".tooltip.popover pre", |
| 118 | + {"color": |content_color|}, |
| 119 | + ALL, |
| 120 | + ) |
| 121 | + assert-css: ( |
| 122 | + ".tooltip.popover pre a.struct", |
| 123 | + {"color": |type_color|}, |
| 124 | + ALL, |
| 125 | + ) |
| 126 | + assert-css: ( |
| 127 | + ".tooltip.popover pre a.trait", |
| 128 | + {"color": |trait_color|}, |
| 129 | + ALL, |
| 130 | + ) |
| 131 | + }, |
| 132 | +) |
| 133 | + |
| 134 | +call-function: ( |
| 135 | + "check-colors", |
| 136 | + { |
| 137 | + "theme": "ayu", |
| 138 | + "link_color": "#39afd7", |
| 139 | + "content_color": "#e6e1cf", |
| 140 | + "header_color": "#fff", |
| 141 | + "type_color": "#ffa0a5", |
| 142 | + "trait_color": "#39afd7", |
| 143 | + }, |
| 144 | +) |
| 145 | + |
| 146 | +call-function: ( |
| 147 | + "check-colors", |
| 148 | + { |
| 149 | + "theme": "dark", |
| 150 | + "link_color": "#d2991d", |
| 151 | + "content_color": "#ddd", |
| 152 | + "header_color": "#ddd", |
| 153 | + "type_color": "#2dbfb8", |
| 154 | + "trait_color": "#b78cf2", |
| 155 | + }, |
| 156 | +) |
| 157 | + |
| 158 | +call-function: ( |
| 159 | + "check-colors", |
| 160 | + { |
| 161 | + "theme": "light", |
| 162 | + "link_color": "#3873ad", |
| 163 | + "content_color": "black", |
| 164 | + "header_color": "black", |
| 165 | + "type_color": "#ad378a", |
| 166 | + "trait_color": "#6e4fc9", |
| 167 | + }, |
| 168 | +) |
| 169 | + |
| 170 | +// Checking on mobile now. |
| 171 | +set-window-size: (650, 600) |
| 172 | +wait-for-size: ("body", {"width": 650}) |
| 173 | +call-function: ("check-notable-tooltip-position-complete", { |
| 174 | + "x": 26, |
| 175 | + "i_x": 305, |
| 176 | + "popover_x": 0, |
| 177 | +}) |
| 178 | + |
| 179 | +reload: |
| 180 | + |
| 181 | +// Check that pressing escape works |
| 182 | +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 183 | +move-cursor-to: "//*[@class='tooltip popover']" |
| 184 | +assert-count: ("//*[@class='tooltip popover']", 1) |
| 185 | +press-key: "Escape" |
| 186 | +assert-count: ("//*[@class='tooltip popover']", 0) |
| 187 | +assert: "#method\.create_an_iterator_from_read .tooltip:focus" |
| 188 | + |
| 189 | +// Check that clicking outside works. |
| 190 | +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 191 | +assert-count: ("//*[@class='tooltip popover']", 1) |
| 192 | +click: ".main-heading h1" |
| 193 | +assert-count: ("//*[@class='tooltip popover']", 0) |
| 194 | +assert-false: "#method\.create_an_iterator_from_read .tooltip:focus" |
| 195 | + |
| 196 | +// Check that pressing tab over and over works. |
| 197 | +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 198 | +move-cursor-to: "//*[@class='tooltip popover']" |
| 199 | +assert-count: ("//*[@class='tooltip popover']", 1) |
| 200 | +press-key: "Tab" |
| 201 | +press-key: "Tab" |
| 202 | +press-key: "Tab" |
| 203 | +press-key: "Tab" |
| 204 | +press-key: "Tab" |
| 205 | +press-key: "Tab" |
| 206 | +press-key: "Tab" |
| 207 | +assert-count: ("//*[@class='tooltip popover']", 0) |
| 208 | +assert: "#method\.create_an_iterator_from_read .tooltip:focus" |
| 209 | + |
| 210 | +define-function: ( |
| 211 | + "setup-popup", |
| 212 | + [], |
| 213 | + block { |
| 214 | + store-window-property: {"scrollY": scroll} |
| 215 | + click: "#method\.create_an_iterator_from_read .fn" |
| 216 | + // We ensure that the scroll position changed. |
| 217 | + assert-window-property-false: {"scrollY": |scroll|} |
| 218 | + // Store the new position. |
| 219 | + store-window-property: {"scrollY": scroll} |
| 220 | + click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 221 | + wait-for: "//*[@class='tooltip popover']" |
| 222 | + click: ".main-heading h1" |
| 223 | + } |
| 224 | +) |
| 225 | + |
| 226 | +// Now we check that the focus isn't given back to the wrong item when opening |
| 227 | +// another popover. |
| 228 | +call-function: ("setup-popup", {}) |
| 229 | +click: ".main-heading h1" |
| 230 | +// We ensure we didn't come back to the previous focused item. |
| 231 | +assert-window-property-false: {"scrollY": |scroll|} |
| 232 | + |
| 233 | +// Same but with Escape handling. |
| 234 | +call-function: ("setup-popup", {}) |
| 235 | +press-key: "Escape" |
| 236 | +// We ensure we didn't come back to the previous focused item. |
| 237 | +assert-window-property-false: {"scrollY": |scroll|} |
| 238 | + |
| 239 | +// Opening the mobile sidebar should close the popover. |
| 240 | +set-window-size: (650, 600) |
| 241 | +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 242 | +assert-count: ("//*[@class='tooltip popover']", 1) |
| 243 | +click: ".sidebar-menu-toggle" |
| 244 | +assert: "//*[@class='sidebar shown']" |
| 245 | +assert-count: ("//*[@class='tooltip popover']", 0) |
| 246 | +assert-false: "#method\.create_an_iterator_from_read .tooltip:focus" |
| 247 | + |
| 248 | +// Also check the focus handling for the settings button. |
| 249 | +set-window-size: (1100, 600) |
| 250 | +reload: |
| 251 | +assert-count: ("//*[@class='tooltip popover']", 0) |
| 252 | +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" |
| 253 | +wait-for-count: ("//*[@class='tooltip popover']", 1) |
| 254 | +call-function: ("open-settings-menu", {}) |
| 255 | +wait-for-count: ("//*[@class='tooltip popover']", 0) |
| 256 | +assert-false: "#method\.create_an_iterator_from_read .tooltip:focus" |
0 commit comments