|
| 1 | +// This test ensures that the image zoom-in/zoom-out works as expected. |
| 2 | + |
| 3 | +define-function: ( |
| 4 | + "check-image-not-zoomed-in", |
| 5 | + [], |
| 6 | + block { |
| 7 | + // The "zoomed in" image should not be displayed. |
| 8 | + assert-css: (".checkbox-label > .img-wrapper", {"display": "none"}) |
| 9 | + // The cursor for the image should be "zoom-in". |
| 10 | + assert-css: (".checkbox-label > img", {"cursor": "zoom-in"}) |
| 11 | + }, |
| 12 | +) |
| 13 | + |
| 14 | +define-function: ( |
| 15 | + "check-image-zoomed-in", |
| 16 | + [], |
| 17 | + block { |
| 18 | + // The image wrapper should now be displayed and have a "zoom-out" cursor. |
| 19 | + assert-css: (".checkbox-label > .img-wrapper", {"display": "flex", "cursor": "zoom-out"}) |
| 20 | + // Same for the image it contains. |
| 21 | + assert-css: ( |
| 22 | + ".checkbox-label > .img-wrapper img", |
| 23 | + {"display": "block", "cursor": "zoom-out"}, |
| 24 | + ) |
| 25 | + }, |
| 26 | +) |
| 27 | + |
| 28 | +go-to: |DOC_PATH| + "basic/index.html" |
| 29 | +show-text: true |
| 30 | +call-function: ("check-image-not-zoomed-in", {}) |
| 31 | + |
| 32 | +// We click on the image to "zoom in". |
| 33 | +click: ".checkbox-label > img" |
| 34 | +call-function: ("check-image-zoomed-in", {}) |
| 35 | + |
| 36 | +// We click on the wrapper to "zoom out". |
| 37 | +click: ".checkbox-label > img" |
| 38 | +// We check that everything is back to the previous state. |
| 39 | +call-function: ("check-image-not-zoomed-in", {}) |
| 40 | + |
| 41 | +// We test that the "escape" key also hides the "zoomed in" image. |
| 42 | +// We click on the image to "zoom in". |
| 43 | +click: ".checkbox-label > img" |
| 44 | +call-function: ("check-image-zoomed-in", {}) |
| 45 | +press-key: "Escape" |
| 46 | +// We check that everything is back to the previous state. |
| 47 | +call-function: ("check-image-not-zoomed-in", {}) |
| 48 | + |
| 49 | +// We test that we can zoom in and out using only the keyboard. |
| 50 | +// First we focus on the link just before the image we want to zoom in. |
| 51 | +focus: "a[href='a']" |
| 52 | +assert: "a[href='a']:focus" |
| 53 | +press-key: "Tab" |
| 54 | +// We check that the checkbox to "zoom in" is focused. |
| 55 | +assert: ".checkbox-img:focus" |
| 56 | +// We check that the image about to be zoomed in has the outline. |
| 57 | +store-css: (".checkbox-img:focus", {"outline": outline}) |
| 58 | +// Because we're using "auto" to match the system outline, we cannot check the whole value directly |
| 59 | +// so instead we check if "auto" is present. |
| 60 | +assert-variable: (outline, "auto", CONTAINS) |
| 61 | +// We zoom in. |
| 62 | +press-key: "Space" |
| 63 | +call-function: ("check-image-zoomed-in", {}) |
| 64 | +// We press the key again to zoom out. |
| 65 | +press-key: "Space" |
| 66 | +call-function: ("check-image-not-zoomed-in", {}) |
| 67 | +// We now check it works with the "Escape" key as well. |
| 68 | +press-key: "Space" |
| 69 | +call-function: ("check-image-zoomed-in", {}) |
| 70 | +press-key: "Escape" |
| 71 | +call-function: ("check-image-not-zoomed-in", {}) |
| 72 | + |
| 73 | +// Now we check that images in links (in `<a>` elements) don't get the "zoom-in" feature enabled. |
| 74 | +// There is only one zoomable image. |
| 75 | +assert-count: ("main .checkbox-img", 1) |
| 76 | +// We should have 5 images: 4 "normal" ones visible in the rendered book and one hidden which is |
| 77 | +// used only for the "zoom-in" feature. |
| 78 | +assert-count: ("main img", 5) |
| 79 | +// We check exact paths to ensure the 5 `<img>` are different. |
| 80 | +assert: ("main > p > label.checkbox-label > img:nth-of-type(1)") |
| 81 | +assert: ("main > p > label.checkbox-label > span.img-wrapper > img") |
| 82 | +assert: ("main > p:nth-of-type(1) > a:nth-of-type(1) > img") |
| 83 | +assert: ("main > p:nth-of-type(1) > a:nth-of-type(2) > img") |
| 84 | +assert: ("main > p:not(:nth-of-type(2)) > a > img") |
| 85 | + |
| 86 | +// The cursor for the image in link should not have "zoom-in". |
| 87 | +assert-css: ("main > p > a > img", {"cursor": "pointer"}) |
0 commit comments