|
1 | 1 | import { describe, expect, it, vi } from "@test/unit"; |
2 | 2 | import { mount as vueMount } from "@vue/test-utils"; |
| 3 | +import html from "@/panel/html"; |
3 | 4 | import Item from "./Item.vue"; |
4 | 5 |
|
5 | 6 | function mount(props = {}, attrs = {}) { |
@@ -85,8 +86,15 @@ describe("Item.vue", () => { |
85 | 86 | }); |
86 | 87 |
|
87 | 88 | describe("text prop", () => { |
88 | | - it("renders the text as HTML", () => { |
| 89 | + it("escapes a plain string", () => { |
89 | 90 | const wrapper = mount({ text: "<b>Hello</b>" }); |
| 91 | + expect(wrapper.find(".k-item-title span").html()).toBe( |
| 92 | + "<span><b>Hello</b></span>" |
| 93 | + ); |
| 94 | + }); |
| 95 | + |
| 96 | + it("renders trusted HTML as-is", () => { |
| 97 | + const wrapper = mount({ text: html("<b>Hello</b>") }); |
90 | 98 | expect(wrapper.find(".k-item-title span").html()).toBe( |
91 | 99 | "<span><b>Hello</b></span>" |
92 | 100 | ); |
@@ -177,18 +185,27 @@ describe("Item.vue", () => { |
177 | 185 | ); |
178 | 186 | }); |
179 | 187 |
|
180 | | - it("strips tags", () => { |
| 188 | + it("keeps markup a plain string renders as visible text", () => { |
181 | 189 | const wrapper = mount({ text: "<b>Hello</b>" }); |
182 | | - expect(wrapper.find(".k-item-title").attributes("title")).toBe("Hello"); |
| 190 | + expect(wrapper.find(".k-item-title").attributes("title")).toBe( |
| 191 | + "<b>Hello</b>" |
| 192 | + ); |
183 | 193 | }); |
184 | 194 |
|
185 | | - it("unescapes entities", () => { |
186 | | - const wrapper = mount({ text: "Tom & Jerry" }); |
| 195 | + it("strips authored tags from trusted HTML", () => { |
| 196 | + const wrapper = mount({ text: html("<b>Tom & Jerry</b>") }); |
187 | 197 | expect(wrapper.find(".k-item-title").attributes("title")).toBe( |
188 | 198 | "Tom & Jerry" |
189 | 199 | ); |
190 | 200 | }); |
191 | 201 |
|
| 202 | + it("keeps escaped tags, which render as visible text", () => { |
| 203 | + const wrapper = mount({ text: html("Using <div> tags") }); |
| 204 | + expect(wrapper.find(".k-item-title").attributes("title")).toBe( |
| 205 | + "Using <div> tags" |
| 206 | + ); |
| 207 | + }); |
| 208 | + |
192 | 209 | it("trims surrounding whitespace", () => { |
193 | 210 | const wrapper = mount({ text: " Kirby " }); |
194 | 211 | expect(wrapper.find(".k-item-title").attributes("title")).toBe("Kirby"); |
|
0 commit comments