|
30 | 30 | }, |
31 | 31 | linkpreviews: { |
32 | 32 | enabled: true, |
| 33 | + selector: null, |
33 | 34 | }, |
34 | 35 | }, |
35 | 36 | }; |
|
40 | 41 | server.restore(); |
41 | 42 |
|
42 | 43 | document.querySelectorAll("div.tooltip").forEach((el) => el.remove()); |
| 44 | + document |
| 45 | + .querySelectorAll(".link-preview") |
| 46 | + .forEach((el) => el.classList.remove("link-preview")); |
43 | 47 | }); |
44 | 48 |
|
45 | 49 | describe("Link previews tests", () => { |
|
61 | 65 | expect(linkExternal).to.not.have.class("link-preview"); |
62 | 66 | }); |
63 | 67 |
|
| 68 | + it("use CSS selector from API", async () => { |
| 69 | + config.addons.linkpreviews.selector = "section p a"; |
| 70 | + let linkInternal = document.querySelector("#linkpreview-internal"); |
| 71 | + let linkExternal = document.querySelector("#linkpreview-external"); |
| 72 | + let linkCustom = document.querySelector("#linkpreview-custom"); |
| 73 | + |
| 74 | + expect(linkInternal).to.not.have.class("link-preview"); |
| 75 | + expect(linkExternal).to.not.have.class("link-preview"); |
| 76 | + expect(linkCustom).to.not.have.class("link-preview"); |
| 77 | + |
| 78 | + const addon = new linkpreviews.LinkPreviewsAddon(config); |
| 79 | + const element = document.querySelector("readthedocs-linkpreviews"); |
| 80 | + await elementUpdated(element); |
| 81 | + |
| 82 | + // Custom link should have a specific class |
| 83 | + expect(linkCustom).to.have.class("link-preview"); |
| 84 | + |
| 85 | + // Intenrnal and external link shouldn't be previewed |
| 86 | + expect(linkExternal).to.not.have.class("link-preview"); |
| 87 | + expect(linkInternal).to.not.have.class("link-preview"); |
| 88 | + }); |
| 89 | + |
64 | 90 | it("trigger mouseenter event without response to show Loading... tooltip", async () => { |
65 | 91 | const addon = new linkpreviews.LinkPreviewsAddon(config); |
66 | 92 | const element = document.querySelector("readthedocs-linkpreviews"); |
|
150 | 176 | >. |
151 | 177 | </p> |
152 | 178 | </main> |
| 179 | + |
| 180 | + <!-- Add a link _outside_ main to use with a custom CSS selector --> |
| 181 | + <section> |
| 182 | + <p> |
| 183 | + Link with |
| 184 | + <a id="linkpreview-custom" href="http://localhost:8000/custom.html" |
| 185 | + >custom CSS selector</a |
| 186 | + >. |
| 187 | + </p> |
| 188 | + </section> |
153 | 189 | </body> |
154 | 190 | </html> |
0 commit comments