import { defineComponent } from 'vue' import { mountSuspended } from '@nuxt/test-utils/runtime' import SampleDataModal from '@baserow/modules/core/components/SampleDataModal' const ModalStub = defineComponent({ name: 'Modal', methods: { show() {}, hide() {}, }, template: '', }) const ButtonStub = defineComponent({ name: 'Button', inheritAttrs: false, template: '', }) const TabsStub = defineComponent({ name: 'Tabs', inheritAttrs: false, template: '
', }) const TabStub = defineComponent({ name: 'Tab', props: { title: { type: String, required: false, default: '' } }, template: '
', }) async function mountComponent(props = {}) { return await mountSuspended(SampleDataModal, { props: { sampleData: { subject: 'Hello' }, title: 'Payload for trigger', subtitle: 'JSON payload', ...props, }, global: { stubs: { Modal: ModalStub, Button: ButtonStub, Tabs: TabsStub, Tab: TabStub, }, mocks: { $t: (key) => key, }, }, }) } describe('SampleDataModal', () => { test('renders only the JSON payload by default', async () => { const wrapper = await mountComponent() expect(wrapper.find('.tabs-stub').exists()).toBe(false) expect(wrapper.find('.sample-data-modal__code').text()).toContain( '"subject": "Hello"' ) }) test('renders JSON and HTML tabs for the html content type', async () => { const wrapper = await mountComponent({ contentType: 'html', sampleDataHtml: '

An email body

', }) expect(wrapper.find('.tabs-stub').exists()).toBe(true) const tabTitles = wrapper .findAll('.tab-stub') .map((tab) => tab.attributes('data-title')) expect(tabTitles).toStrictEqual(['JSON', 'HTML']) expect(wrapper.find('.sample-data-modal__code').text()).toContain( '"subject": "Hello"' ) const iframe = wrapper.find('iframe.sample-data-modal__html-preview') expect(iframe.exists()).toBe(true) // The document is prefixed with a policy that blocks remote loads, so a // tracking pixel cannot report the preview. expect(iframe.attributes('srcdoc')).toMatch( /^