Skip to content

Commit

Permalink
fix: drupal-markup component
Browse files Browse the repository at this point in the history
  • Loading branch information
fago committed Dec 28, 2024
1 parent 4c5c319 commit ffefcf1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
10 changes: 7 additions & 3 deletions playground/components/global/drupal-markup.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<template>
<div v-html="content" />
<div>
<slot>
<component :is="useDrupalCe().renderCustomElements($attrs.content)" />
</slot>
</div>
</template>

<script setup lang="ts">
defineProps<{
content: string
defineSlots<{
default();
}>()
</script>
37 changes: 37 additions & 0 deletions test/unit/components/drupal-markup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// test/unit/components/drupal-markup.test.ts
// @vitest-environment nuxt
import { describe, it, expect } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { defineComponent } from 'vue'
import { useDrupalCe } from '../../../src/runtime/composables/useDrupalCe'
import DrupalMarkup from '../../../playground/components/global/drupal-markup.vue'

describe('drupal-markup custom element', () => {
const markupData = {
element: 'drupal-markup',
content: '<p>Some <b>formatted</b> content.</p>'
}

const createMarkupComponent = (data = markupData) => defineComponent({
components: { 'drupal-markup': DrupalMarkup },
setup() {
const { renderCustomElements } = useDrupalCe()
return { component: renderCustomElements(data) }
},
template: '<component :is="component" />'
})

it('renders markup content via custom element json', async () => {
const wrapper = await mountSuspended(createMarkupComponent())
expect(wrapper.html()).toContain('<p>Some <b>formatted</b> content.</p>')
})

it('renders markup content via custom element markup ', async () => {
const TestComponent = defineComponent({
components: { 'drupal-markup': DrupalMarkup },
template: '<drupal-markup><p>Slotted <b>content</b></p></drupal-markup>'
})
const wrapper = await mountSuspended(TestComponent)
expect(wrapper.html()).toContain('<p>Slotted <b>content</b></p>')
})
})

0 comments on commit ffefcf1

Please sign in to comment.