Files
Tsering Paljor 674e4b12a8 feat: Add markdown support to more Builder elements (#6124)
* WIP

* Remove formula conversion related changes

* Move the file input click guard to formatted text component

* Move format types into their own components

* Use a shared markdown-it instance

* Move the formatter into data explorer

* Move minification logic into BaserowFormulaMinified

* Renderer should own the root element

* Ensure long choice names are truncated

* Ensure line height doesn't grow for paragraphs

* Add tests

* Add changelog

* Add specific tests for choice element
2026-10-09 09:36:32 +04:00

92 lines
2.8 KiB
JavaScript

import { mountSuspended } from '@nuxt/test-utils/runtime'
import ABFileInput from '@baserow/modules/builder/components/elements/baseComponents/ABFileInput.vue'
describe('ABFileInput', () => {
let openFilePicker = null
beforeEach(() => {
// The component opens the native file picker by clicking its hidden input.
openFilePicker = vi
.spyOn(HTMLInputElement.prototype, 'click')
.mockImplementation(() => {})
})
afterEach(() => {
openFilePicker.mockRestore()
})
const mountComponent = (props = {}) => {
return mountSuspended(ABFileInput, {
props: { modelValue: null, multiple: false, ...props },
})
}
test('renders a plain help text as paragraphs without interpreting markdown', async () => {
const wrapper = await mountComponent({
helpText: 'Drop **files** here\nor click to select',
})
const helpText = wrapper.find('.ab-file-input__help-text')
expect(helpText.element.tagName).toBe('DIV')
expect(helpText.findAll('p.ab-text').map((p) => p.text())).toEqual([
'Drop **files** here',
'or click to select',
])
expect(helpText.find('strong').exists()).toBe(false)
})
test('renders a markdown help text', async () => {
const wrapper = await mountComponent({
helpText: 'Drop **files** here\n\nor click to select',
helpTextFormat: 'markdown',
})
const helpText = wrapper.find('.ab-file-input__help-text')
expect(helpText.find('p.ab-text strong').text()).toBe('files')
expect(helpText.findAll('p.ab-text')).toHaveLength(2)
})
test.each([
['Enter', 'Enter'],
['Space', ' '],
])('opens the file picker on %s on the drop zone', async (_, key) => {
const wrapper = await mountComponent()
await wrapper.find('.ab-file-input').trigger('keydown', { key })
expect(openFilePicker).toHaveBeenCalledTimes(1)
})
test('leaves Enter on a link inside the help text to the link', async () => {
const wrapper = await mountComponent({
helpText: 'Read the [docs](https://baserow.io) first',
helpTextFormat: 'markdown',
})
await wrapper
.find('.ab-file-input__help-text a')
.trigger('keydown', { key: 'Enter' })
expect(openFilePicker).not.toHaveBeenCalled()
})
test('does not open the file picker when a link in the help text is clicked', async () => {
const wrapper = await mountComponent({
helpText: 'Read the [docs](https://baserow.io) first',
helpTextFormat: 'markdown',
})
// Keep jsdom from trying to navigate to the external page.
wrapper.element.addEventListener(
'click',
(event) => event.preventDefault(),
true
)
await wrapper.find('.ab-file-input__help-text a').trigger('click')
expect(openFilePicker).not.toHaveBeenCalled()
await wrapper.find('.ab-file-input').trigger('click')
expect(openFilePicker).toHaveBeenCalledTimes(1)
})
})