-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): support inline markdown in
AnnotatedText
- WF-169
Use `BaseMarkdown` in `CoreAnnotatedText` to support inline markdown syntax. I also reworked a bit `BaseMarkdown` to have an inline mode.
- Loading branch information
Showing
4 changed files
with
119 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { beforeEach, describe, expect, it, Mock, vi } from "vitest"; | ||
import { flushPromises, shallowMount } from "@vue/test-utils"; | ||
import VueDOMPurifyHTML from "vue-dompurify-html"; | ||
import BaseMarkdown from "./BaseMarkdown.vue"; | ||
import { parse, parseInline } from "marked"; | ||
|
||
vi.mock("marked", () => ({ | ||
parse: vi.fn().mockImplementation((v) => `<div>${v}</div>`), | ||
parseInline: vi.fn().mockImplementation((v) => `<span>${v}</span>`), | ||
})); | ||
|
||
describe("BaseMarkdown", () => { | ||
const rawText = "# hello\nI'm **MD** "; | ||
|
||
beforeEach(() => { | ||
(parse as unknown as Mock).mockClear(); | ||
(parseInline as unknown as Mock).mockClear(); | ||
}); | ||
|
||
it("should render markdown as block", async () => { | ||
const wrapper = shallowMount(BaseMarkdown, { | ||
props: { rawText }, | ||
global: { plugins: [VueDOMPurifyHTML] }, | ||
}); | ||
await flushPromises(); | ||
expect(wrapper.element).toMatchSnapshot(); | ||
expect(parse).toHaveBeenCalledOnce(); | ||
|
||
wrapper.setProps({ rawText: "updated" }); | ||
await flushPromises(); | ||
expect(parse).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it("should render markdown as inline", async () => { | ||
const wrapper = shallowMount(BaseMarkdown, { | ||
props: { rawText, inline: true }, | ||
global: { plugins: [VueDOMPurifyHTML] }, | ||
}); | ||
await flushPromises(); | ||
expect(wrapper.element).toMatchSnapshot(); | ||
expect(parseInline).toHaveBeenCalledOnce(); | ||
|
||
wrapper.setProps({ rawText: "updated" }); | ||
await flushPromises(); | ||
expect(parseInline).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/ui/src/components/core/base/__snapshots__/BaseMarkdown.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`BaseMarkdown > should render markdown as block 1`] = ` | ||
<div | ||
data-v-app="" | ||
> | ||
<div | ||
class="BaseMarkdown markdown" | ||
data-v-03a7c885="" | ||
> | ||
<div> | ||
# hello | ||
I'm **MD** | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`BaseMarkdown > should render markdown as inline 1`] = ` | ||
<div | ||
data-v-app="" | ||
> | ||
<span | ||
class="BaseMarkdown markdown" | ||
data-v-03a7c885="" | ||
> | ||
<span> | ||
# hello | ||
I'm **MD** | ||
</span> | ||
</span> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters